#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int O_EXCL;
int O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ umask(int);
int main(int argc, char **argv) {
  if (open("foo1", O_CREAT | O_EXCL | O_WRONLY,
           S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) == -1) {
    perror("create error for foo1");
    exit(EXIT_FAILURE);
  }
  umask(0);
  if (open("foo2", O_CREAT | O_EXCL | O_WRONLY,
           S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) == -1) {
    perror("create error for foo2");
    exit(EXIT_FAILURE);
  }
  umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
  if (open("foo3", O_CREAT | O_EXCL | O_WRONLY,
           S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) == -1) {
    perror("create error for foo3");
    exit(EXIT_FAILURE);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    0x2e62(%rip),%rax
or     (%rax),%esi
mov    0x2e21(%rip),%rax
or     (%rax),%esi
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
mov    0x2e57(%rip),%rax
or     (%rax),%edx
mov    0x2e36(%rip),%rax
or     (%rax),%edx
mov    0x2e4d(%rip),%rax
or     (%rax),%edx
mov    0x2e1c(%rip),%rax
or     (%rax),%edx
mov    0x2de3(%rip),%rax
or     (%rax),%edx
lea    0xe63(%rip),%rdi
call   1040 <open@plt>
cmp    $0xffffffff,%eax
jne    11d6 <main+0x96>
lea    0xe3d(%rip),%rdi
call   1050 <perror@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
xor    %edi,%edi
call   1030 <umask@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
mov    0x2ddb(%rip),%rax
or     (%rax),%esi
mov    0x2d9a(%rip),%rax
or     (%rax),%esi
mov    0x2da9(%rip),%rax
mov    (%rax),%edx
mov    0x2dd0(%rip),%rax
or     (%rax),%edx
mov    0x2daf(%rip),%rax
or     (%rax),%edx
mov    0x2dc6(%rip),%rax
or     (%rax),%edx
mov    0x2d95(%rip),%rax
or     (%rax),%edx
mov    0x2d5c(%rip),%rax
or     (%rax),%edx
lea    0xdf2(%rip),%rdi
call   1040 <open@plt>
cmp    $0xffffffff,%eax
jne    125d <main+0x11d>
lea    0xdcc(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
mov    0x2d73(%rip),%rax
or     (%rax),%edi
mov    0x2d42(%rip),%rax
or     (%rax),%edi
mov    0x2d09(%rip),%rax
or     (%rax),%edi
call   1030 <umask@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%esi
mov    0x2d32(%rip),%rax
or     (%rax),%esi
mov    0x2cf1(%rip),%rax
or     (%rax),%esi
mov    0x2d00(%rip),%rax
mov    (%rax),%edx
mov    0x2d27(%rip),%rax
or     (%rax),%edx
mov    0x2d06(%rip),%rax
or     (%rax),%edx
mov    0x2d1d(%rip),%rax
or     (%rax),%edx
mov    0x2cec(%rip),%rax
or     (%rax),%edx
mov    0x2cb3(%rip),%rax
or     (%rax),%edx
lea    0xd5f(%rip),%rdi
call   1040 <open@plt>
cmp    $0xffffffff,%eax
jne    1306 <main+0x1c6>
lea    0xd39(%rip),%rdi
call   1050 <perror@plt>
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2c93(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2ea6(%rip),%rax
mov    0x2e6f(%rip),%r13
mov    0x0(%r13),%esi
or     (%rax),%esi
mov    0x2e2a(%rip),%rax
or     (%rax),%esi
mov    0x2e39(%rip),%rax
mov    0x2e62(%rip),%rbx
mov    (%rbx),%edx
or     (%rax),%edx
mov    0x2e3f(%rip),%rbp
or     0x0(%rbp),%edx
mov    0x2e55(%rip),%r14
or     (%r14),%edx
mov    0x2e23(%rip),%r15
or     (%r15),%edx
mov    0x2de9(%rip),%r12
or     (%r12),%edx
lea    0xe67(%rip),%rdi
call   1040 <open@plt>
cmp    $0xffffffff,%eax
je     1267 <main+0x127>
xor    %edi,%edi
call   1030 <umask@plt>
mov    0x0(%r13),%esi
mov    0x2e2e(%rip),%rax
or     (%rax),%esi
mov    0x2dbd(%rip),%rax
or     (%rax),%esi
mov    (%rbx),%edx
mov    0x2dca(%rip),%rax
or     (%rax),%edx
or     0x0(%rbp),%edx
or     (%r14),%edx
or     (%r15),%edx
or     (%r12),%edx
lea    0xe33(%rip),%rdi
call   1040 <open@plt>
cmp    $0xffffffff,%eax
je     1270 <main+0x130>
mov    (%r14),%edi
or     0x0(%rbp),%edi
or     (%r15),%edi
or     (%r12),%edi
call   1030 <umask@plt>
mov    0x0(%r13),%esi
mov    0x2ddd(%rip),%rax
or     (%rax),%esi
mov    0x2d6c(%rip),%rax
or     (%rax),%esi
mov    (%rbx),%edx
mov    0x2d79(%rip),%rax
or     (%rax),%edx
or     0x0(%rbp),%edx
or     (%r14),%edx
or     (%r15),%edx
or     (%r12),%edx
lea    0xdf8(%rip),%rdi
call   1040 <open@plt>
cmp    $0xffffffff,%eax
je     1279 <main+0x139>
mov    0x2d4a(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd92(%rip),%rdi
jmp    1280 <main+0x140>
lea    0xd9f(%rip),%rdi
jmp    1280 <main+0x140>
lea    0xdac(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"foo1\00"
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_WRONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@.str.1 = [22 x i8] c"create error for foo1\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"foo2\00"
@.str.3 = [22 x i8] c"create error for foo2\00"
@.str.4 = [5 x i8] c"foo3\00"
@.str.5 = [22 x i8] c"create error for foo3\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* @O_CREAT
%7 = load i32, i32* @O_EXCL
%8 = or i32 %6, %7
%9 = load i32, i32* @O_WRONLY
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IRUSR
%12 = load i32, i32* @S_IWUSR
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IRGRP
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IWGRP
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IROTH
%19 = or i32 %17, %18
%20 = load i32, i32* @S_IWOTH
%21 = or i32 %19, %20
%22 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %28
24: ; preds = %2
%25 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %2
%29 = call i32 @umask(i32 0)
%30 = load i32, i32* @O_CREAT
%31 = load i32, i32* @O_EXCL
%32 = or i32 %30, %31
%33 = load i32, i32* @O_WRONLY
%34 = or i32 %32, %33
%35 = load i32, i32* @S_IRUSR
%36 = load i32, i32* @S_IWUSR
%37 = or i32 %35, %36
%38 = load i32, i32* @S_IRGRP
%39 = or i32 %37, %38
%40 = load i32, i32* @S_IWGRP
%41 = or i32 %39, %40
%42 = load i32, i32* @S_IROTH
%43 = or i32 %41, %42
%44 = load i32, i32* @S_IWOTH
%45 = or i32 %43, %44
%46 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %34, i32 %45)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %52
48: ; preds = %28
%49 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %28
%53 = load i32, i32* @S_IRGRP
%54 = load i32, i32* @S_IWGRP
%55 = or i32 %53, %54
%56 = load i32, i32* @S_IROTH
%57 = or i32 %55, %56
%58 = load i32, i32* @S_IWOTH
%59 = or i32 %57, %58
%60 = call i32 @umask(i32 %59)
%61 = load i32, i32* @O_CREAT
%62 = load i32, i32* @O_EXCL
%63 = or i32 %61, %62
%64 = load i32, i32* @O_WRONLY
%65 = or i32 %63, %64
%66 = load i32, i32* @S_IRUSR
%67 = load i32, i32* @S_IWUSR
%68 = or i32 %66, %67
%69 = load i32, i32* @S_IRGRP
%70 = or i32 %68, %69
%71 = load i32, i32* @S_IWGRP
%72 = or i32 %70, %71
%73 = load i32, i32* @S_IROTH
%74 = or i32 %72, %73
%75 = load i32, i32* @S_IWOTH
%76 = or i32 %74, %75
%77 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %65, i32 %76)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %83
79: ; preds = %52
%80 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%81 = load i32, i32* @EXIT_FAILURE
%82 = call i32 @exit(i32 %81)
unreachable
83: ; preds = %52
%84 = load i32, i32* @EXIT_SUCCESS
ret i32 %84
}

LLVM IR (-O2):
@.str = [5 x i8] c"foo1\00"
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_WRONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@.str.1 = [22 x i8] c"create error for foo1\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"foo2\00"
@.str.3 = [22 x i8] c"create error for foo2\00"
@.str.4 = [5 x i8] c"foo3\00"
@.str.5 = [22 x i8] c"create error for foo3\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_CREAT
%4 = load i32, i32* @O_EXCL
%5 = or i32 %4, %3
%6 = load i32, i32* @O_WRONLY
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IRUSR
%9 = load i32, i32* @S_IWUSR
%10 = or i32 %9, %8
%11 = load i32, i32* @S_IRGRP
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IWGRP
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IROTH
%16 = or i32 %14, %15
%17 = load i32, i32* @S_IWOTH
%18 = or i32 %16, %17
%19 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %25
21: ; preds = %2
%22 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %2
%26 = tail call i32 @umask(i32 0)
%27 = load i32, i32* @O_CREAT
%28 = load i32, i32* @O_EXCL
%29 = or i32 %28, %27
%30 = load i32, i32* @O_WRONLY
%31 = or i32 %29, %30
%32 = load i32, i32* @S_IRUSR
%33 = load i32, i32* @S_IWUSR
%34 = or i32 %33, %32
%35 = load i32, i32* @S_IRGRP
%36 = or i32 %34, %35
%37 = load i32, i32* @S_IWGRP
%38 = or i32 %36, %37
%39 = load i32, i32* @S_IROTH
%40 = or i32 %38, %39
%41 = load i32, i32* @S_IWOTH
%42 = or i32 %40, %41
%43 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %31, i32 %42)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %49
45: ; preds = %25
%46 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = tail call i32 @exit(i32 %47)
unreachable
49: ; preds = %25
%50 = load i32, i32* @S_IRGRP
%51 = load i32, i32* @S_IWGRP
%52 = or i32 %51, %50
%53 = load i32, i32* @S_IROTH
%54 = or i32 %52, %53
%55 = load i32, i32* @S_IWOTH
%56 = or i32 %54, %55
%57 = tail call i32 @umask(i32 %56)
%58 = load i32, i32* @O_CREAT
%59 = load i32, i32* @O_EXCL
%60 = or i32 %59, %58
%61 = load i32, i32* @O_WRONLY
%62 = or i32 %60, %61
%63 = load i32, i32* @S_IRUSR
%64 = load i32, i32* @S_IWUSR
%65 = or i32 %64, %63
%66 = load i32, i32* @S_IRGRP
%67 = or i32 %65, %66
%68 = load i32, i32* @S_IWGRP
%69 = or i32 %67, %68
%70 = load i32, i32* @S_IROTH
%71 = or i32 %69, %70
%72 = load i32, i32* @S_IWOTH
%73 = or i32 %71, %72
%74 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %62, i32 %73)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %80
76: ; preds = %49
%77 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%78 = load i32, i32* @EXIT_FAILURE
%79 = tail call i32 @exit(i32 %78)
unreachable
80: ; preds = %49
%81 = load i32, i32* @EXIT_SUCCESS
ret i32 %81
}