#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*/ close(int);
int /*<<< orphan*/ creat(char *, int);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  if (argc > 1) {
    close(1);
    creat(argv[1], 0644);
  }
  char buf[1000];
  int len;
  while ((len = read(0, buf, 1000)))
    write(1, buf, len);
  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   $0x1,-0x8(%rbp)
jle    117f <main+0x3f>
mov    $0x1,%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
jmp    1184 <main+0x44>
lea    -0x400(%rbp),%rsi
xor    %edi,%edi
mov    $0x3e8,%edx
call   1050 <read@plt>
mov    %eax,-0x404(%rbp)
cmp    $0x0,%eax
je     11c2 <main+0x82>
lea    -0x400(%rbp),%rsi
mov    -0x404(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    1184 <main+0x44>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x3f0,%rsp
cmp    $0x2,%edi
jl     1168 <main+0x28>
mov    %rsi,%rbx
mov    $0x1,%edi
call   1040 <close@plt>
mov    0x8(%rbx),%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x3e8,%edx
call   1050 <read@plt>
test   %eax,%eax
je     11a2 <main+0x62>
mov    %rsp,%rbx
xchg   %ax,%ax
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x3e8,%edx
call   1050 <read@plt>
test   %eax,%eax
jne    1180 <main+0x40>
xor    %eax,%eax
add    $0x3f0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1000 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = call i32 @close(i32 1)
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @creat(i8* %14, i32 420)
br label %16
16: ; preds = %10, %2
br label %17
17: ; preds = %21, %16
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%19 = call i32 @read(i32 0, i8* %18, i32 1000)
store i32 %19, i32* %7
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%23 = load i32, i32* %7
%24 = call i32 @write(i32 1, i8* %22, i32 %23)
br label %17
25: ; preds = %17
ret i32 0
}

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