#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 */
typedef int mode_t;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ open(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int umask(int);
int main() {
  mode_t new_mask, oldmask;
  printf("Enter new umask :");
  scanf("%u", &new_mask);
  oldmask = umask(new_mask);
  printf("Umask changed from %u\n to %u\n", oldmask, new_mask);
  char str1[15];
  mode_t mode;
  printf("Enter file name: ");
  scanf("%s", str1);
  printf("Enter file mode: ");
  open(str1, O_RDWR | O_CREAT, 465);
  scanf("%u", &mode);
  printf("File %s created with mode %u\n", str1, mode);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb5(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x4(%rbp),%edi
call   1040 <umask@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x4(%rbp),%edx
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x17(%rbp),%rsi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x17(%rbp),%rdi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
mov    0x2e2f(%rip),%rax
or     (%rax),%esi
mov    $0x1d1,%edx
call   1060 <open@plt>
lea    0xe36(%rip),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    -0x17(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xeb2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb6(%rip),%r14
mov    %rsp,%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    (%rsp),%edi
call   1040 <umask@plt>
mov    (%rsp),%edx
lea    0xe9a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeac(%rip),%rdi
lea    0x9(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xe99(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e23(%rip),%rax
mov    0x2e34(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1d1,%edx
call   1060 <open@plt>
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x4(%rsp),%edx
lea    0xe6b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Enter new umask :\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [30 x i8] c"Umask changed from %u\0A to %u\0A\00"
@.str.3 = [18 x i8] c"Enter file name: \00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [18 x i8] c"Enter file mode: \00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.6 = [30 x i8] c"File %s created with mode %u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [15 x i8]
%4 = alloca i32
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = call i32 @umask(i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = load i32, i32* %1
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %9, i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%13 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%16 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%17 = load i32, i32* @O_RDWR
%18 = load i32, i32* @O_CREAT
%19 = or i32 %17, %18
%20 = call i32 @open(i8* %16, i32 %19, i32 465)
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%22 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%23 = load i32, i32* %4
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* %22, i32 %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"Enter new umask :\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [30 x i8] c"Umask changed from %u\0A to %u\0A\00"
@.str.3 = [18 x i8] c"Enter file name: \00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [18 x i8] c"Enter file mode: \00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.6 = [30 x i8] c"File %s created with mode %u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [15 x i8]
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = call i32 @umask(i32 %7)
%9 = load i32, i32* %1
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %8, i32 %9)
%11 = getelementptr inbounds [15 x i8], [15 x i8]* %2, i64 0, i64 0
%12 = bitcast i32* %3 to i8*
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%16 = load i32, i32* @O_RDWR
%17 = load i32, i32* @O_CREAT
%18 = or i32 %17, %16
%19 = call i32 @open(i8* %11, i32 %18, i32 465)
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%21 = load i32, i32* %3
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* %11, i32 %21)
ret i32 0
}