#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 chroot(char *);
int /*<<< orphan*/ err(int, char *);
int setgid(int);
int setgroups(int /*<<< orphan*/, int /*<<< orphan*/ *);
int setuid(int);
void drop_privs() {
  if (chroot(".") == -1)
    err(1, "chroot()");
  if (setgroups(0, NULL) == -1)
    err(1, "setgroups()");
  if (setgid(69) == -1)
    err(1, "setgid()");
  if (setuid(69) == -1)
    err(1, "setuid()");
}


x86 assembly (clang, -O0):
<drop_privs>:
push   %rbp
mov    %rsp,%rbp
lea    0xea5(%rip),%rdi
call   1030 <chroot@plt>
cmp    $0xffffffff,%eax
jne    117a <drop_privs+0x2a>
mov    $0x1,%edi
lea    0xe8d(%rip),%rsi
call   1050 <err@plt>
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <setgroups@plt>
cmp    $0xffffffff,%eax
jne    119f <drop_privs+0x4f>
mov    $0x1,%edi
lea    0xe71(%rip),%rsi
call   1050 <err@plt>
mov    $0x45,%edi
call   1060 <setgid@plt>
cmp    $0xffffffff,%eax
jne    11c3 <drop_privs+0x73>
mov    $0x1,%edi
lea    0xe59(%rip),%rsi
call   1050 <err@plt>
mov    $0x45,%edi
call   1070 <setuid@plt>
cmp    $0xffffffff,%eax
jne    11e7 <drop_privs+0x97>
mov    $0x1,%edi
lea    0xe3e(%rip),%rsi
call   1050 <err@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<drop_privs>:
push   %rax
lea    0xea8(%rip),%rdi
call   1030 <chroot@plt>
cmp    $0xffffffff,%eax
jne    1173 <drop_privs+0x23>
lea    0xe99(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1040 <setgroups@plt>
cmp    $0xffffffff,%eax
jne    1192 <drop_privs+0x42>
lea    0xe83(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
mov    $0x45,%edi
call   1060 <setgid@plt>
cmp    $0xffffffff,%eax
jne    11b2 <drop_privs+0x62>
lea    0xe6f(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
mov    $0x45,%edi
call   1070 <setuid@plt>
cmp    $0xffffffff,%eax
je     11c3 <drop_privs+0x73>
pop    %rax
ret
lea    0xe56(%rip),%rsi
mov    $0x1,%edi
pop    %rax
jmp    1050 <err@plt>

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [9 x i8] c"chroot()\00"
@.str.2 = [12 x i8] c"setgroups()\00"
@.str.3 = [9 x i8] c"setgid()\00"
@.str.4 = [9 x i8] c"setuid()\00"
define void @drop_privs() {
%1 = call i32 @chroot(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32 %1, -1
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = call i32 @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %5
5: ; preds = %3, %0
%6 = call i32 @setgroups(i32 0, i32* null)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
%11 = call i32 @setgid(i32 69)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = call i32 @setuid(i32 69)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [9 x i8] c"chroot()\00"
@.str.2 = [12 x i8] c"setgroups()\00"
@.str.3 = [9 x i8] c"setgid()\00"
@.str.4 = [9 x i8] c"setuid()\00"
define void @drop_privs() {
%1 = tail call i32 @chroot(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32 %1, -1
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %5
5: ; preds = %3, %0
%6 = tail call i32 @setgroups(i32 0, i32* null)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
%11 = tail call i32 @setgid(i32 69)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = tail call i32 @setuid(i32 69)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
ret void
}