#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ hexBin(char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
void lstBin(char *lstfile, char *binfile) {
  FILE *infile;
  FILE *outfile;
  char *hexstring = (char *)malloc(8);
  char *binstring = (char *)malloc(32);
  if (hexstring == NULL) {
    printf("Memory error");
    return;
  }
  if (binstring == NULL) {
    printf("Memory error");
    return;
  }
  infile = fopen(lstfile, "r");
  outfile = fopen(binfile, "w");
  if (infile != NULL && outfile != NULL) {
    while (!feof(infile)) {
      fgets(hexstring, 10, infile);
      hexBin(hexstring, binstring);
      fputs(binstring, outfile);
      fputc('\n', outfile);
    }
    fclose(infile);
    fclose(outfile);
  }
  free(hexstring);
  free(binstring);
}


x86 assembly (clang, -O0):
<lstBin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x8,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x20,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e8 <lstBin+0x48>
lea    0xe22(%rip),%rdi
call   1050 <printf@plt>
jmp    12c8 <lstBin+0x128>
cmpq   $0x0,-0x30(%rbp)
jne    1204 <lstBin+0x64>
lea    0xe06(%rip),%rdi
call   1050 <printf@plt>
jmp    12c8 <lstBin+0x128>
mov    -0x8(%rbp),%rdi
lea    0xdfc(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdea(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12b6 <lstBin+0x116>
cmpq   $0x0,-0x20(%rbp)
je     12b6 <lstBin+0x116>
jmp    1247 <lstBin+0xa7>
mov    -0x18(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1265 <lstBin+0xc5>
jmp    12a4 <lstBin+0x104>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xa,%esi
call   1090 <fgets@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <hexBin@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <fputs@plt>
mov    -0x20(%rbp),%rsi
mov    $0xa,%edi
call   1080 <fputc@plt>
jmp    1247 <lstBin+0xa7>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lstBin>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%rbx
mov    $0x8,%edi
call   10b0 <malloc@plt>
mov    %rax,%r15
mov    $0x20,%edi
call   10b0 <malloc@plt>
test   %r15,%r15
je     1241 <lstBin+0xa1>
mov    %rax,%r14
test   %rax,%rax
je     1241 <lstBin+0xa1>
lea    0xe32(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
mov    %rax,%rbx
lea    0xe22(%rip),%rsi
mov    %r12,%rdi
call   10c0 <fopen@plt>
test   %rbx,%rbx
je     1268 <lstBin+0xc8>
mov    %rax,%r12
test   %rax,%rax
je     1268 <lstBin+0xc8>
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    1258 <lstBin+0xb8>
mov    %r15,%rdi
mov    $0xa,%esi
mov    %rbx,%rdx
call   1090 <fgets@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <hexBin@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1060 <fputs@plt>
mov    $0xa,%edi
mov    %r12,%rsi
call   1080 <fputc@plt>
jmp    1200 <lstBin+0x60>
lea    0xdb8(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"Memory error\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
define void @lstBin(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = call i64 @malloc(i32 8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %7
%11 = call i64 @malloc(i32 32)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %8
%13 = load i8*, i8** %7
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %60
17: ; preds = %2
%18 = load i8*, i8** %8
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %60
22: ; preds = %17
%23 = load i8*, i8** %3
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %5
%25 = load i8*, i8** %4
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %26, i32** %6
%27 = load i32*, i32** %5
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %55
29: ; preds = %22
%30 = load i32*, i32** %6
%31 = icmp ne i32* %30, null
br i1 %31, label %32, label %55
32: ; preds = %29
br label %33
33: ; preds = %38, %32
%34 = load i32*, i32** %5
%35 = call i32 @feof(i32* %34)
%36 = icmp ne i32 %35, 0
%37 = xor i1 %36, true
br i1 %37, label %38, label %50
38: ; preds = %33
%39 = load i8*, i8** %7
%40 = load i32*, i32** %5
%41 = call i32 @fgets(i8* %39, i32 10, i32* %40)
%42 = load i8*, i8** %7
%43 = load i8*, i8** %8
%44 = call i32 @hexBin(i8* %42, i8* %43)
%45 = load i8*, i8** %8
%46 = load i32*, i32** %6
%47 = call i32 @fputs(i8* %45, i32* %46)
%48 = load i32*, i32** %6
%49 = call i32 @fputc(i8 signext 10, i32* %48)
br label %33
50: ; preds = %33
%51 = load i32*, i32** %5
%52 = call i32 @fclose(i32* %51)
%53 = load i32*, i32** %6
%54 = call i32 @fclose(i32* %53)
br label %55
55: ; preds = %50, %29, %22
%56 = load i8*, i8** %7
%57 = call i32 @free(i8* %56)
%58 = load i8*, i8** %8
%59 = call i32 @free(i8* %58)
br label %60
60: ; preds = %55, %20, %15
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"Memory error\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
define void @lstBin(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i64 @malloc(i32 8)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i64 @malloc(i32 32)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %3, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %36
10: ; preds = %2
%11 = icmp eq i64 %5, 0
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %36
14: ; preds = %10
%15 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp ne i32* %15, null
%18 = icmp ne i32* %16, null
%19 = and i1 %17, %18
br i1 %19, label %20, label %33
20: ; preds = %14
%21 = tail call i32 @feof(i32* %15)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %20, %23
%24 = tail call i32 @fgets(i8* %4, i32 10, i32* %15)
%25 = tail call i32 @hexBin(i8* %4, i8* %6)
%26 = tail call i32 @fputs(i8* %6, i32* %16)
%27 = tail call i32 @fputc(i8 signext 10, i32* %16)
%28 = tail call i32 @feof(i32* %15)
%29 = icmp eq i32 %28, 0
br i1 %29, label %23, label %30
30: ; preds = %23, %20
%31 = tail call i32 @fclose(i32* %15)
%32 = tail call i32 @fclose(i32* %16)
br label %33
33: ; preds = %30, %14
%34 = tail call i32 @free(i8* %4)
%35 = tail call i32 @free(i8* %6)
br label %36
36: ; preds = %33, %12, %8
ret void
}