#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_IRWXG;
int S_IRWXO;
int S_IRWXU;
scalar_t__ creat(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ umask(int);
int main(int argc, char *argv[]) {
  umask(0);
  if (creat("example_umask1.txt", S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
    perror("creat");
    exit(1);
  }
  umask(S_IRWXO);
  if (creat("example_umask2.txt", S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
    perror("creat");
    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   1030 <umask@plt>
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
mov    0x2e6b(%rip),%rax
or     (%rax),%esi
mov    0x2e7a(%rip),%rax
or     (%rax),%esi
lea    0xe81(%rip),%rdi
call   1050 <creat@plt>
cmp    $0x0,%rax
jge    11a4 <main+0x64>
lea    0xe7e(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1030 <umask@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
mov    0x2e16(%rip),%rax
or     (%rax),%esi
mov    0x2e25(%rip),%rax
or     (%rax),%esi
lea    0xe45(%rip),%rdi
call   1050 <creat@plt>
cmp    $0x0,%rax
jge    11f9 <main+0xb9>
lea    0xe29(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@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   1030 <umask@plt>
mov    0x2e8d(%rip),%r14
mov    0x2e7e(%rip),%r15
mov    (%r15),%esi
or     (%r14),%esi
mov    0x2e89(%rip),%rbx
or     (%rbx),%esi
lea    0xe90(%rip),%rdi
call   1050 <creat@plt>
test   %rax,%rax
js     11a2 <main+0x62>
mov    (%rbx),%edi
call   1030 <umask@plt>
mov    (%r15),%esi
or     (%r14),%esi
or     (%rbx),%esi
lea    0xe89(%rip),%rdi
call   1050 <creat@plt>
test   %rax,%rax
js     11a2 <main+0x62>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe6a(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"example_umask1.txt\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@.str.1 = [6 x i8] c"creat\00"
@.str.2 = [19 x i8] c"example_umask2.txt\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 ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i32, i32* @S_IRWXO
%19 = call i32 @umask(i32 %18)
%20 = load i32, i32* @S_IRWXU
%21 = load i32, i32* @S_IRWXG
%22 = or i32 %20, %21
%23 = load i32, i32* @S_IRWXO
%24 = or i32 %22, %23
%25 = call i64 @creat(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %17
%28 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %17
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"example_umask1.txt\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@.str.1 = [6 x i8] c"creat\00"
@.str.2 = [19 x i8] c"example_umask2.txt\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 ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i32, i32* @S_IRWXO
%16 = tail call i32 @umask(i32 %15)
%17 = load i32, i32* @S_IRWXU
%18 = load i32, i32* @S_IRWXG
%19 = or i32 %18, %17
%20 = load i32, i32* @S_IRWXO
%21 = or i32 %19, %20
%22 = tail call i64 @creat(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %14
%25 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %14
ret i32 0
}