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

/* Variables and functions */
char *getenv(char *);
int /*<<< orphan*/ log_stderr(char *, char *);
int /*<<< orphan*/ log_stdout(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strtol(char *, char **, int);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
void set_umask() {
  char *umaskstr = getenv("DUCC_UMASK");
  mode_t umaskval = 0;
  mode_t oldval = 0;
  if (umaskstr != NULL) {
    char *en = 0;
    umaskval = strtol(umaskstr, &en, 8);
    if (*en) {
      log_stderr("4080 UMASK: %s is not numeric/octal; umask not set.\n",
                 umaskstr);
      return;
    }
    oldval = umask(umaskval);
    log_stdout("4090 Umask set to O%o.  Old value: O%o\n", umaskval, oldval);
  }
}


x86 assembly (clang, -O0):
<set_umask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11dd <set_umask+0x8d>
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1060 <strtol@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c0 <set_umask+0x70>
mov    -0x8(%rbp),%rsi
lea    0xe55(%rip),%rdi
call   1040 <log_stderr@plt>
jmp    11dd <set_umask+0x8d>
mov    -0xc(%rbp),%edi
call   1050 <umask@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe68(%rip),%rdi
call   1070 <log_stdout@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_umask>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11b2 <set_umask+0x62>
mov    %rax,%rbx
movq   $0x0,(%rsp)
mov    %rsp,%rsi
mov    %rax,%rdi
mov    $0x8,%edx
call   1060 <strtol@plt>
mov    %eax,%ebp
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     119b <set_umask+0x4b>
lea    0xe7a(%rip),%rdi
mov    %rbx,%rsi
call   1040 <log_stderr@plt>
jmp    11b2 <set_umask+0x62>
mov    %ebp,%edi
call   1050 <umask@plt>
lea    0xe97(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1070 <log_stdout@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"DUCC_UMASK\00"
@.str.1 = [53 x i8] c"4080 UMASK: %s is not numeric/octal; umask not set.\0A\00"
@.str.2 = [40 x i8] c"4090 Umask set to O%o. Old value: O%o\0A\00"
define void @set_umask() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %1
store i32 0, i32* %2
store i32 0, i32* %3
%6 = load i8*, i8** %1
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %23
8: ; preds = %0
store i8* null, i8** %4
%9 = load i8*, i8** %1
%10 = call i32 @strtol(i8* %9, i8** %4, i32 8)
store i32 %10, i32* %2
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = load i8*, i8** %1
%16 = call i32 @log_stderr(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %23
17: ; preds = %8
%18 = load i32, i32* %2
%19 = call i32 @umask(i32 %18)
store i32 %19, i32* %3
%20 = load i32, i32* %2
%21 = load i32, i32* %3
%22 = call i32 @log_stdout(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %21)
br label %23
23: ; preds = %14, %17, %0
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"DUCC_UMASK\00"
@.str.1 = [53 x i8] c"4080 UMASK: %s is not numeric/octal; umask not set.\0A\00"
@.str.2 = [40 x i8] c"4090 Umask set to O%o. Old value: O%o\0A\00"
define void @set_umask() {
%1 = alloca i8*
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %16, label %4
4: ; preds = %0
%5 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%6 = call i32 @strtol(i8* %2, i8** %1, i32 8)
%7 = load i8*, i8** %1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %4
%11 = tail call i32 @log_stderr(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %15
12: ; preds = %4
%13 = tail call i32 @umask(i32 %6)
%14 = tail call i32 @log_stdout(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %6, i32 %13)
br label %15
15: ; preds = %12, %10
br label %16
16: ; preds = %15, %0
ret void
}