#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 uid_t;

/* Variables and functions */
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int geteuid();
int getuid();
int /*<<< orphan*/ perror(char *);
scalar_t__ setgid(int /*<<< orphan*/);
scalar_t__ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  uid_t uid;
  uid_t euid;
  char *user_name;
  uid = getuid();
  euid = geteuid();
  if (uid != 500) {
    fprintf(stderr, "DAVRAP: uid not httpd uid (%i), but %i.\n", 500, uid);
  } else if (euid != 0) {
    fprintf(stderr, "DAVRAP: euid not 0, but %i.\n", euid);
  } else if (setgid(0) != 0) {
    fprintf(stderr, "DAVRAP: Can't setgid()\n");
    perror("setgid");
  } else if (setuid(0) != 0) {
    fprintf(stderr, "DAVRAP: Can't setuid()\n");
  } else {
    fprintf(stderr, "DAVRAP: OK, exe %s\n", "/bin/umount");
    execv("/bin/umount", argv);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1040 <geteuid@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1f4,-0x14(%rbp)
je     11cb <main+0x5b>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%ecx
lea    0xe46(%rip),%rsi
mov    $0x1f4,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1297 <main+0x127>
cmpl   $0x0,-0x18(%rbp)
je     11f4 <main+0x84>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xe41(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1292 <main+0x122>
xor    %edi,%edi
call   1060 <setgid@plt>
cmp    $0x0,%rax
je     122d <main+0xbd>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    0xe3b(%rip),%rdi
call   1070 <perror@plt>
jmp    128d <main+0x11d>
xor    %edi,%edi
call   1080 <setuid@plt>
cmp    $0x0,%rax
je     125a <main+0xea>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1288 <main+0x118>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
lea    0xe20(%rip),%rdx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe0e(%rip),%rdi
call   1090 <execv@plt>
jmp    128d <main+0x11d>
jmp    1292 <main+0x122>
jmp    1297 <main+0x127>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
xor    %eax,%eax
call   1030 <getuid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <geteuid@plt>
cmp    $0x1f4,%ebp
jne    11ad <main+0x3d>
test   %eax,%eax
je     11d4 <main+0x64>
mov    0x2e47(%rip),%rcx
mov    (%rcx),%edi
lea    0xe87(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11cb <main+0x5b>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
mov    $0x1f4,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %edi,%edi
call   1060 <setgid@plt>
test   %rax,%rax
jne    122a <main+0xba>
xor    %edi,%edi
call   1080 <setuid@plt>
mov    0x2df2(%rip),%rcx
mov    (%rcx),%edi
test   %rax,%rax
je     1205 <main+0x95>
lea    0xe69(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11cb <main+0x5b>
lea    0xe71(%rip),%rsi
lea    0xe7e(%rip),%rbp
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1090 <execv@plt>
jmp    11cb <main+0x5b>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe16(%rip),%rdi
call   1070 <perror@plt>
jmp    11cb <main+0x5b>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"DAVRAP: uid not httpd uid (%i), but %i.\0A\00"
@.str.1 = [29 x i8] c"DAVRAP: euid not 0, but %i.\0A\00"
@.str.2 = [24 x i8] c"DAVRAP: Can't setgid()\0A\00"
@.str.3 = [7 x i8] c"setgid\00"
@.str.4 = [24 x i8] c"DAVRAP: Can't setuid()\0A\00"
@.str.5 = [20 x i8] c"DAVRAP: OK, exe %s\0A\00"
@.str.6 = [12 x i8] c"/bin/umount\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @getuid()
store i32 %9, i32* %6
%10 = call i32 (...) @geteuid()
store i32 %10, i32* %7
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 500
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i32, i32* %6
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 500, i32 %15)
br label %45
17: ; preds = %2
%18 = load i32, i32* %7
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = load i32, i32* %7
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %44
24: ; preds = %17
%25 = call i64 @setgid(i32 0)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %43
31: ; preds = %24
%32 = call i64 @setuid(i32 0)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %42
37: ; preds = %31
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%40 = load i8**, i8*** %5
%41 = call i32 @execv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8** %40)
br label %42
42: ; preds = %37, %34
br label %43
43: ; preds = %42, %27
br label %44
44: ; preds = %43, %20
br label %45
45: ; preds = %44, %13
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"DAVRAP: uid not httpd uid (%i), but %i.\0A\00"
@.str.1 = [29 x i8] c"DAVRAP: euid not 0, but %i.\0A\00"
@.str.2 = [24 x i8] c"DAVRAP: Can't setgid()\0A\00"
@.str.3 = [7 x i8] c"setgid\00"
@.str.4 = [24 x i8] c"DAVRAP: Can't setuid()\0A\00"
@.str.5 = [20 x i8] c"DAVRAP: OK, exe %s\0A\00"
@.str.6 = [12 x i8] c"/bin/umount\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 (...) @getuid()
%4 = tail call i32 (...) @geteuid()
%5 = icmp eq i32 %3, 500
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 500, i32 %3)
br label %30
9: ; preds = %2
%10 = icmp eq i32 %4, 0
br i1 %10, label %14, label %11
11: ; preds = %9
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %4)
br label %30
14: ; preds = %9
%15 = tail call i64 @setgid(i32 0)
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %30
21: ; preds = %14
%22 = tail call i64 @setuid(i32 0)
%23 = icmp eq i64 %22, 0
%24 = load i32, i32* @stderr
br i1 %23, label %27, label %25
25: ; preds = %21
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %30
27: ; preds = %21
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%29 = tail call i32 @execv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8** %1)
br label %30
30: ; preds = %11, %25, %27, %17, %6
ret i32 0
}