#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 creat(char *, int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int read(int, char *, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int f1, f2, n;
  char buf[1000];
  if (argc != 3)
    ;
  if ((f1 = open(argv[1], O_RDONLY, 0)) == -1)
    ;
  if ((f2 = creat(argv[2], 0666)) == -1)
    ;
  while ((n = read(f1, buf, 1000)) > 0)
    if (write(f2, buf, n) != n)
      ;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1168 <main+0x28>
jmp    1168 <main+0x28>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1191 <main+0x51>
jmp    1191 <main+0x51>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x1b6,%esi
call   1060 <creat@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    11b4 <main+0x74>
jmp    11b4 <main+0x74>
jmp    11b9 <main+0x79>
mov    -0x14(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x3e8,%edx
call   1040 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    11fe <main+0xbe>
mov    -0x18(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
cmp    -0x1c(%rbp),%eax
je     11f9 <main+0xb9>
jmp    11f9 <main+0xb9>
jmp    11b9 <main+0x79>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x3f0,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <open@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
mov    $0x1b6,%esi
call   1060 <creat@plt>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x3e8,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    11b0 <main+0x70>
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x3e8,%edx
call   1040 <read@plt>
test   %eax,%eax
jg     1190 <main+0x50>
xor    %eax,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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 [1000 x i8]
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 %13
12: ; preds = %2
br label %13
13: ; preds = %12, %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %16, i32 %17, i32 0)
store i32 %18, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %13
br label %21
21: ; preds = %20, %13
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @creat(i8* %24, i32 438)
store i32 %25, i32* %7
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %28
27: ; preds = %21
br label %28
28: ; preds = %27, %21
br label %29
29: ; preds = %42, %28
%30 = load i32, i32* %6
%31 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%32 = call i32 @read(i32 %30, i8* %31, i32 1000)
store i32 %32, i32* %8
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %43
34: ; preds = %29
%35 = load i32, i32* %7
%36 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%37 = load i32, i32* %8
%38 = call i32 @write(i32 %35, i8* %36, i32 %37)
%39 = load i32, i32* %8
%40 = icmp ne i32 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %34
br label %42
42: ; preds = %41, %34
br label %29
43: ; preds = %29
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %6, i32 %7, i32 0)
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32 @creat(i8* %10, i32 438)
%12 = call i32 @read(i32 %8, i8* %4, i32 1000)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %2, %14
%15 = phi i32 [ %17, %14 ], [ %12, %2 ]
%16 = call i32 @write(i32 %11, i8* %4, i32 %15)
%17 = call i32 @read(i32 %8, i8* %4, i32 1000)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %14, label %19
19: ; preds = %14, %2
ret i32 0
}