#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 /*<<< orphan*/ exit(int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ umask(int);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("please input filename\n");
    exit(1);
  } else {
    int fd;
    umask(0000);
    fd = open(argv[1], O_RDWR | O_CREAT, 0664);
    if (fd < 0) {
      printf("error\n");
      exit(1);
    } else {
      printf("success=%d\n", fd);
      close(fd);
      printf("closed\n");
    }
  }
  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)
cmpl   $0x2,-0x8(%rbp)
jge    1188 <main+0x38>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
xor    %edi,%edi
call   1050 <umask@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
mov    0x2e51(%rip),%rax
or     (%rax),%esi
mov    $0x1b4,%edx
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d8 <main+0x88>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1204 <main+0xb4>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x1,%edi
jle    11bd <main+0x5d>
mov    %rsi,%rbx
xor    %edi,%edi
call   1060 <umask@plt>
mov    0x8(%rbx),%rdi
mov    0x2e65(%rip),%rax
mov    0x2e76(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1b4,%edx
call   1070 <open@plt>
test   %eax,%eax
js     11c6 <main+0x66>
mov    %eax,%ebx
lea    0xe63(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
lea    0xe58(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe55(%rip),%rdi
jmp    11cd <main+0x6d>
lea    0xe46(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"please input filename\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [7 x i8] c"error\0A\00"
@.str.2 = [12 x i8] c"success=%d\0A\00"
@.str.3 = [8 x i8] c"closed\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 i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = call i32 @umask(i32 0)
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDWR
%18 = load i32, i32* @O_CREAT
%19 = or i32 %17, %18
%20 = call i32 @open(i8* %16, i32 %19, i32 436)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %12
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %12
%27 = load i32, i32* %6
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %6
%30 = call i32 @close(i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %26
br label %33
33: ; preds = %32
ret i32 0
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.2 = [12 x i8] c"success=%d\0A\00"
@str = [7 x i8] c"closed\00"
@str.4 = [6 x i8] c"error\00"
@str.5 = [22 x i8] c"please input filename\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.5, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = tail call i32 @umask(i32 0)
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDWR
%12 = load i32, i32* @O_CREAT
%13 = or i32 %12, %11
%14 = tail call i32 @open(i8* %10, i32 %13, i32 436)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %7
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.4, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %7
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%21 = tail call i32 @close(i32 %14)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
ret i32 0
}