#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_IRWXG;
int S_IRWXO;
int S_IRWXU;
int S_IWGRP;
int S_IWOTH;
scalar_t__ creat(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ umask(int);
int main(int argc, char *argv[]) {
  umask(0);
  if (creat("foo", S_IRWXU | S_IRWXG | S_IRWXO))
    printf("create foo failed.\n");
  umask(S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH);
  if (creat("bar", S_IRWXU | S_IRWXG | S_IRWXO))
    printf("creat bar failed.\n");
  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    0x2e8c(%rip),%rax
mov    (%rax),%esi
mov    0x2e7b(%rip),%rax
or     (%rax),%esi
mov    0x2e8a(%rip),%rax
or     (%rax),%esi
lea    0xe91(%rip),%rdi
call   1050 <creat@plt>
cmp    $0x0,%rax
je     118a <main+0x5a>
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    0x2e26(%rip),%rax
or     (%rax),%edi
mov    0x2e05(%rip),%rax
or     (%rax),%edi
mov    0x2e0c(%rip),%rax
or     (%rax),%edi
call   1040 <umask@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
mov    0x2e15(%rip),%rax
or     (%rax),%esi
mov    0x2e24(%rip),%rax
or     (%rax),%esi
lea    0xe43(%rip),%rdi
call   1050 <creat@plt>
cmp    $0x0,%rax
je     11f0 <main+0xc0>
lea    0xe31(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %edi,%edi
call   1040 <umask@plt>
mov    0x2e9d(%rip),%r14
mov    0x2e8e(%rip),%rbx
mov    (%rbx),%esi
or     (%r14),%esi
mov    0x2e9a(%rip),%r15
or     (%r15),%esi
lea    0xea0(%rip),%rdi
call   1050 <creat@plt>
test   %rax,%rax
je     1176 <main+0x46>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e53(%rip),%rax
mov    0x2e3c(%rip),%rcx
mov    (%rcx),%edi
or     (%rax),%edi
mov    0x2e19(%rip),%rax
or     (%rax),%edi
mov    0x2e20(%rip),%rax
or     (%rax),%edi
call   1040 <umask@plt>
mov    (%rbx),%esi
or     (%r14),%esi
or     (%r15),%esi
lea    0xe56(%rip),%rdi
call   1050 <creat@plt>
test   %rax,%rax
je     11c4 <main+0x94>
lea    0xe49(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"foo\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@.str.1 = [20 x i8] c"create foo failed.\0A\00"
@S_IWGRP = global i32 0
@S_IRGRP = global i32 0
@S_IWOTH = global i32 0
@S_IROTH = global i32 0
@.str.2 = [4 x i8] c"bar\00"
@.str.3 = [19 x i8] c"creat bar failed.\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_IRWXU
%8 = load i32, i32* @S_IRWXG
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IRWXO
%11 = or i32 %9, %10
%12 = call i64 @creat(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = load i32, i32* @S_IWGRP
%18 = load i32, i32* @S_IRGRP
%19 = or i32 %17, %18
%20 = load i32, i32* @S_IWOTH
%21 = or i32 %19, %20
%22 = load i32, i32* @S_IROTH
%23 = or i32 %21, %22
%24 = call i32 @umask(i32 %23)
%25 = load i32, i32* @S_IRWXU
%26 = load i32, i32* @S_IRWXG
%27 = or i32 %25, %26
%28 = load i32, i32* @S_IRWXO
%29 = or i32 %27, %28
%30 = call i64 @creat(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %16
%33 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %32, %16
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"foo\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@S_IWGRP = global i32 0
@S_IRGRP = global i32 0
@S_IWOTH = global i32 0
@S_IROTH = global i32 0
@.str.2 = [4 x i8] c"bar\00"
@str = [18 x i8] c"creat bar failed.\00"
@str.4 = [19 x i8] c"create foo failed.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @umask(i32 0)
%4 = load i32, i32* @S_IRWXU
%5 = load i32, i32* @S_IRWXG
%6 = or i32 %5, %4
%7 = load i32, i32* @S_IRWXO
%8 = or i32 %6, %7
%9 = tail call i64 @creat(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.4, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = load i32, i32* @S_IWGRP
%15 = load i32, i32* @S_IRGRP
%16 = or i32 %15, %14
%17 = load i32, i32* @S_IWOTH
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IROTH
%20 = or i32 %18, %19
%21 = tail call i32 @umask(i32 %20)
%22 = load i32, i32* @S_IRWXU
%23 = load i32, i32* @S_IRWXG
%24 = or i32 %23, %22
%25 = load i32, i32* @S_IRWXO
%26 = or i32 %24, %25
%27 = tail call i64 @creat(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %13
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %31
31: ; preds = %29, %13
ret i32 0
}