#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ getgid();
int /*<<< orphan*/ getuid();
scalar_t__ setresgid(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ setresuid(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void drop_privileges() {
  if (setresuid(-1, getuid(), getuid()) || setresgid(-1, getgid(), getgid())) {
    fprintf(stderr, "ERROR: Failed to drop privileges.\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<drop_privileges>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    -0x4(%rbp),%esi
mov    %eax,%edx
mov    $0xffffffff,%edi
call   1030 <setresuid@plt>
cmp    $0x0,%rax
jne    11bc <drop_privileges+0x5c>
mov    $0x0,%al
call   1070 <getgid@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1070 <getgid@plt>
mov    -0x8(%rbp),%esi
mov    %eax,%edx
mov    $0xffffffff,%edi
call   1050 <setresgid@plt>
cmp    $0x0,%rax
je     11db <drop_privileges+0x7b>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drop_privileges>:
push   %rbx
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <getuid@plt>
mov    $0xffffffff,%edi
mov    %ebx,%esi
mov    %eax,%edx
call   1030 <setresuid@plt>
test   %rax,%rax
jne    11a9 <drop_privileges+0x49>
xor    %eax,%eax
call   1070 <getgid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <getgid@plt>
mov    $0xffffffff,%edi
mov    %ebx,%esi
mov    %eax,%edx
call   1050 <setresgid@plt>
test   %rax,%rax
jne    11a9 <drop_privileges+0x49>
pop    %rbx
ret
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"ERROR: Failed to drop privileges.\0A\00"
define void @drop_privileges() {
%1 = call i32 (...) @getuid()
%2 = call i32 (...) @getuid()
%3 = call i64 @setresuid(i32 -1, i32 %1, i32 %2)
%4 = icmp ne i64 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %0
%6 = call i32 (...) @getgid()
%7 = call i32 (...) @getgid()
%8 = call i64 @setresgid(i32 -1, i32 %6, i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %5, %0
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %5
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"ERROR: Failed to drop privileges.\0A\00"
define void @drop_privileges() {
%1 = tail call i32 (...) @getuid()
%2 = tail call i32 (...) @getuid()
%3 = tail call i64 @setresuid(i32 -1, i32 %1, i32 %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = tail call i32 (...) @getgid()
%7 = tail call i32 (...) @getgid()
%8 = tail call i64 @setresgid(i32 -1, i32 %6, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %5, %0
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %5
ret void
}