#include <random>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>

#include <chrono>

void ldpcEncoder (unsigned int *infoWord, unsigned int* W_ROW_ROM,
                  unsigned int numMsgBits, unsigned int numRowsinRom, unsigned int numParBits,
                  unsigned int shiftRegLength,
                  unsigned int *codeWord);

int main (int argc, char **argv) {

  unsigned int numChecks, numBits, maxBitsForCheck, maxChecksForBit;
  unsigned int numRowsW, numColsW, shiftRegLength;
  unsigned int *W_ROW_ROM;

  char alistFile[256];
  char wROM_File[256];
  FILE *src;
  int errnum;
  unsigned int infoLeng, rnum, rdenom;

  using clock = std::chrono::steady_clock;

  clock::time_point startTime;
  clock::time_point endTime;
  clock::duration encoderTime;

  unsigned int  seed = 163331;
  /*  or use this to get a fresh sequence each time the program is run.
  std::random_device  rd;  //Will be used to obtain a seed for the random number engine
  std::mt19937 generator(rd()); //Standard mersenne_twister_engine seeded with rd()
  */
  std::mt19937 generator(seed); //Standard mersenne_twister_engine
  std::uniform_real_distribution<> rDist(0, 1);

  if (argc < 4) {
    printf("usage:  TestEncoder <infoLength> <r-numerator> <r-denominator>\n" );
    exit(-1);
  }
  infoLeng = atoi(argv[1]);
  rnum = atoi(argv[2]);
  rdenom = atoi(argv[3]);
  sprintf(alistFile, "./G_and_H_Matrices/H_%d%d_%d.alist", rnum, rdenom, infoLeng);
  sprintf(wROM_File, "./G_and_H_Matrices/W_ROW_ROM_%d%d_%d.binary", rnum, rdenom, infoLeng);

  src = fopen(alistFile, "r");
  if (src == NULL) {
    errnum = errno;
    printf("Value of errno: %d\n", errnum);
    perror("Error printed by perror");
    printf("Error opening file %s\n", alistFile);
    return(EXIT_FAILURE);
  }

  fscanf(src,"%d", &numBits);
  fscanf(src ,"%d", &numChecks);
  fscanf(src,"%d", &maxChecksForBit);
  fscanf(src,"%d", &maxBitsForCheck);
  fclose(src);

  src = fopen(wROM_File, "r");
  if (src == NULL) {
    errnum = errno;
    printf("Value of errno: %d\n", errnum);
    perror("Error printed by perror");
    printf("Error opening file %s\n", wROM_File);
    return(EXIT_FAILURE);
  }

  fread(& numRowsW, sizeof(unsigned int), 1, src);
  fread(& numColsW, sizeof(unsigned int), 1, src);
  fread(& shiftRegLength, sizeof(unsigned int), 1, src);
  W_ROW_ROM = (unsigned int*) malloc(numRowsW * numColsW * sizeof( unsigned int));
  fread(W_ROW_ROM, sizeof(unsigned int), numRowsW * numColsW, src);
  fclose(src);

  printf("parameters have been read.\n");
  printf("numBits = %i, numChecks = %i\n", numBits, numChecks);
  printf("Max checks for bit: %i  Max bits for check %i\n", maxChecksForBit, maxBitsForCheck);
  // ///////////////////////////////////////////

  unsigned int* infoWord;
  unsigned int* codeWord;

  infoWord = (unsigned int *)malloc(infoLeng * sizeof(unsigned int));
  codeWord = (unsigned int *)malloc(numBits * sizeof(unsigned int));

    for (unsigned int j=0; j < infoLeng; j++) {
      //      infoWord[j] = (0.5 >= rDist(generator))? 1:0;
      infoWord[j] = j % 2;
    }
    startTime = clock::now();
    ldpcEncoder(infoWord, W_ROW_ROM, infoLeng, numRowsW, numColsW, shiftRegLength, codeWord);
    endTime = clock::now();
    encoderTime = endTime - startTime;

    printf("Time for encoder: %i microsec\n",
           std::chrono::duration_cast<std::chrono::microseconds>(encoderTime).count());


  char encodedFile[256];
  sprintf(encodedFile, "./evenodd%d.encoded", numBits);
  src = fopen(encodedFile, "w");
  if (src == NULL) {
    errnum = errno;
    printf("Value of errno: %d\n", errnum);
    perror("Error printed by perror");
    printf("Error opening file %s\n", encodedFile);
    return(EXIT_FAILURE);
  }
  for(unsigned int j=0; j<numBits; j++) fprintf(src,"%d\n", codeWord[j]);
  fclose(src);


    // Debug.
    // unsigned int numParityBits = numColsW;
    // for (unsigned int j=0; j< numParityBits; j++) {
    //   printf(" %i", codeWord[infoLeng+j]);
    //   if ( (j % 40) == 39)  { printf("\n"); }
    // }
    // printf("\n");
}

	.file	"tmpxft_00212b2a_00000000-6_TestEncoder.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4219:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4219:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"usage:  TestEncoder <infoLength> <r-numerator> <r-denominator>\n"
