#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*/ *);
void 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);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4020,%rsp
lea    0xeae(%rip),%rdi
lea    0xead(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x8(%rbp)
lea    0xe9b(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x4010(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4000,%edx
call   1030 <fread@plt>
mov    %eax,-0x4014(%rbp)
cmp    $0x0,%eax
jle    11c2 <main+0x82>
lea    -0x4010(%rbp),%rdi
mov    -0x4014(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
jmp    1179 <main+0x39>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x4020,%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
add    $0x4000,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>

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 void @main() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca [16384 x i8]
%4 = alloca i32
%5 = 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* %5, i32** %1
%6 = 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* %6, i32** %2
br label %7
7: ; preds = %12, %0
%8 = getelementptr inbounds [16384 x i8], [16384 x i8]* %3, i64 0, i64 0
%9 = load i32*, i32** %1
%10 = call i32 @fread(i8* %8, i32 1, i32 16384, i32* %9)
store i32 %10, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %7
%13 = getelementptr inbounds [16384 x i8], [16384 x i8]* %3, i64 0, i64 0
%14 = load i32, i32* %4
%15 = load i32*, i32** %2
%16 = call i32 @fwrite(i8* %13, i32 1, i32 %14, i32* %15)
br label %7
17: ; preds = %7
%18 = load i32*, i32** %1
%19 = call i32 @fclose(i32* %18)
%20 = load i32*, i32** %2
%21 = call i32 @fclose(i32* %20)
ret void
}

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 void @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 void
}