#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__ changeid(int, int, char *);
scalar_t__ config_compare_option(char *, char const *);
scalar_t__ config_get_option(char *);
scalar_t__ getuid();
int /*<<< orphan*/ jlog(int, char *);
int dropprivileges(const char *stage) {
  if (config_compare_option("dropprivileges", stage)) {
    if (config_get_option("runasgroup")) {
      if (changeid(2, 3, "Dropping group privileges") < 0) {
        return -1;
      }
    }
    if (config_get_option("runasuser")) {
      if (changeid(2, 1, "Dropping user privileges") < 0) {
        return -1;
      }
    } else {
      if (getuid() == 0) {
        jlog(2, "Option runasuser not set but dropping "
                "privileges requested - terminating");
        jlog(2, "If you don't have a dropprivileges option in your "
                "configuration file at all, this is because dropprivileges is "
                "a standard option. If you really want to run as root, set "
                "\"dropprivileges never\" in the configuration file.");
        return -1;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<dropprivileges>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe99(%rip),%rdi
call   1050 <config_compare_option@plt>
cmp    $0x0,%rax
je     124d <dropprivileges+0xfd>
lea    0xe92(%rip),%rdi
call   1060 <config_get_option@plt>
cmp    $0x0,%rax
je     11bd <dropprivileges+0x6d>
mov    $0x2,%edi
mov    $0x3,%esi
lea    0xe7d(%rip),%rdx
call   1070 <changeid@plt>
cmp    $0x0,%rax
jge    11b8 <dropprivileges+0x68>
movl   $0xffffffff,-0x4(%rbp)
jmp    1254 <dropprivileges+0x104>
jmp    11bd <dropprivileges+0x6d>
lea    0xe70(%rip),%rdi
call   1060 <config_get_option@plt>
cmp    $0x0,%rax
je     1204 <dropprivileges+0xb4>
mov    $0x2,%edi
mov    $0x1,%esi
lea    0xe5a(%rip),%rdx
call   1070 <changeid@plt>
cmp    $0x0,%rax
jge    11ff <dropprivileges+0xaf>
movl   $0xffffffff,-0x4(%rbp)
jmp    1254 <dropprivileges+0x104>
jmp    1248 <dropprivileges+0xf8>
mov    $0x0,%al
call   1030 <getuid@plt>
cmp    $0x0,%rax
jne    1243 <dropprivileges+0xf3>
mov    $0x2,%edi
lea    0xe36(%rip),%rsi
call   1040 <jlog@plt>
mov    $0x2,%edi
lea    0xe6e(%rip),%rsi
call   1040 <jlog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1254 <dropprivileges+0x104>
jmp    1248 <dropprivileges+0xf8>
jmp    124d <dropprivileges+0xfd>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dropprivileges>:
push   %rax
mov    %rdi,%rsi
lea    0xea5(%rip),%rdi
call   1050 <config_compare_option@plt>
test   %rax,%rax
je     11cb <dropprivileges+0x7b>
lea    0xea3(%rip),%rdi
call   1060 <config_get_option@plt>
test   %rax,%rax
je     1191 <dropprivileges+0x41>
lea    0xe9d(%rip),%rdx
mov    $0x2,%edi
mov    $0x3,%esi
call   1070 <changeid@plt>
test   %rax,%rax
js     11f1 <dropprivileges+0xa1>
lea    0xe9c(%rip),%rdi
call   1060 <config_get_option@plt>
test   %rax,%rax
je     11bf <dropprivileges+0x6f>
lea    0xe95(%rip),%rdx
mov    $0x2,%edi
mov    $0x1,%esi
call   1070 <changeid@plt>
test   %rax,%rax
jns    11cb <dropprivileges+0x7b>
jmp    11f1 <dropprivileges+0xa1>
xor    %eax,%eax
call   1030 <getuid@plt>
test   %rax,%rax
je     11cf <dropprivileges+0x7f>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe81(%rip),%rsi
mov    $0x2,%edi
call   1040 <jlog@plt>
lea    0xeb9(%rip),%rsi
mov    $0x2,%edi
call   1040 <jlog@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"dropprivileges\00"
@.str.1 = [11 x i8] c"runasgroup\00"
@.str.2 = [26 x i8] c"Dropping group privileges\00"
@.str.3 = [10 x i8] c"runasuser\00"
@.str.4 = [25 x i8] c"Dropping user privileges\00"
@.str.5 = [73 x i8] c"Option runasuser not set but dropping privileges requested - terminating\00"
@.str.6 = [219 x i8] c"If you don't have a dropprivileges option in your configuration file at all, this is because dropprivileges is a standard option. If you really want to run as root, set \22dropprivileges never\22 in the configuration file.\00"
define i32 @dropprivileges(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = call i64 @config_compare_option(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %31
7: ; preds = %1
%8 = call i64 @config_get_option(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = call i64 @changeid(i32 2, i32 3, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 -1, i32* %2
br label %32
14: ; preds = %10
br label %15
15: ; preds = %14, %7
%16 = call i64 @config_get_option(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = call i64 @changeid(i32 2, i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 -1, i32* %2
br label %32
22: ; preds = %18
br label %30
23: ; preds = %15
%24 = call i64 (...) @getuid()
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = call i32 @jlog(i32 2, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.5, i64 0, i64 0))
%28 = call i32 @jlog(i32 2, i8* getelementptr inbounds ([219 x i8], [219 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %2
br label %32
29: ; preds = %23
br label %30
30: ; preds = %29, %22
br label %31
31: ; preds = %30, %1
store i32 0, i32* %2
br label %32
32: ; preds = %31, %26, %21, %13
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@.str = [15 x i8] c"dropprivileges\00"
@.str.1 = [11 x i8] c"runasgroup\00"
@.str.2 = [26 x i8] c"Dropping group privileges\00"
@.str.3 = [10 x i8] c"runasuser\00"
@.str.4 = [25 x i8] c"Dropping user privileges\00"
@.str.5 = [73 x i8] c"Option runasuser not set but dropping privileges requested - terminating\00"
@.str.6 = [219 x i8] c"If you don't have a dropprivileges option in your configuration file at all, this is because dropprivileges is a standard option. If you really want to run as root, set \22dropprivileges never\22 in the configuration file.\00"
define i32 @dropprivileges(i8* %0) {
%2 = tail call i64 @config_compare_option(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %22, label %4
4: ; preds = %1
%5 = tail call i64 @config_get_option(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = tail call i64 @changeid(i32 2, i32 3, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp slt i64 %8, 0
br i1 %9, label %23, label %10
10: ; preds = %7, %4
%11 = tail call i64 @config_get_option(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = tail call i64 @changeid(i32 2, i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%15 = icmp slt i64 %14, 0
br i1 %15, label %23, label %22
16: ; preds = %10
%17 = tail call i64 (...) @getuid()
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = tail call i32 @jlog(i32 2, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.5, i64 0, i64 0))
%21 = tail call i32 @jlog(i32 2, i8* getelementptr inbounds ([219 x i8], [219 x i8]* @.str.6, i64 0, i64 0))
br label %23
22: ; preds = %13, %16, %1
br label %23
23: ; preds = %13, %7, %22, %19
%24 = phi i32 [ 0, %22 ], [ -1, %19 ], [ -1, %7 ], [ -1, %13 ]
ret i32 %24
}