.LC1:
	.string	"./G_and_H_Matrices/H_%d%d_%d.alist"
.LC2:
	.string	"./G_and_H_Matrices/W_ROW_ROM_%d%d_%d.binary"
.LC3:
	.string	"r"
.LC4:
	.string	"Value of errno: %d\n"
.LC5:
	.string	"Error printed by perror"
.LC6:
	.string	"Error opening file %s\n"
.LC7:
	.string	"%d"
.LC8:
	.string	"parameters have been read.\n"
.LC9:
	.string	"numBits = %i, numChecks = %i\n"
.LC10:
	.string	"Max checks for bit: %i  Max bits for check %i\n"
.LC11:
	.string	"Time for encoder: %i microsec\n"
.LC12:
	.string	"./evenodd%d.encoded"
.LC13:
	.string	"w"
.LC14:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB4207:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$840, %rsp
	.cfi_def_cfa_offset 896
	movq	%fs:40, %rax
	movq	%rax, 824(%rsp)
	xorl	%eax, %eax
	cmpl	$3, %edi
	jg	.L3
	movl	$2, %edi
	leaq	.LC0(%rip), %rsi
	call	__printf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
.L3:
	movq	8(%rsi), %rdi
	movq	%rsi, %rbx
	leaq	56(%rsp), %r14
	leaq	.LC3(%rip), %r15
	call	atoi@PLT
	movq	16(%rbx), %rdi
	movl	%eax, %ebp
	call	atoi@PLT
	movq	24(%rbx), %rdi
	movl	%eax, %r12d
	call	atoi@PLT
	movl	%r12d, %r8d
	movl	$256, %edx
	movq	%r14, %rdi
	pushq	%rsi
	.cfi_def_cfa_offset 904
	movl	%eax, %r9d
	leaq	.LC1(%rip), %rcx
	movl	$2, %esi
	pushq	%rbp
	.cfi_def_cfa_offset 912
	movl	%eax, 28(%rsp)
	xorl	%eax, %eax
	leaq	328(%rsp), %r13
	call	__sprintf_chk@PLT
	movl	28(%rsp), %r9d
	movl	%r12d, %r8d
	movq	%r13, %rdi
	movl	$256, %edx
	movl	$2, %esi
	xorl	%eax, %eax
	movl	%ebp, (%rsp)
	leaq	.LC2(%rip), %rcx
	call	__sprintf_chk@PLT
	popq	%rdi
	.cfi_def_cfa_offset 904
	movq	%r15, %rsi
	popq	%r8
	.cfi_def_cfa_offset 896
	movq	%r14, %rdi
	call	fopen@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.L4
	call	__errno_location@PLT
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	movl	(%rax), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC5(%rip), %rdi
	call	perror@PLT
	movq	%r14, %rdx
	jmp	.L16
.L4:
	leaq	.LC7(%rip), %r12
	movq	%rax, %rdi
	leaq	32(%rsp), %rdx
	xorl	%eax, %eax
	movq	%r12, %rsi
	call	__isoc23_fscanf@PLT
	movq	%rbx, %rdi
	leaq	28(%rsp), %rdx
	movq	%r12, %rsi
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movq	%rbx, %rdi
	leaq	40(%rsp), %rdx
	movq	%r12, %rsi
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	leaq	36(%rsp), %rdx
	movq	%r12, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	movq	%r15, %rsi
	movq	%r13, %rdi
	call	fopen@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.L6
