#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*/ PATH_MAX;
int /*<<< orphan*/ execl(char *, char *, char *, char *, char *, char *,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
char *getenv(char *);
scalar_t__ geteuid();
char *getlogin();
scalar_t__ getuid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ realpath(char *, char *);
int main(int argc, char *argv[]) {
  char buffer[PATH_MAX + 1];
  char *p;
  int i, m = 0xFFFF;
  if (geteuid() == 0 || getuid() == 0) {
    realpath(argv[0], buffer);
    execl("/usr/bin/su", "/usr/bin/su", "-", "ast", "-c", buffer, NULL);
    printf("Test  3 cannot run as root; test aborted\n");
    exit(1);
  }
  if ((p = getenv("HOME")) != NULL && *p == '/')
    printf("HOME=%s\n", p);
  if ((p = getenv("PATH")) != NULL)
    printf("PATH=%s\n", p);
  if ((p = getenv("LOGNAME")) != NULL)
    printf("LOGNAME=%s\n", p);
  p = getlogin();
  printf("getlogin=%s\n", p);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0xffff,-0x30(%rbp)
mov    $0x0,%al
call   1060 <geteuid@plt>
cmp    $0x0,%rax
je     11ee <main+0x6e>
mov    $0x0,%al
call   1040 <getuid@plt>
cmp    $0x0,%rax
jne    1250 <main+0xd0>
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <realpath@plt>
mov    -0x38(%rbp),%r9
lea    0xdf7(%rip),%rsi
lea    0xdfc(%rip),%rdx
lea    0xdf7(%rip),%rcx
lea    0xdf4(%rip),%r8
xor    %eax,%eax
sub    $0x10,%rsp
mov    %rsi,%rdi
movq   $0x0,(%rsp)
call   10a0 <execl@plt>
add    $0x10,%rsp
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xde8(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     128c <main+0x10c>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    128c <main+0x10c>
mov    -0x28(%rbp),%rsi
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdba(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     12b8 <main+0x138>
mov    -0x28(%rbp),%rsi
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd9c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     12e4 <main+0x164>
mov    -0x28(%rbp),%rsi
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <getlogin@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
xor    %eax,%eax
call   1070 <geteuid@plt>
test   %rax,%rax
je     1265 <main+0xd5>
xor    %eax,%eax
call   1050 <getuid@plt>
test   %rax,%rax
je     1265 <main+0xd5>
lea    0xe37(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11fe <main+0x6e>
cmpb   $0x2f,(%rax)
jne    11fe <main+0x6e>
lea    0xe26(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe1e(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1220 <main+0x90>
lea    0xe12(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe0a(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1242 <main+0xb2>
lea    0xe01(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1090 <getlogin@plt>
lea    0xdf5(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%r14),%rdi
mov    %rbx,%rsi
call   1080 <realpath@plt>
sub    $0x8,%rsp
lea    0xd85(%rip),%rdi
lea    0xd8a(%rip),%rdx
lea    0xd85(%rip),%rcx
lea    0xd82(%rip),%r8
mov    %rdi,%rsi
mov    %rbx,%r9
push   $0x0
call   10b0 <execl@plt>
add    $0x10,%rsp
lea    0xdaa(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [12 x i8] c"/usr/bin/su\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [4 x i8] c"ast\00"
@.str.3 = [3 x i8] c"-c\00"
@.str.4 = [42 x i8] c"Test 3 cannot run as root; test aborted\0A\00"
@.str.5 = [5 x i8] c"HOME\00"
@.str.6 = [9 x i8] c"HOME=%s\0A\00"
@.str.7 = [5 x i8] c"PATH\00"
@.str.8 = [9 x i8] c"PATH=%s\0A\00"
@.str.9 = [8 x i8] c"LOGNAME\00"
@.str.10 = [12 x i8] c"LOGNAME=%s\0A\00"
@.str.11 = [13 x i8] c"getlogin=%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @PATH_MAX
%12 = add nsw i32 %11, 1
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
store i32 65535, i32* %10
%16 = call i64 (...) @geteuid()
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %2
%19 = call i64 (...) @getuid()
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %18, %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 @realpath(i8* %24, i8* %15)
%26 = call i32 @execl(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %15, i32* null)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %18
%30 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i8* %30, i8** %8
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %40
32: ; preds = %29
%33 = load i8*, i8** %8
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 47
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i8*, i8** %8
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %37, %32, %29
%41 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
store i8* %41, i8** %8
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i8*, i8** %8
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %43, %40
%47 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
store i8* %47, i8** %8
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i8*, i8** %8
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %49, %46
%53 = call i8* (...) @getlogin()
store i8* %53, i8** %8
%54 = load i8*, i8** %8
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i8* %54)
store i32 0, i32* %3
%56 = load i8*, i8** %6
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [12 x i8] c"/usr/bin/su\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [4 x i8] c"ast\00"
@.str.3 = [3 x i8] c"-c\00"
@.str.5 = [5 x i8] c"HOME\00"
@.str.6 = [9 x i8] c"HOME=%s\0A\00"
@.str.7 = [5 x i8] c"PATH\00"
@.str.8 = [9 x i8] c"PATH=%s\0A\00"
@.str.9 = [8 x i8] c"LOGNAME\00"
@.str.10 = [12 x i8] c"LOGNAME=%s\0A\00"
@.str.11 = [13 x i8] c"getlogin=%s\0A\00"
@str = [41 x i8] c"Test 3 cannot run as root; test aborted\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @PATH_MAX
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = tail call i64 (...) @geteuid()
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = tail call i64 (...) @getuid()
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %9, %2
%13 = load i8*, i8** %1
%14 = call i32 @realpath(i8* %13, i8* %6)
%15 = call i32 @execl(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %6, i32* null)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %9
%19 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %26, label %21
21: ; preds = %18
%22 = load i8, i8* %19
%23 = icmp eq i8 %22, 47
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %19)
br label %26
26: ; preds = %24, %21, %18
%27 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%28 = icmp eq i8* %27, null
br i1 %28, label %31, label %29
29: ; preds = %26
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %27)
br label %31
31: ; preds = %29, %26
%32 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
%33 = icmp eq i8* %32, null
br i1 %33, label %36, label %34
34: ; preds = %31
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8* %32)
br label %36
36: ; preds = %34, %31
%37 = tail call i8* (...) @getlogin()
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i8* %37)
ret i32 0
}