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

/* Variables and functions */
int O_CREAT;
int O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int, int);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int in, out;
  char c;
  in = open("file.in", O_RDONLY, 0666);
  out = open("file.out", O_WRONLY | O_CREAT, 0666);
  while (read(in, &c, 1)) {
    write(out, &c, 1);
  }
  close(in);
  close(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
mov    $0x1b6,%edx
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
mov    0x2e7c(%rip),%rax
or     (%rax),%esi
lea    0xe83(%rip),%rdi
mov    $0x1b6,%edx
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
je     11c3 <main+0x83>
mov    -0xc(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1192 <main+0x52>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
mov    $0x1b6,%edx
call   1060 <open@plt>
mov    %eax,%r14d
mov    0x2e5c(%rip),%rax
mov    0x2e85(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe8a(%rip),%rdi
mov    $0x1b6,%edx
call   1060 <open@plt>
mov    %eax,%ebp
lea    0xf(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   1050 <read@plt>
test   %rax,%rax
je     11d4 <main+0x94>
lea    0xf(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %rax,%rax
jne    11b0 <main+0x70>
mov    %r14d,%edi
call   1040 <close@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 0, i32* %1
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %5, i32 438)
store i32 %6, i32* %2
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 438)
store i32 %10, i32* %3
br label %11
11: ; preds = %15, %0
%12 = load i32, i32* %2
%13 = call i64 @read(i32 %12, i8* %4, i32 1)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* %3
%17 = call i32 @write(i32 %16, i8* %4, i32 1)
br label %11
18: ; preds = %11
%19 = load i32, i32* %2
%20 = call i32 @close(i32 %19)
%21 = load i32, i32* %3
%22 = call i32 @close(i32 %21)
ret i32 0
}

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
define i32 @main() {
%1 = alloca i8
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %2, i32 438)
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_CREAT
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 438)
%8 = call i64 @read(i32 %3, i8* %1, i32 1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %0, %10
%11 = call i32 @write(i32 %7, i8* %1, i32 1)
%12 = call i64 @read(i32 %3, i8* %1, i32 1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %10
14: ; preds = %10, %0
%15 = tail call i32 @close(i32 %3)
%16 = tail call i32 @close(i32 %7)
ret i32 0
}