#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*/ block;

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int, ...);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  char block[1024];
  int in, out;
  int nread;
  in = open("file.in", O_RDONLY);
  out = open("file.out", O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
  while ((nread = read(in, block, sizeof(block))) > 0)
    write(out, block, nread);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1050 <open@plt>
mov    %eax,-0x414(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
mov    0x2e79(%rip),%rax
or     (%rax),%esi
mov    0x2e40(%rip),%rax
mov    (%rax),%edx
mov    0x2e47(%rip),%rax
or     (%rax),%edx
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1050 <open@plt>
mov    %eax,-0x418(%rbp)
mov    -0x414(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,-0x41c(%rbp)
cmp    $0x0,%eax
jle    11ea <main+0xaa>
mov    -0x418(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x41c(%rbp),%edx
call   1030 <write@plt>
jmp    11a7 <main+0x67>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1050 <open@plt>
mov    %eax,%r14d
mov    0x2e4c(%rip),%rax
mov    0x2e85(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e4a(%rip),%rax
mov    0x2e53(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1050 <open@plt>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x400,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    11d0 <main+0x90>
mov    %rsp,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
test   %eax,%eax
jg     11b0 <main+0x70>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"file.in\00"
@O_RDONLY = global i32 0
@.str.1 = [9 x i8] c"file.out\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @O_RDONLY
%7 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* @O_WRONLY
%9 = load i32, i32* @O_CREAT
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IRUSR
%12 = load i32, i32* @S_IWUSR
%13 = or i32 %11, %12
%14 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %13)
store i32 %14, i32* %4
br label %15
15: ; preds = %20, %0
%16 = load i32, i32* %3
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%18 = call i32 @read(i32 %16, i8* %17, i32 1024)
store i32 %18, i32* %5
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i32, i32* %4
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%23 = load i32, i32* %5
%24 = call i32 @write(i32 %21, i8* %22, i32 %23)
br label %15
25: ; preds = %15
%26 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"file.in\00"
@O_RDONLY = global i32 0
@.str.1 = [9 x i8] c"file.out\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_CREAT
%7 = or i32 %6, %5
%8 = load i32, i32* @S_IRUSR
%9 = load i32, i32* @S_IWUSR
%10 = or i32 %9, %8
%11 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %10)
%12 = call i32 @read(i32 %4, i8* %2, i32 1024)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %0, %14
%15 = phi i32 [ %17, %14 ], [ %12, %0 ]
%16 = call i32 @write(i32 %11, i8* %2, i32 %15)
%17 = call i32 @read(i32 %4, i8* %2, i32 1024)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %14, label %19
19: ; preds = %14, %0
%20 = tail call i32 @exit(i32 0)
unreachable
}