#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 S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
scalar_t__ creat(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ umask(int);
int main(int argc, char const *argv[]) {
  umask(0);
  if (creat("foo",
            (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)) < 0) {
    fprintf(stderr, "creat error for foo\n");
    exit(1);
  }
  umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
  if (creat("bar",
            (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)) < 0) {
    fprintf(stderr, "creat error for bar\n");
    exit(1);
  }
  return 0;
}


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)
xor    %edi,%edi
call   1040 <umask@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
mov    0x2e73(%rip),%rax
or     (%rax),%esi
mov    0x2e52(%rip),%rax
or     (%rax),%esi
mov    0x2e69(%rip),%rax
or     (%rax),%esi
mov    0x2e38(%rip),%rax
or     (%rax),%esi
mov    0x2e17(%rip),%rax
or     (%rax),%esi
lea    0xe66(%rip),%rdi
call   1050 <creat@plt>
cmp    $0x0,%rax
jge    11c8 <main+0x88>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    0x2e10(%rip),%rax
or     (%rax),%edi
mov    0x2ddf(%rip),%rax
or     (%rax),%edi
mov    0x2dbe(%rip),%rax
or     (%rax),%edi
call   1040 <umask@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
mov    0x2ddf(%rip),%rax
or     (%rax),%esi
mov    0x2dbe(%rip),%rax
or     (%rax),%esi
mov    0x2dd5(%rip),%rax
or     (%rax),%esi
mov    0x2da4(%rip),%rax
or     (%rax),%esi
mov    0x2d83(%rip),%rax
or     (%rax),%esi
lea    0xdeb(%rip),%rdi
call   1050 <creat@plt>
cmp    $0x0,%rax
jge    125c <main+0x11c>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %eax,%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
xor    %edi,%edi
call   1040 <umask@plt>
mov    0x2e5f(%rip),%r14
mov    0x2e80(%rip),%r15
mov    (%r15),%esi
or     (%r14),%esi
mov    0x2e5b(%rip),%r12
or     (%r12),%esi
mov    0x2e70(%rip),%r13
or     0x0(%r13),%esi
mov    0x2e3d(%rip),%rbx
or     (%rbx),%esi
mov    0x2e1c(%rip),%rbp
or     0x0(%rbp),%esi
lea    0xe6a(%rip),%rdi
call   1050 <creat@plt>
test   %rax,%rax
js     11e7 <main+0xa7>
mov    0x0(%r13),%edi
or     (%r12),%edi
or     (%rbx),%edi
or     0x0(%rbp),%edi
call   1040 <umask@plt>
mov    (%r15),%esi
or     (%r14),%esi
or     (%r12),%esi
or     0x0(%r13),%esi
or     (%rbx),%esi
or     0x0(%rbp),%esi
lea    0xe4d(%rip),%rdi
call   1050 <creat@plt>
test   %rax,%rax
js     11f9 <main+0xb9>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
jmp    1209 <main+0xc9>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"foo\00"
@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
@stderr = global i32 0
@.str.1 = [21 x i8] c"creat error for foo\0A\00"
@.str.2 = [4 x i8] c"bar\00"
@.str.3 = [21 x i8] c"creat error for bar\0A\00"
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 = call i32 @umask(i32 0)
%7 = load i32, i32* @S_IRUSR
%8 = load i32, i32* @S_IWUSR
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IRGRP
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IWGRP
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IROTH
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IWOTH
%17 = or i32 %15, %16
%18 = call i64 @creat(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
%25 = load i32, i32* @S_IRGRP
%26 = load i32, i32* @S_IWGRP
%27 = or i32 %25, %26
%28 = load i32, i32* @S_IROTH
%29 = or i32 %27, %28
%30 = load i32, i32* @S_IWOTH
%31 = or i32 %29, %30
%32 = call i32 @umask(i32 %31)
%33 = load i32, i32* @S_IRUSR
%34 = load i32, i32* @S_IWUSR
%35 = or i32 %33, %34
%36 = load i32, i32* @S_IRGRP
%37 = or i32 %35, %36
%38 = load i32, i32* @S_IWGRP
%39 = or i32 %37, %38
%40 = load i32, i32* @S_IROTH
%41 = or i32 %39, %40
%42 = load i32, i32* @S_IWOTH
%43 = or i32 %41, %42
%44 = call i64 @creat(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %24
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %24
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"foo\00"
@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
@stderr = global i32 0
@.str.1 = [21 x i8] c"creat error for foo\0A\00"
@.str.2 = [4 x i8] c"bar\00"
@.str.3 = [21 x i8] c"creat error for bar\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @umask(i32 0)
%4 = load i32, i32* @S_IRUSR
%5 = load i32, i32* @S_IWUSR
%6 = or i32 %5, %4
%7 = load i32, i32* @S_IRGRP
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IWGRP
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IROTH
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IWOTH
%14 = or i32 %12, %13
%15 = tail call i64 @creat(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i32, i32* @S_IRGRP
%23 = load i32, i32* @S_IWGRP
%24 = or i32 %23, %22
%25 = load i32, i32* @S_IROTH
%26 = or i32 %24, %25
%27 = load i32, i32* @S_IWOTH
%28 = or i32 %26, %27
%29 = tail call i32 @umask(i32 %28)
%30 = load i32, i32* @S_IRUSR
%31 = load i32, i32* @S_IWUSR
%32 = or i32 %31, %30
%33 = load i32, i32* @S_IRGRP
%34 = or i32 %32, %33
%35 = load i32, i32* @S_IWGRP
%36 = or i32 %34, %35
%37 = load i32, i32* @S_IROTH
%38 = or i32 %36, %37
%39 = load i32, i32* @S_IWOTH
%40 = or i32 %38, %39
%41 = tail call i64 @creat(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %21
%44 = load i32, i32* @stderr
%45 = tail call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%46 = tail call i32 @exit(i32 1)
unreachable
47: ; preds = %21
ret i32 0
}