#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 */
scalar_t__ EOF;
int /*<<< orphan*/ bin_hex_conv(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  FILE *file;
  char line[20];
  int hex;
  int counter = 0;
  if (argc != 3)
    printf("usage: %s File MemoryStartAddress\n", argv[0]);
  else {
    file = fopen(argv[1], "r");
    counter = *argv[2];
    while (fscanf(file, "%x", &hex) != EOF) {
      bin_hex_conv(hex, counter);
      counter++;
    }
    fclose(file);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     118f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe7b(%rip),%rdi
call   1050 <printf@plt>
jmp    11fb <main+0xab>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe65(%rip),%rsi
lea    -0x34(%rbp),%rdx
call   1060 <fscanf@plt>
mov    0x2e18(%rip),%rcx
cmp    (%rcx),%rax
je     11f2 <main+0xa2>
mov    -0x34(%rbp),%edi
mov    -0x38(%rbp),%esi
call   1030 <bin_hex_conv@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11b5 <main+0x65>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
cmp    $0x3,%edi
jne    11dc <main+0x8c>
mov    0x8(%rbp),%rdi
lea    0xeb4(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    0x10(%rbp),%rax
movsbl (%rax),%ebp
lea    0xea0(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <fscanf@plt>
mov    0x2e4f(%rip),%r12
cmp    (%r12),%rax
je     11d2 <main+0x82>
lea    0xe7f(%rip),%r14
lea    0xc(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    0xc(%rsp),%edi
mov    %ebp,%esi
call   1030 <bin_hex_conv@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <fscanf@plt>
cmp    (%r12),%rax
jne    11b0 <main+0x60>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11ec <main+0x9c>
mov    0x0(%rbp),%rsi
lea    0xe19(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"usage: %s File MemoryStartAddress\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%x\00"
@EOF = global i64 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [20 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %41
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
store i32 %26, i32* %9
br label %27
27: ; preds = %32, %17
%28 = load i32*, i32** %6
%29 = call i64 @fscanf(i32* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%30 = load i64, i64* @EOF
%31 = icmp ne i64 %29, %30
br i1 %31, label %32, label %38
32: ; preds = %27
%33 = load i32, i32* %8
%34 = load i32, i32* %9
%35 = call i32 @bin_hex_conv(i32 %33, i32 %34)
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 1
store i32 %37, i32* %9
br label %27
38: ; preds = %27
%39 = load i32*, i32** %6
%40 = call i32 @fclose(i32* %39)
br label %41
41: ; preds = %38, %12
ret i32 0
}

LLVM IR (-O2):
@.str = [35 x i8] c"usage: %s File MemoryStartAddress\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%x\00"
@EOF = global i64 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %31
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = load i8, i8* %14
%16 = call i64 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%17 = load i64, i64* @EOF
%18 = icmp eq i64 %16, %17
br i1 %18, label %29, label %19
19: ; preds = %9
%20 = sext i8 %15 to i32
br label %21
21: ; preds = %19, %21
%22 = phi i32 [ %25, %21 ], [ %20, %19 ]
%23 = load i32, i32* %3
%24 = call i32 @bin_hex_conv(i32 %23, i32 %22)
%25 = add nsw i32 %22, 1
%26 = call i64 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%27 = load i64, i64* @EOF
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %21
29: ; preds = %21, %9
%30 = call i32 @fclose(i32* %12)
br label %31
31: ; preds = %29, %6
ret i32 0
}