.L17:
	call	__errno_location@PLT
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	movl	(%rax), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC5(%rip), %rdi
	call	perror@PLT
	movq	%r13, %rdx
.L16:
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %eax
	jmp	.L2
.L6:
	leaq	44(%rsp), %rdi
	movq	%rax, %r8
	movl	$1, %ecx
	movl	$4, %edx
	movl	$4, %esi
	call	__fread_chk@PLT
	movq	%rbx, %r8
	leaq	48(%rsp), %rdi
	movl	$1, %ecx
	movl	$4, %edx
	movl	$4, %esi
	call	__fread_chk@PLT
	movq	%rbx, %r8
	movl	$1, %ecx
	movl	$4, %edx
	movl	$4, %esi
	leaq	52(%rsp), %rdi
	call	__fread_chk@PLT
	movl	44(%rsp), %r12d
	imull	48(%rsp), %r12d
	leaq	0(,%r12,4), %r14
	movq	%r14, %rdi
	call	malloc@PLT
	movq	%rbx, %r8
	movq	%r12, %rcx
	movl	$4, %edx
	movq	%r14, %rsi
	movq	%rax, %rdi
	movq	%rax, %r13
	call	__fread_chk@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	28(%rsp), %ecx
	movl	32(%rsp), %edx
	xorl	%eax, %eax
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	36(%rsp), %ecx
	movl	40(%rsp), %edx
	xorl	%eax, %eax
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	%ebp, %edi
	salq	$2, %rdi
	call	malloc@PLT
	movl	32(%rsp), %edi
	movq	%rax, %rbx
	salq	$2, %rdi
	call	malloc@PLT
	movq	%rax, %r12
	xorl	%eax, %eax
.L8:
	cmpl	%ebp, %eax
	jnb	.L19
	movl	%eax, %edx
	andl	$1, %edx
	movl	%edx, (%rbx,%rax,4)
	incq	%rax
	jmp	.L8
.L19:
	call	_ZNSt6chrono3_V212steady_clock3nowEv@PLT
	movl	%ebp, %edx
	movq	%r13, %rsi
	movq	%rbx, %rdi
	movq	%rax, %r14
	pushq	%rax
	.cfi_def_cfa_offset 904
	xorl	%ebp, %ebp
	pushq	%r12
	.cfi_def_cfa_offset 912
	movl	68(%rsp), %r9d
	movl	64(%rsp), %r8d
	movl	60(%rsp), %ecx
	call	_Z11ldpcEncoderPjS_jjjjS_@PLT
	call	_ZNSt6chrono3_V212steady_clock3nowEv@PLT
	popq	%rdx
	.cfi_def_cfa_offset 904
	popq	%rcx
	.cfi_def_cfa_offset 896
	movl	$1000, %ecx
	subq	%r14, %rax
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	cqto
	leaq	568(%rsp), %r13
	leaq	.LC14(%rip), %r14
	idivq	%rcx
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	32(%rsp), %r8d
	movq	%r13, %rdi
	xorl	%eax, %eax
	leaq	.LC12(%rip), %rcx
	movl	$256, %edx
	movl	$2, %esi
	call	__sprintf_chk@PLT
	leaq	.LC13(%rip), %rsi
	movq	%r13, %rdi
	call	fopen@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	je	.L17
.L10:
	cmpl	32(%rsp), %ebp
	jnb	.L20
	movl	%ebp, %eax
	movq	%r14, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	movl	(%r12,%rax,4), %ecx
	xorl	%eax, %eax
	incl	%ebp
	call	__fprintf_chk@PLT
	jmp	.L10
.L20:
	movq	%rbx, %rdi
	call	fclose@PLT
	xorl	%eax, %eax
