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

/* Variables and functions */
int /*<<< orphan*/ die(char *);
int getresuid(scalar_t__ *, scalar_t__ *, scalar_t__ *);
int setresuid(scalar_t__, scalar_t__, scalar_t__);
void set_user(uid_t uid) {
  uid_t ruid, euid, suid;
  int status;
  status = setresuid(uid, uid, uid);
  if (status != 0)
    die("unable to set UID");
  status = getresuid(&ruid, &euid, &suid);
  if (status != 0)
    die("unable to check if UID was changed properly");
  if (ruid != uid || euid != uid || suid != uid)
    die("changed UID but it didn't change! (insanity, quitting for security)");
}


x86 assembly (clang, -O0):
<set_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1030 <setresuid@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1166 <set_user+0x36>
lea    0xe9f(%rip),%rdi
call   1050 <die@plt>
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <getresuid@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1190 <set_user+0x60>
lea    0xe87(%rip),%rdi
call   1050 <die@plt>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    11ba <set_user+0x8a>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    11ba <set_user+0x8a>
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     11c6 <set_user+0x96>
lea    0xe7d(%rip),%rdi
call   1050 <die@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_user>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
mov    %rdi,%rsi
mov    %rdi,%rdx
call   1030 <setresuid@plt>
test   %eax,%eax
je     1153 <set_user+0x23>
lea    0xeb2(%rip),%rdi
call   1050 <die@plt>
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1040 <getresuid@plt>
test   %eax,%eax
je     1177 <set_user+0x47>
lea    0xea0(%rip),%rdi
call   1050 <die@plt>
cmp    %rbx,0x18(%rsp)
jne    118c <set_user+0x5c>
cmp    %rbx,0x10(%rsp)
jne    118c <set_user+0x5c>
cmp    %rbx,0x8(%rsp)
je     1198 <set_user+0x68>
lea    0xeab(%rip),%rdi
call   1050 <die@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"unable to set UID\00"
@.str.1 = [44 x i8] c"unable to check if UID was changed properly\00"
@.str.2 = [68 x i8] c"changed UID but it didn't change! (insanity, quitting for security)\00"
define void @set_user(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store i64 %0, i64* %2
%7 = load i64, i64* %2
%8 = load i64, i64* %2
%9 = load i64, i64* %2
%10 = call i32 @setresuid(i64 %7, i64 %8, i64 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @die(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %1
%16 = call i32 @getresuid(i64* %3, i64* %4, i64* %5)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @die(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = load i64, i64* %3
%23 = load i64, i64* %2
%24 = icmp ne i64 %22, %23
br i1 %24, label %33, label %25
25: ; preds = %21
%26 = load i64, i64* %4
%27 = load i64, i64* %2
%28 = icmp ne i64 %26, %27
br i1 %28, label %33, label %29
29: ; preds = %25
%30 = load i64, i64* %5
%31 = load i64, i64* %2
%32 = icmp ne i64 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %29, %25, %21
%34 = call i32 @die(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %29
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"unable to set UID\00"
@.str.1 = [44 x i8] c"unable to check if UID was changed properly\00"
@.str.2 = [68 x i8] c"changed UID but it didn't change! (insanity, quitting for security)\00"
define void @set_user(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = bitcast i64* %2 to i8*
%6 = bitcast i64* %3 to i8*
%7 = bitcast i64* %4 to i8*
%8 = tail call i32 @setresuid(i64 %0, i64 %0, i64 %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = tail call i32 @die(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
%13 = call i32 @getresuid(i64* %2, i64* %3, i64* %4)
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = call i32 @die(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = load i64, i64* %2
%19 = icmp eq i64 %18, %0
%20 = load i64, i64* %3
%21 = icmp eq i64 %20, %0
%22 = select i1 %19, i1 %21, i1 false
%23 = load i64, i64* %4
%24 = icmp eq i64 %23, %0
%25 = select i1 %22, i1 %24, i1 false
br i1 %25, label %28, label %26
26: ; preds = %17
%27 = call i32 @die(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %17, %26
ret void
}