#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*/ EINVAL;
int /*<<< orphan*/ errno;
unsigned int strtoul(char *, char **, int);
int umask(unsigned int);
int set_umask(char *mask_string) {
  int rc;
  unsigned mask;
  char *end;
  mask = strtoul(mask_string, &end, 8);
  if (!end || *end != '\0') {
    errno = EINVAL;
    return -1;
  }
  rc = umask(mask);
  return rc;
}


x86 assembly (clang, -O0):
<set_umask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1040 <strtoul@plt>
mov    %eax,-0x18(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     115c <set_umask+0x3c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     117a <set_umask+0x5a>
mov    0x2e75(%rip),%rax
mov    (%rax),%ecx
mov    0x2e74(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    118b <set_umask+0x6b>
mov    -0x18(%rbp),%edi
call   1030 <umask@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_umask>:
push   %rax
mov    %rsp,%rsi
mov    $0x8,%edx
call   1040 <strtoul@plt>
mov    (%rsp),%rcx
test   %rcx,%rcx
je     113c <set_umask+0x1c>
cmpb   $0x0,(%rcx)
je     1155 <set_umask+0x35>
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    0x2e94(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rcx
ret
mov    %eax,%edi
pop    %rax
jmp    1030 <umask@plt>

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @set_umask(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strtoul(i8* %7, i8** %6, i32 8)
store i32 %8, i32* %5
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i8*, i8** %6
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11, %1
%17 = load i32, i32* @EINVAL
store i32 %17, i32* @errno
store i32 -1, i32* %2
br label %22
18: ; preds = %11
%19 = load i32, i32* %5
%20 = call i32 @umask(i32 %19)
store i32 %20, i32* %4
%21 = load i32, i32* %4
store i32 %21, i32* %2
br label %22
22: ; preds = %18, %16
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @set_umask(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i32 @strtoul(i8* %0, i8** %2, i32 8)
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7, %1
%11 = load i32, i32* @EINVAL
store i32 %11, i32* @errno
br label %14
12: ; preds = %7
%13 = tail call i32 @umask(i32 %4)
br label %14
14: ; preds = %12, %10
%15 = phi i32 [ -1, %10 ], [ %13, %12 ]
ret i32 %15
}