#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);
  if (in < 0) {
    write(1, "NO SUCH FILE OR DIRECTORY\n", 28);
    exit(0);
  }
  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)
cmpl   $0x0,-0xc(%rbp)
jge    1190 <main+0x50>
mov    $0x1,%edi
lea    0xe89(%rip),%rsi
mov    $0x1c,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
mov    0x2e58(%rip),%rax
or     (%rax),%esi
mov    0x2e1f(%rip),%rax
mov    (%rax),%edx
mov    0x2e26(%rip),%rax
or     (%rax),%edx
lea    0xe68(%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    11f5 <main+0xb5>
mov    -0x10(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    11c5 <main+0x85>
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>
test   %eax,%eax
jns    1180 <main+0x40>
lea    0xe9e(%rip),%rsi
mov    $0x1,%edi
mov    $0x1c,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    %eax,%r14d
mov    0x2e2e(%rip),%rax
mov    0x2e67(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e2c(%rip),%rax
mov    0x2e35(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe75(%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    1204 <main+0xc4>
lea    0xf(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%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     11e0 <main+0xa0>
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 = [27 x i8] c"NO SUCH FILE OR DIRECTORY\0A\00"
@.str.2 = [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* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @write(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 28)
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %0
%13 = load i32, i32* @O_WRONLY
%14 = load i32, i32* @O_CREAT
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IRUSR
%17 = load i32, i32* @S_IWUSR
%18 = or i32 %16, %17
%19 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %15, i32 %18)
store i32 %19, i32* %4
br label %20
20: ; preds = %24, %12
%21 = load i32, i32* %3
%22 = call i32 @read(i32 %21, i8* %2, i32 1)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* %4
%26 = call i32 @write(i32 %25, i8* %2, i32 1)
br label %20
27: ; preds = %20
%28 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"file.in\00"
@O_RDONLY = global i32 0
@.str.1 = [27 x i8] c"NO SUCH FILE OR DIRECTORY\0A\00"
@.str.2 = [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 = icmp slt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 28)
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %0
%9 = load i32, i32* @O_WRONLY
%10 = load i32, i32* @O_CREAT
%11 = or i32 %10, %9
%12 = load i32, i32* @S_IRUSR
%13 = load i32, i32* @S_IWUSR
%14 = or i32 %13, %12
%15 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %11, i32 %14)
%16 = call i32 @read(i32 %3, i8* %1, i32 1)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %22
18: ; preds = %8, %18
%19 = call i32 @write(i32 %15, i8* %1, i32 1)
%20 = call i32 @read(i32 %3, i8* %1, i32 1)
%21 = icmp eq i32 %20, 1
br i1 %21, label %18, label %22
22: ; preds = %18, %8
%23 = tail call i32 @exit(i32 0)
unreachable
}