#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int in_fd, out_fd, byte_letti, byte_scritti;
  char buffer[4096];
  if (argc != 3)
    exit(1);
  in_fd = open(argv[1], O_RDONLY);
  if (in_fd < 0)
    exit(2);
  out_fd = creat(argv[2], 0700);
  if (out_fd < 0)
    exit(3);
  while (1) {
    byte_letti = read(in_fd, buffer, 4096);
    if (byte_letti <= 0)
      break;
    byte_scritti = write(out_fd, buffer, byte_letti);
    if (byte_scritti <= 0)
      exit(4);
  }
  close(in_fd);
  close(out_fd);
  if (byte_letti == 0)
    exit(0);
  else
    exit(5);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     118d <main+0x2d>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ba <main+0x5a>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x1c0,%esi
call   1070 <creat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11e3 <main+0x83>
mov    $0x3,%edi
call   1080 <exit@plt>
jmp    11e8 <main+0x88>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     120e <main+0xae>
jmp    123c <main+0xdc>
mov    -0x18(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jg     1237 <main+0xd7>
mov    $0x4,%edi
call   1080 <exit@plt>
jmp    11e8 <main+0x88>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    125d <main+0xfd>
xor    %edi,%edi
call   1080 <exit@plt>
mov    $0x5,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
cmp    $0x3,%edi
jne    1195 <main+0x35>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
jns    119f <main+0x3f>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
mov    $0x1c0,%esi
call   1070 <creat@plt>
test   %eax,%eax
jns    11be <main+0x5e>
mov    $0x3,%edi
call   1080 <exit@plt>
mov    %eax,%r15d
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1201 <main+0xa1>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
test   %eax,%eax
jg     11d0 <main+0x70>
mov    $0x4,%edi
call   1080 <exit@plt>
mov    %r14d,%edi
call   1040 <close@plt>
mov    %r15d,%edi
call   1040 <close@plt>
test   %ebp,%ebp
jne    121c <main+0xbc>
xor    %edi,%edi
call   1080 <exit@plt>
mov    $0x5,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = call i32 @exit(i32 2)
unreachable
25: ; preds = %15
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @creat(i8* %28, i32 448)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = call i32 @exit(i32 3)
unreachable
34: ; preds = %25
br label %35
35: ; preds = %34, %51
%36 = load i32, i32* %6
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%38 = call i32 @read(i32 %36, i8* %37, i32 4096)
store i32 %38, i32* %8
%39 = load i32, i32* %8
%40 = icmp sle i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %35
br label %52
42: ; preds = %35
%43 = load i32, i32* %7
%44 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%45 = load i32, i32* %8
%46 = call i32 @write(i32 %43, i8* %44, i32 %45)
store i32 %46, i32* %9
%47 = load i32, i32* %9
%48 = icmp sle i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %42
%50 = call i32 @exit(i32 4)
unreachable
51: ; preds = %42
br label %35
52: ; preds = %41
%53 = load i32, i32* %6
%54 = call i32 @close(i32 %53)
%55 = load i32, i32* %7
%56 = call i32 @close(i32 %55)
%57 = load i32, i32* %8
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %52
%60 = call i32 @exit(i32 0)
unreachable
61: ; preds = %52
%62 = call i32 @exit(i32 5)
unreachable
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* %10, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = tail call i32 @exit(i32 2)
unreachable
16: ; preds = %8
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @creat(i8* %18, i32 448)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @exit(i32 3)
unreachable
23: ; preds = %16, %26
%24 = call i32 @read(i32 %12, i8* %4, i32 4096)
%25 = icmp slt i32 %24, 1
br i1 %25, label %31, label %26
26: ; preds = %23
%27 = call i32 @write(i32 %19, i8* %4, i32 %24)
%28 = icmp slt i32 %27, 1
br i1 %28, label %29, label %23
29: ; preds = %26
%30 = tail call i32 @exit(i32 4)
unreachable
31: ; preds = %23
%32 = tail call i32 @close(i32 %12)
%33 = tail call i32 @close(i32 %19)
%34 = icmp eq i32 %24, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = tail call i32 @exit(i32 0)
unreachable
37: ; preds = %31
%38 = tail call i32 @exit(i32 5)
unreachable
}