#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_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, char *, ...);
int main(int argc, char *argv[]) {
  int fd;
  fd = open(argv[1], O_CREAT | O_RDWR, 0777);
  if (fd < 0) {
    printf("create file %s failure\n", argv[1]);
    return -1;
  }
  printf("create file %s success, fd=%d\n", argv[1], fd);
  close(fd);
  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    0x2ea3(%rip),%rax
mov    (%rax),%esi
mov    0x2e82(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1199 <main+0x69>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c1 <main+0x91>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x14(%rbp),%edx
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
mov    0x2eb7(%rip),%rax
mov    0x2e98(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1ff,%edx
call   1050 <open@plt>
mov    0x8(%rbp),%rsi
test   %eax,%eax
js     117b <main+0x4b>
mov    %eax,%ebx
lea    0xeb1(%rip),%rdi
xor    %ebp,%ebp
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
call   1040 <close@plt>
jmp    118e <main+0x5e>
lea    0xe7e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str = [24 x i8] c"create file %s failure\0A\00"
@.str.1 = [31 x i8] c"create file %s success, fd=%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_CREAT
%11 = load i32, i32* @O_RDWR
%12 = or i32 %10, %11
%13 = call i32 @open(i8* %9, i32 %12, i32 511)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 -1, i32* %3
br label %29
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* %6
%26 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %24, i32 %25)
%27 = load i32, i32* %6
%28 = call i32 @close(i32 %27)
store i32 0, i32* %3
br label %29
29: ; preds = %21, %16
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str = [24 x i8] c"create file %s failure\0A\00"
@.str.1 = [31 x i8] c"create file %s success, fd=%d\0A\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_CREAT
%6 = load i32, i32* @O_RDWR
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* %4, i32 %7, i32 511)
%9 = icmp slt i32 %8, 0
%10 = load i8*, i8** %3
br i1 %9, label %11, label %13
11: ; preds = %2
%12 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %16
13: ; preds = %2
%14 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 %8)
%15 = tail call i32 @close(i32 %8)
br label %16
16: ; preds = %13, %11
%17 = phi i32 [ -1, %11 ], [ 0, %13 ]
ret i32 %17
}