#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*/ createFile(int);
int /*<<< orphan*/ printFilePerms();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ umask(int);
int /*<<< orphan*/ unlink(char *);
int main(void) {
  printf("Decimal %d and octal %d\n\n", 777, 0777);
  printf("Trying to create a file with rwxrwxrwx permissions with open()\n");
  createFile(0777);
  printFilePerms();
  printf("\n");
  printf("Setting umask to 0000\n");
  umask(0000);
  printf("Trying to create a file with rwxrwxrwx permissions with open()\n");
  createFile(0777);
  printFilePerms();
  printf("\n");
  printf("Setting umask to 0000\n");
  umask(0000);
  printf("Trying to create a file with rwx------ permissions with open()\n");
  createFile(0700);
  printFilePerms();
  printf("\n");
  printf("Setting umask to 0077\n");
  umask(0077);
  printf("Trying to create a file with rwxrwxrwx permissions with open()\n");
  createFile(0777);
  printFilePerms();
  printf("\n");
  printf("Setting umask to 0077\n");
  umask(0077);
  printf("Trying to create a file with rw-rw-rw- permissions with open()\n");
  createFile(0666);
  printFilePerms();
  umask(0321);
  unlink("umask-example.temp");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x309,%esi
mov    $0x1ff,%edx
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1ff,%edi
call   1050 <createFile@plt>
mov    $0x0,%al
call   1070 <printFilePerms@plt>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <umask@plt>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1ff,%edi
call   1050 <createFile@plt>
mov    $0x0,%al
call   1070 <printFilePerms@plt>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <umask@plt>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1c0,%edi
call   1050 <createFile@plt>
mov    $0x0,%al
call   1070 <printFilePerms@plt>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x3f,%edi
call   1060 <umask@plt>
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1ff,%edi
call   1050 <createFile@plt>
mov    $0x0,%al
call   1070 <printFilePerms@plt>
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x3f,%edi
call   1060 <umask@plt>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1b6,%edi
call   1050 <createFile@plt>
mov    $0x0,%al
call   1070 <printFilePerms@plt>
mov    $0xd1,%edi
call   1060 <umask@plt>
lea    0xe53(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe85(%rip),%rdi
mov    $0x309,%esi
mov    $0x1ff,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xeef(%rip),%r14
mov    %r14,%rdi
call   1050 <puts@plt>
mov    $0x1ff,%edi
call   1070 <createFile@plt>
xor    %eax,%eax
call   1090 <printFilePerms@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe70(%rip),%rbx
mov    %rbx,%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   1080 <umask@plt>
mov    %r14,%rdi
call   1050 <puts@plt>
mov    $0x1ff,%edi
call   1070 <createFile@plt>
xor    %eax,%eax
call   1090 <printFilePerms@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   1080 <umask@plt>
lea    0xe3e(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1c0,%edi
call   1070 <createFile@plt>
xor    %eax,%eax
call   1090 <printFilePerms@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe95(%rip),%rbx
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    $0x3f,%edi
call   1080 <umask@plt>
mov    %r14,%rdi
call   1050 <puts@plt>
mov    $0x1ff,%edi
call   1070 <createFile@plt>
xor    %eax,%eax
call   1090 <printFilePerms@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    $0x3f,%edi
call   1080 <umask@plt>
lea    0xe5d(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1b6,%edi
call   1070 <createFile@plt>
xor    %eax,%eax
call   1090 <printFilePerms@plt>
mov    $0xd1,%edi
call   1080 <umask@plt>
lea    0xd79(%rip),%rdi
call   1040 <unlink@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Decimal %d and octal %d\0A\0A\00"
@.str.1 = [64 x i8] c"Trying to create a file with rwxrwxrwx permissions with open()\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [23 x i8] c"Setting umask to 0000\0A\00"
@.str.4 = [64 x i8] c"Trying to create a file with rwx------ permissions with open()\0A\00"
@.str.5 = [23 x i8] c"Setting umask to 0077\0A\00"
@.str.6 = [64 x i8] c"Trying to create a file with rw-rw-rw- permissions with open()\0A\00"
@.str.7 = [19 x i8] c"umask-example.temp\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 777, i32 511)
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @createFile(i32 511)
%5 = call i32 (...) @printFilePerms()
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 @umask(i32 0)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @createFile(i32 511)
%11 = call i32 (...) @printFilePerms()
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @umask(i32 0)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @createFile(i32 448)
%17 = call i32 (...) @printFilePerms()
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%20 = call i32 @umask(i32 63)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @createFile(i32 511)
%23 = call i32 (...) @printFilePerms()
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 @umask(i32 63)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.6, i64 0, i64 0))
%28 = call i32 @createFile(i32 438)
%29 = call i32 (...) @printFilePerms()
%30 = call i32 @umask(i32 209)
%31 = call i32 @unlink(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"Decimal %d and octal %d\0A\0A\00"
@.str.7 = [19 x i8] c"umask-example.temp\00"
@str.10 = [22 x i8] c"Setting umask to 0000\00"
@str.11 = [63 x i8] c"Trying to create a file with rwx------ permissions with open()\00"
@str.13 = [63 x i8] c"Trying to create a file with rwxrwxrwx permissions with open()\00"
@str.14 = [22 x i8] c"Setting umask to 0077\00"
@str.15 = [63 x i8] c"Trying to create a file with rw-rw-rw- permissions with open()\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 777, i32 511)
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str.13, i64 0, i64 0))
%3 = tail call i32 @createFile(i32 511)
%4 = tail call i32 (...) @printFilePerms()
%5 = tail call i32 @putchar(i32 10)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.10, i64 0, i64 0))
%7 = tail call i32 @umask(i32 0)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str.13, i64 0, i64 0))
%9 = tail call i32 @createFile(i32 511)
%10 = tail call i32 (...) @printFilePerms()
%11 = tail call i32 @putchar(i32 10)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.10, i64 0, i64 0))
%13 = tail call i32 @umask(i32 0)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str.11, i64 0, i64 0))
%15 = tail call i32 @createFile(i32 448)
%16 = tail call i32 (...) @printFilePerms()
%17 = tail call i32 @putchar(i32 10)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.14, i64 0, i64 0))
%19 = tail call i32 @umask(i32 63)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str.13, i64 0, i64 0))
%21 = tail call i32 @createFile(i32 511)
%22 = tail call i32 (...) @printFilePerms()
%23 = tail call i32 @putchar(i32 10)
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.14, i64 0, i64 0))
%25 = tail call i32 @umask(i32 63)
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str.15, i64 0, i64 0))
%27 = tail call i32 @createFile(i32 438)
%28 = tail call i32 (...) @printFilePerms()
%29 = tail call i32 @umask(i32 209)
%30 = tail call i32 @unlink(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}