#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*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int main() {
  FILE *fin, *fout;
  char buf[16384];
  int count;
  fin = fopen("foo", "r");
  fout = fopen("bar", "w");
  while ((count = fread(buf, 1, 16384, fin)) > 0)
    fwrite(buf, 1, count, fout);
  fclose(fin);
  fclose(fout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4030,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe94(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x4020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4000,%edx
call   1030 <fread@plt>
mov    %eax,-0x4024(%rbp)
cmp    $0x0,%eax
jle    11c9 <main+0x89>
lea    -0x4020(%rbp),%rdi
mov    -0x4024(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
jmp    1180 <main+0x40>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x4030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x4000,%rsp
lea    0xead(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
lea    0xe9b(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x4000,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    11cb <main+0x8b>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r15,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x4000,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jg     11a0 <main+0x60>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x4000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"foo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"bar\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca [16384 x i8]
%2 = getelementptr inbounds [16384 x i8], [16384 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%5 = call i32 @fread(i8* %2, i32 1, i32 16384, i32* %3)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %0, %7
%8 = phi i32 [ %10, %7 ], [ %5, %0 ]
%9 = call i32 @fwrite(i8* %2, i32 1, i32 %8, i32* %4)
%10 = call i32 @fread(i8* %2, i32 1, i32 16384, i32* %3)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %7, label %12
12: ; preds = %7, %0
%13 = tail call i32 @fclose(i32* %3)
%14 = tail call i32 @fclose(i32* %4)
ret i32 0
}