#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 /*<<< 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 c;
  int in, out;
  in = open("file.in", O_RDONLY);
  out = open("file.out", O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
  while (read(in, &c, 1) == 1)
    write(out, &c, 1);
  exit(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    $0x0,%al
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
mov    0x2e7f(%rip),%rax
or     (%rax),%esi
mov    0x2e46(%rip),%rax
mov    (%rax),%edx
mov    0x2e4d(%rip),%rax
or     (%rax),%edx
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1050 <open@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
jne    11ce <main+0x8e>
mov    -0x10(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    119e <main+0x5e>
xor    %edi,%edi
call   1060 <exit@plt>

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
xor    %eax,%eax
call   1050 <open@plt>
mov    %eax,%r14d
mov    0x2e4f(%rip),%rax
mov    0x2e88(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e4d(%rip),%rax
mov    0x2e56(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe7b(%rip),%rdi
xor    %eax,%eax
call   1050 <open@plt>
mov    %eax,%ebp
lea    0xf(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
jne    11e4 <main+0xa4>
lea    0xf(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
je     11c0 <main+0x80>
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 i8
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @O_RDONLY
%6 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IRUSR
%11 = load i32, i32* @S_IWUSR
%12 = or i32 %10, %11
%13 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %12)
store i32 %13, i32* %4
br label %14
14: ; preds = %18, %0
%15 = load i32, i32* %3
%16 = call i32 @read(i32 %15, i8* %2, i32 1)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %4
%20 = call i32 @write(i32 %19, i8* %2, i32 1)
br label %14
21: ; preds = %14
%22 = 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 i8
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_CREAT
%6 = or i32 %5, %4
%7 = load i32, i32* @S_IRUSR
%8 = load i32, i32* @S_IWUSR
%9 = or i32 %8, %7
%10 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %9)
%11 = call i32 @read(i32 %3, i8* %1, i32 1)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %0, %13
%14 = call i32 @write(i32 %10, i8* %1, i32 1)
%15 = call i32 @read(i32 %3, i8* %1, i32 1)
%16 = icmp eq i32 %15, 1
br i1 %16, label %13, label %17
17: ; preds = %13, %0
%18 = tail call i32 @exit(i32 0)
unreachable
}