#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*/ fopen(char *, char *);
int /*<<< orphan*/ open(char *, int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ system(char *);
int umask(int);
void main() {
  printf("previous umask 0%o\n", umask(0));
  open("f1", O_RDWR | O_CREAT, 0644);
  fopen("f2", "w");
  umask(027);
  open("f3", O_RDWR | O_CREAT, 0777);
  fopen("f4", "w");
  system("ls -l f?");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
xor    %edi,%edi
call   1050 <umask@plt>
mov    %eax,%esi
lea    0xe9c(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    0x2e7f(%rip),%rax
or     (%rax),%esi
lea    0xe92(%rip),%rdi
mov    $0x1a4,%edx
call   1060 <open@plt>
lea    0xe84(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1070 <fopen@plt>
mov    $0x17,%edi
call   1050 <umask@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
mov    0x2e3f(%rip),%rax
or     (%rax),%esi
lea    0xe5a(%rip),%rdi
mov    $0x1ff,%edx
call   1060 <open@plt>
lea    0xe4c(%rip),%rdi
lea    0xe40(%rip),%rsi
call   1070 <fopen@plt>
lea    0xe3c(%rip),%rdi
call   1030 <system@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %edi,%edi
call   1050 <umask@plt>
lea    0xe9d(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x2e6f(%rip),%r14
mov    0x2e80(%rip),%r15
mov    (%r15),%esi
or     (%r14),%esi
lea    0xe8f(%rip),%rdi
mov    $0x1a4,%edx
call   1060 <open@plt>
lea    0xe81(%rip),%rdi
lea    0xe7d(%rip),%rbx
mov    %rbx,%rsi
call   1070 <fopen@plt>
mov    $0x17,%edi
call   1050 <umask@plt>
mov    (%r15),%esi
or     (%r14),%esi
lea    0xe60(%rip),%rdi
mov    $0x1ff,%edx
call   1060 <open@plt>
lea    0xe52(%rip),%rdi
mov    %rbx,%rsi
call   1070 <fopen@plt>
lea    0xe46(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <system@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"previous umask 0%o\0A\00"
@.str.1 = [3 x i8] c"f1\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.2 = [3 x i8] c"f2\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"f3\00"
@.str.5 = [3 x i8] c"f4\00"
@.str.6 = [9 x i8] c"ls -l f?\00"
define void @main() {
%1 = call i32 @umask(i32 0)
%2 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_CREAT
%5 = or i32 %3, %4
%6 = call i32 @open(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 420)
%7 = call i32 @fopen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 @umask(i32 23)
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @O_CREAT
%11 = or i32 %9, %10
%12 = call i32 @open(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %11, i32 511)
%13 = call i32 @fopen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @system(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"previous umask 0%o\0A\00"
@.str.1 = [3 x i8] c"f1\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.2 = [3 x i8] c"f2\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"f3\00"
@.str.5 = [3 x i8] c"f4\00"
@.str.6 = [9 x i8] c"ls -l f?\00"
define void @main() {
%1 = tail call i32 @umask(i32 0)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_CREAT
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 420)
%7 = tail call i32 @fopen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 @umask(i32 23)
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @O_CREAT
%11 = or i32 %10, %9
%12 = tail call i32 @open(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %11, i32 511)
%13 = tail call i32 @fopen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 @system(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
ret void
}