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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  FILE *fp1, *fp2;
  char buf[1024];
  int nbytes;
  if (argc != 3) {
    printf("wrong command\n");
    exit(1);
  }
  if ((fp1 = fopen(argv[1], "rb")) == NULL) {
    perror("fail to open");
    exit(1);
  }
  if ((fp2 = fopen(argv[2], "wb")) == NULL) {
    perror("fail to open");
    exit(1);
  }
  while ((nbytes = fread(buf, sizeof(char), 1024, fp1)) > 0) {
    if (fwrite(buf, sizeof(char), nbytes, fp2) == -1) {
      perror("fail to write");
      exit(1);
    }
  }
  if (nbytes == -1) {
    perror("fail to read");
    exit(1);
  }
  fclose(fp1);
  fclose(fp2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a9 <main+0x39>
lea    0xe66(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe57(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11e1 <main+0x71>
lea    0xe40(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe2f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1219 <main+0xa9>
lea    0xe08(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    121e <main+0xae>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %eax,-0x424(%rbp)
cmp    $0x0,%eax
jle    1286 <main+0x116>
lea    -0x420(%rbp),%rdi
mov    -0x424(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1090 <fwrite@plt>
cmp    $0xffffffff,%eax
jne    1281 <main+0x111>
lea    0xdb0(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    121e <main+0xae>
cmpl   $0xffffffff,-0x424(%rbp)
jne    12a9 <main+0x139>
lea    0xd96(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
cmp    $0x3,%edi
jne    1233 <main+0xc3>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe6d(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     122a <main+0xba>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe61(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     122a <main+0xba>
mov    %rax,%r15
mov    %rsp,%rbx
nop
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jle    1206 <main+0x96>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
cmp    $0xffffffff,%eax
jne    11c0 <main+0x50>
lea    0xe1c(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
cmp    $0xffffffff,%eax
je     1249 <main+0xd9>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdd2(%rip),%rdi
jmp    11f7 <main+0x87>
lea    0xdf4(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xdd1(%rip),%rdi
jmp    11f7 <main+0x87>

LLVM IR (-O0):
@.str = [15 x i8] c"wrong command\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [13 x i8] c"fail to open\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [14 x i8] c"fail to write\00"
@.str.5 = [13 x i8] c"fail to read\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [1024 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%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 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %6
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %15
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %28, i32** %7
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %24
br label %34
34: ; preds = %48, %33
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%36 = load i32*, i32** %6
%37 = call i32 @fread(i8* %35, i32 1, i32 1024, i32* %36)
store i32 %37, i32* %9
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %49
39: ; preds = %34
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%41 = load i32, i32* %9
%42 = load i32*, i32** %7
%43 = call i32 @fwrite(i8* %40, i32 1, i32 %41, i32* %42)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %48
45: ; preds = %39
%46 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %39
br label %34
49: ; preds = %34
%50 = load i32, i32* %9
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %49
%56 = load i32*, i32** %6
%57 = call i32 @fclose(i32* %56)
%58 = load i32*, i32** %7
%59 = call i32 @fclose(i32* %58)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [13 x i8] c"fail to open\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [14 x i8] c"fail to write\00"
@.str.5 = [13 x i8] c"fail to read\00"
@str = [14 x i8] c"wrong command\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %9
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %17, %28
%26 = call i32 @fread(i8* %4, i32 1, i32 1024, i32* %12)
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = call i32 @fwrite(i8* %4, i32 1, i32 %26, i32* %20)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %25
31: ; preds = %28
%32 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %25
%35 = icmp eq i32 %26, -1
br i1 %35, label %36, label %39
36: ; preds = %34
%37 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%38 = tail call i32 @exit(i32 1)
unreachable
39: ; preds = %34
%40 = tail call i32 @fclose(i32* %12)
%41 = tail call i32 @fclose(i32* %20)
ret i32 0
}