#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*/ buff;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int main() {
  char buff[1024];
  FILE *in = fopen("file.in", "r");
  FILE *out = fopen("file.out", "w");
  while (fread(buff, sizeof(buff), 1, in) >= 1) {
    fwrite(buff, sizeof(buff), 1, out);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x418(%rbp)
lea    0xea7(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x420(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rcx
mov    $0x400,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
jl     11be <main+0x8e>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rcx
mov    $0x400,%esi
mov    $0x1,%edx
call   1050 <fwrite@plt>
jmp    1176 <main+0x46>
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
lea    0xebd(%rip),%rdi
lea    0xebe(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%r14
lea    0xeb1(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x400,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    11be <main+0x8e>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x400,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1050 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jg     1190 <main+0x60>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"file.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"file.out\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i32*
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 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** %3
%6 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 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** %4
br label %7
7: ; preds = %12, %0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%9 = load i32*, i32** %3
%10 = call i32 @fread(i8* %8, i32 1024, i32 1, i32* %9)
%11 = icmp sge i32 %10, 1
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%14 = load i32*, i32** %4
%15 = call i32 @fwrite(i8* %13, i32 1024, i32 1, i32* %14)
br label %7
16: ; preds = %7
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [8 x i8] c"file.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"file.out\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 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 ([9 x i8], [9 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 1024, i32 1, i32* %3)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0, %7
%8 = call i32 @fwrite(i8* %2, i32 1024, i32 1, i32* %4)
%9 = call i32 @fread(i8* %2, i32 1024, i32 1, i32* %3)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %7, label %11
11: ; preds = %7, %0
ret i32 0
}