#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*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int fread(int *, int, int, int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  FILE *file1 = fopen(argv[1], "r");
  FILE *file2 = fopen(argv[2], "w");
  int ilhv1 = 0;
  int readcount = 0;
iback:
  readcount = fread(&ilhv1, 1, 4, file1);
  fprintf(file2, "%i,", ilhv1);
  if (feof(file1)) {
    fclose(file1);
    fclose(file2);
    return 0;
  }
  if (readcount != 0)
    goto iback;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe75(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe38(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     1202 <main+0xb2>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1218 <main+0xc8>
cmpl   $0x0,-0x28(%rbp)
je     1211 <main+0xc1>
jmp    11a4 <main+0x54>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%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
mov    0x8(%rsi),%rdi
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%r15
lea    0xe6b(%rip),%r12
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %eax,%ebp
mov    0xc(%rsp),%edx
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    11d9 <main+0x89>
test   %ebp,%ebp
jne    11a0 <main+0x50>
jmp    11e9 <main+0x99>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%i,\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %7
store i32 0, i32* %8
store i32 0, i32* %9
br label %18
18: ; preds = %35, %2
%19 = load i32*, i32** %6
%20 = call i32 @fread(i32* %8, i32 1, i32 4, i32* %19)
store i32 %20, i32* %9
%21 = load i32*, i32** %7
%22 = load i32, i32* %8
%23 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = load i32*, i32** %6
%25 = call i64 @feof(i32* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %18
%28 = load i32*, i32** %6
%29 = call i32 @fclose(i32* %28)
%30 = load i32*, i32** %7
%31 = call i32 @fclose(i32* %30)
store i32 0, i32* %3
br label %37
32: ; preds = %18
%33 = load i32, i32* %9
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %32
br label %18
36: ; preds = %32
store i32 0, i32* %3
br label %37
37: ; preds = %36, %27
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%i,\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = bitcast i32* %3 to i8*
store i32 0, i32* %3
br label %11
11: ; preds = %20, %2
%12 = call i32 @fread(i32* %3, i32 1, i32 4, i32* %6)
%13 = load i32, i32* %3
%14 = tail call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = tail call i64 @feof(i32* %6)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %11
%18 = tail call i32 @fclose(i32* %6)
%19 = tail call i32 @fclose(i32* %9)
br label %22
20: ; preds = %11
%21 = icmp eq i32 %12, 0
br i1 %21, label %22, label %11
22: ; preds = %20, %17
ret i32 0
}