#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 */
scalar_t__ chdir(char *);
int /*<<< orphan*/ clearenv();
int /*<<< orphan*/ close(int);
int dup(int);
int /*<<< orphan*/ umask(int);
int init_security(const char *username) {
  int val;
  (void)umask(022);
  if (chdir("/"))
    return -1;
  val = dup(2);
  if (val < 3)
    return -1;
  close(val);
  (void)clearenv();
  (void)username;
  return 0;
}


x86 assembly (clang, -O0):
<init_security>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x12,%edi
call   1070 <umask@plt>
lea    0xe93(%rip),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
je     1188 <init_security+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c1 <init_security+0x71>
mov    $0x2,%edi
call   1050 <dup@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    11ab <init_security+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c1 <init_security+0x71>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    $0x0,%al
call   1030 <clearenv@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_security>:
push   %rbx
mov    $0x12,%edi
call   1070 <umask@plt>
lea    0xe9e(%rip),%rdi
call   1040 <chdir@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    1190 <init_security+0x40>
mov    $0x2,%edi
call   1050 <dup@plt>
cmp    $0x3,%eax
jl     1190 <init_security+0x40>
mov    %eax,%edi
call   1060 <close@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <clearenv@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i32 @init_security(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = call i32 @umask(i32 18)
%6 = call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %19
9: ; preds = %1
%10 = call i32 @dup(i32 2)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 -1, i32* %2
br label %19
14: ; preds = %9
%15 = load i32, i32* %4
%16 = call i32 @close(i32 %15)
%17 = call i32 (...) @clearenv()
%18 = load i8*, i8** %3
store i32 0, i32* %2
br label %19
19: ; preds = %14, %13, %8
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i32 @init_security(i8* nocapture readnone %0) {
%2 = tail call i32 @umask(i32 18)
%3 = tail call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = tail call i32 @dup(i32 2)
%7 = icmp slt i32 %6, 3
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call i32 @close(i32 %6)
%10 = tail call i32 (...) @clearenv()
br label %11
11: ; preds = %5, %1, %8
%12 = phi i32 [ 0, %8 ], [ -1, %1 ], [ -1, %5 ]
ret i32 %12
}