#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 O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup(int);
int open(char *, int, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd = open(argv[1], O_WRONLY | O_CREAT, 0777);
  close(1);
  dup(fd);
  int i;
  for (i = 0; i < 10; ++i) {
    write(1, "EXAMPLE", 7);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    0x2e8a(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    $0x1,%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%edi
call   1040 <dup@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0xa,-0x18(%rbp)
jge    11c4 <main+0x84>
mov    $0x1,%edi
lea    0xe54(%rip),%rsi
mov    $0x7,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1196 <main+0x56>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x8(%rsi),%rdi
mov    0x2e84(%rip),%rax
mov    0x2ea5(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1ff,%edx
call   1060 <open@plt>
mov    %eax,%ebx
mov    $0x1,%edi
call   1050 <close@plt>
mov    %ebx,%edi
call   1040 <dup@plt>
lea    0xe85(%rip),%rbx
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x7,%edx
call   1030 <write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x7,%edx
call   1030 <write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x7,%edx
call   1030 <write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x7,%edx
call   1030 <write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x7,%edx
call   1030 <write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x7,%edx
call   1030 <write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x7,%edx
call   1030 <write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x7,%edx
call   1030 <write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x7,%edx
call   1030 <write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x7,%edx
call   1030 <write@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str = [8 x i8] c"EXAMPLE\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_WRONLY
%12 = load i32, i32* @O_CREAT
%13 = or i32 %11, %12
%14 = call i32 @open(i8* %10, i32 %13, i32 511)
store i32 %14, i32* %6
%15 = call i32 @close(i32 1)
%16 = load i32, i32* %6
%17 = call i32 @dup(i32 %16)
store i32 0, i32* %7
br label %18
18: ; preds = %23, %2
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 10
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = call i32 @write(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
br label %23
23: ; preds = %21
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %18
26: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str = [8 x i8] c"EXAMPLE\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_CREAT
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* %4, i32 %7, i32 511)
%9 = tail call i32 @close(i32 1)
%10 = tail call i32 @dup(i32 %8)
%11 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%12 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%13 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%14 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%15 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%16 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%17 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%18 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%19 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%20 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
ret i32 0
}