.L2:
	movq	824(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	addq	$840, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4207:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4242:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE4242:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <random>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>

#include <chrono>

void ldpcEncoder (unsigned int *infoWord, unsigned int* W_ROW_ROM,
                  unsigned int numMsgBits, unsigned int numRowsinRom, unsigned int numParBits,
                  unsigned int shiftRegLength,
                  unsigned int *codeWord);

int main (int argc, char **argv) {

  unsigned int numChecks, numBits, maxBitsForCheck, maxChecksForBit;
  unsigned int numRowsW, numColsW, shiftRegLength;
  unsigned int *W_ROW_ROM;

  char alistFile[256];
  char wROM_File[256];
  FILE *src;
  int errnum;
  unsigned int infoLeng, rnum, rdenom;

  using clock = std::chrono::steady_clock;

  clock::time_point startTime;
  clock::time_point endTime;
  clock::duration encoderTime;

  unsigned int  seed = 163331;
  /*  or use this to get a fresh sequence each time the program is run.
  std::random_device  rd;  //Will be used to obtain a seed for the random number engine
  std::mt19937 generator(rd()); //Standard mersenne_twister_engine seeded with rd()
  */
  std::mt19937 generator(seed); //Standard mersenne_twister_engine
  std::uniform_real_distribution<> rDist(0, 1);

  if (argc < 4) {
    printf("usage:  TestEncoder <infoLength> <r-numerator> <r-denominator>\n" );
    exit(-1);
  }
  infoLeng = atoi(argv[1]);
  rnum = atoi(argv[2]);
  rdenom = atoi(argv[3]);
  sprintf(alistFile, "./G_and_H_Matrices/H_%d%d_%d.alist", rnum, rdenom, infoLeng);
  sprintf(wROM_File, "./G_and_H_Matrices/W_ROW_ROM_%d%d_%d.binary", rnum, rdenom, infoLeng);

  src = fopen(alistFile, "r");
  if (src == NULL) {
    errnum = errno;
    printf("Value of errno: %d\n", errnum);
    perror("Error printed by perror");
    printf("Error opening file %s\n", alistFile);
    return(EXIT_FAILURE);
  }

  fscanf(src,"%d", &numBits);
  fscanf(src ,"%d", &numChecks);
  fscanf(src,"%d", &maxChecksForBit);
  fscanf(src,"%d", &maxBitsForCheck);
  fclose(src);

  src = fopen(wROM_File, "r");
  if (src == NULL) {
    errnum = errno;
    printf("Value of errno: %d\n", errnum);
    perror("Error printed by perror");
    printf("Error opening file %s\n", wROM_File);
    return(EXIT_FAILURE);
  }

  fread(& numRowsW, sizeof(unsigned int), 1, src);
  fread(& numColsW, sizeof(unsigned int), 1, src);
  fread(& shiftRegLength, sizeof(unsigned int), 1, src);
  W_ROW_ROM = (unsigned int*) malloc(numRowsW * numColsW * sizeof( unsigned int));
  fread(W_ROW_ROM, sizeof(unsigned int), numRowsW * numColsW, src);
  fclose(src);

  printf("parameters have been read.\n");
  printf("numBits = %i, numChecks = %i\n", numBits, numChecks);
  printf("Max checks for bit: %i  Max bits for check %i\n", maxChecksForBit, maxBitsForCheck);
  // ///////////////////////////////////////////

  unsigned int* infoWord;
  unsigned int* codeWord;

  infoWord = (unsigned int *)malloc(infoLeng * sizeof(unsigned int));
  codeWord = (unsigned int *)malloc(numBits * sizeof(unsigned int));

    for (unsigned int j=0; j < infoLeng; j++) {
      //      infoWord[j] = (0.5 >= rDist(generator))? 1:0;
      infoWord[j] = j % 2;
    }
    startTime = clock::now();
    ldpcEncoder(infoWord, W_ROW_ROM, infoLeng, numRowsW, numColsW, shiftRegLength, codeWord);
    endTime = clock::now();
    encoderTime = endTime - startTime;

    printf("Time for encoder: %i microsec\n",
           std::chrono::duration_cast<std::chrono::microseconds>(encoderTime).count());


  char encodedFile[256];
  sprintf(encodedFile, "./evenodd%d.encoded", numBits);
  src = fopen(encodedFile, "w");
  if (src == NULL) {
    errnum = errno;
    printf("Value of errno: %d\n", errnum);
    perror("Error printed by perror");
    printf("Error opening file %s\n", encodedFile);
    return(EXIT_FAILURE);
  }
  for(unsigned int j=0; j<numBits; j++) fprintf(src,"%d\n", codeWord[j]);
  fclose(src);


    // Debug.
    // unsigned int numParityBits = numColsW;
    // for (unsigned int j=0; j< numParityBits; j++) {
    //   printf(" %i", codeWord[infoLeng+j]);
    //   if ( (j % 40) == 39)  { printf("\n"); }
    // }
    // printf("\n");
}

	.text
	.file	"TestEncoder.hip"
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:                                # %_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEC2Em.exit
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$824, %rsp                      # imm = 0x338
	.cfi_def_cfa_offset 880
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$3, %edi
	jle	.LBB0_16
# %bb.1:
	movq	%rsi, %r14
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %ebx
	movq	16(%r14), %rdi
	callq	atoi
	movl	%eax, %ebp
	movq	24(%r14), %rdi
	callq	atoi
	movl	%eax, %r14d
	leaq	560(%rsp), %r15
	movl	$.L.str.1, %esi
	movq	%r15, %rdi
	movl	%ebp, %edx
	movl	%eax, %ecx
	movl	%ebx, %r8d
	xorl	%eax, %eax
	callq	sprintf
	leaq	48(%rsp), %rdi
	movl	$.L.str.2, %esi
	movl	%ebp, %edx
	movl	%r14d, %ecx
	movl	%ebx, %r8d
	xorl	%eax, %eax
	callq	sprintf
	movl	$.L.str.3, %esi
	movq	%r15, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB0_2
# %bb.3:
	movq	%rax, %r14
	leaq	16(%rsp), %rdx
	movl	$.L.str.7, %esi
	movq	%rax, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	leaq	36(%rsp), %rdx
	movl	$.L.str.7, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	leaq	28(%rsp), %rdx
	movl	$.L.str.7, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	leaq	32(%rsp), %rdx
	movl	$.L.str.7, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movq	%r14, %rdi
	callq	fclose
	leaq	48(%rsp), %rdi
	movl	$.L.str.3, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB0_4
# %bb.5:
	movq	%rax, %r14
	leaq	44(%rsp), %r15
	movl	$4, %esi
	movl	$1, %edx
	movq	%r15, %rdi
	movq	%rax, %rcx
	callq	fread
	leaq	40(%rsp), %r12
	movl	$4, %esi
	movl	$1, %edx
	movq	%r12, %rdi
	movq	%r14, %rcx
	callq	fread
	leaq	24(%rsp), %rdi
	movl	$4, %esi
	movl	$1, %edx
	movq	%r14, %rcx
	callq	fread
	movl	(%r15), %ebp
	movl	(%r12), %eax
	movl	%eax, 20(%rsp)                  # 4-byte Spill
	movl	%eax, %r13d
	imull	%ebp, %r13d
	leaq	(,%r13,4), %rdi
	callq	malloc
	movq	%rax, %r12
	movl	$4, %esi
	movq	%rax, %rdi
	movq	%r13, %rdx
	movq	%r14, %rcx
	callq	fread
	movq	%r14, %rdi
	callq	fclose
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	16(%rsp), %esi
	movl	36(%rsp), %edx
	movl	$.L.str.9, %edi
	xorl	%eax, %eax
	callq	printf
	movl	28(%rsp), %esi
	movl	32(%rsp), %edx
	movl	$.L.str.10, %edi
	xorl	%eax, %eax
	callq	printf
	movl	%ebx, %r15d
	leaq	(,%r15,4), %rdi
	callq	malloc
	movq	%rax, %r13
	movl	16(%rsp), %edi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, %r14
	testl	%ebx, %ebx
	je	.LBB0_8
# %bb.6:                                # %.lr.ph.preheader
	xorl	%eax, %eax
.LBB0_7:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%eax, %ecx
	andl	$1, %ecx
	movl	%ecx, (%r13,%rax,4)
	incq	%rax
	cmpq	%rax, %r15
	jne	.LBB0_7
.LBB0_8:                                # %._crit_edge
	callq	_ZNSt6chrono3_V212steady_clock3nowEv
	movq	%rax, %r15
	movl	24(%rsp), %r9d
	movq	%r14, (%rsp)
	movq	%r13, %rdi
	movq	%r12, %rsi
	movl	%ebx, %edx
	movl	%ebp, %ecx
	movl	20(%rsp), %r8d                  # 4-byte Reload
	callq	_Z11ldpcEncoderPjS_jjjjS_
	callq	_ZNSt6chrono3_V212steady_clock3nowEv
	subq	%r15, %rax
	movabsq	$2361183241434822607, %rcx      # imm = 0x20C49BA5E353F7CF
	imulq	%rcx
	movq	%rdx, %rsi
	shrq	$63, %rsi
	sarq	$7, %rdx
	addq	%rdx, %rsi
	movl	$.L.str.11, %edi
	xorl	%eax, %eax
	callq	printf
	movl	16(%rsp), %edx
	leaq	304(%rsp), %rbx
	movl	$.L.str.12, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	sprintf
	movl	$.L.str.13, %esi
	movq	%rbx, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB0_13
# %bb.9:                                # %.preheader
	movq	%rax, %rbx
	cmpl	$0, 16(%rsp)
	je	.LBB0_12
# %bb.10:                               # %.lr.ph60.preheader
	xorl	%r15d, %r15d
.LBB0_11:                               # %.lr.ph60
                                        # =>This Inner Loop Header: Depth=1
	movl	(%r14,%r15,4), %edx
	movl	$.L.str.14, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%r15
	movl	16(%rsp), %eax
	cmpq	%rax, %r15
	jb	.LBB0_11
.LBB0_12:                               # %._crit_edge61
	movq	%rbx, %rdi
	callq	fclose
	xorl	%eax, %eax
.LBB0_15:
	addq	$824, %rsp                      # imm = 0x338
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB0_2:
	.cfi_def_cfa_offset 880
	callq	__errno_location
	movl	(%rax), %esi
	movl	$.L.str.4, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.5, %edi
	callq	perror
	leaq	560(%rsp), %rsi
	jmp	.LBB0_14
.LBB0_4:
	callq	__errno_location
	movl	(%rax), %esi
	movl	$.L.str.4, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.5, %edi
	callq	perror
	leaq	48(%rsp), %rsi
	jmp	.LBB0_14
.LBB0_13:
	callq	__errno_location
	movl	(%rax), %esi
	movl	$.L.str.4, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.5, %edi
	callq	perror
	leaq	304(%rsp), %rsi
.LBB0_14:
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %eax
	jmp	.LBB0_15
.LBB0_16:
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	$-1, %edi
	callq	exit
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"./G_and_H_Matrices/H_%d%d_%d.alist"
	.size	.L.str.1, 35

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"./G_and_H_Matrices/W_ROW_ROM_%d%d_%d.binary"
	.size	.L.str.2, 44

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"r"
	.size	.L.str.3, 2

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Value of errno: %d\n"
	.size	.L.str.4, 20

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Error printed by perror"
	.size	.L.str.5, 24

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Error opening file %s\n"
	.size	.L.str.6, 23

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"%d"
	.size	.L.str.7, 3

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"numBits = %i, numChecks = %i\n"
	.size	.L.str.9, 30

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Max checks for bit: %i  Max bits for check %i\n"
	.size	.L.str.10, 47

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Time for encoder: %i microsec\n"
	.size	.L.str.11, 31

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"./evenodd%d.encoded"
	.size	.L.str.12, 20

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"w"
	.size	.L.str.13, 2

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"%d\n"
	.size	.L.str.14, 4

	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"parameters have been read."
	.size	.Lstr, 27

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"usage:  TestEncoder <infoLength> <r-numerator> <r-denominator>"
	.size	.Lstr.1, 63

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym __hip_cuid_

	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
