#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*/ child_log(char *, ...);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ geteuid();
int /*<<< orphan*/ getuid();
int setresuid(int, int, int);
scalar_t__ strerror(int /*<<< orphan*/);
void do_setresuid(int uid) {
  int result = setresuid(uid, uid, uid);
  if (result == -1) {
    char *msg = (char *)strerror(errno);
    child_log("Child: An error has occurred during the 			  "
              "setresuid call: %d\n%s\n",
              errno, msg);
    child_log("This probably means that the process 			  was "
              "not privilaged enough to make this call\n");
    exit(-1);
  }
  child_log("Child: Uid:%d\nEUid:%d\n", getuid(), geteuid());
  child_log("Child: Successful setresuid\n");
}


x86 assembly (clang, -O0):
<do_setresuid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1030 <setresuid@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11cb <do_setresuid+0x6b>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <child_log@plt>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <child_log@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1050 <getuid@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    -0x14(%rbp),%esi
mov    %eax,%edx
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <child_log@plt>
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1040 <child_log@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_setresuid>:
push   %rbx
mov    %edi,%esi
mov    %edi,%edx
call   1030 <setresuid@plt>
cmp    $0xffffffff,%eax
je     11a0 <do_setresuid+0x40>
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <geteuid@plt>
lea    0xf15(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <child_log@plt>
lea    0xf1a(%rip),%rdi
xor    %eax,%eax
pop    %rbx
jmp    1040 <child_log@plt>
mov    0x2e39(%rip),%rbx
mov    (%rbx),%edi
call   1080 <strerror@plt>
mov    (%rbx),%esi
lea    0xe49(%rip),%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <child_log@plt>
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1040 <child_log@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@errno = global i32 0
@.str = [68 x i8] c"Child: An error has occurred during the \09\09\09 setresuid call: %d\0A%s\0A\00"
@.str.1 = [87 x i8] c"This probably means that the process \09\09\09 was not privilaged enough to make this call\0A\00"
@.str.2 = [23 x i8] c"Child: Uid:%d\0AEUid:%d\0A\00"
@.str.3 = [29 x i8] c"Child: Successful setresuid\0A\00"
define void @do_setresuid(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = load i32, i32* %2
%7 = load i32, i32* %2
%8 = call i32 @setresuid(i32 %5, i32 %6, i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %20
11: ; preds = %1
%12 = load i32, i32* @errno
%13 = call i64 @strerror(i32 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %4
%15 = load i32, i32* @errno
%16 = load i8*, i8** %4
%17 = call i32 (i8*, ...) @child_log(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %16)
%18 = call i32 (i8*, ...) @child_log(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %1
%21 = call i32 (...) @getuid()
%22 = call i32 (...) @geteuid()
%23 = call i32 (i8*, ...) @child_log(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 %22)
%24 = call i32 (i8*, ...) @child_log(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [68 x i8] c"Child: An error has occurred during the \09\09\09 setresuid call: %d\0A%s\0A\00"
@.str.1 = [87 x i8] c"This probably means that the process \09\09\09 was not privilaged enough to make this call\0A\00"
@.str.2 = [23 x i8] c"Child: Uid:%d\0AEUid:%d\0A\00"
@.str.3 = [29 x i8] c"Child: Successful setresuid\0A\00"
define void @do_setresuid(i32 %0) {
%2 = tail call i32 @setresuid(i32 %0, i32 %0, i32 %0)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = load i32, i32* @errno
%6 = tail call i64 @strerror(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = load i32, i32* @errno
%9 = tail call i32 (i8*, ...) @child_log(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i32 %8, i8* %7)
%10 = tail call i32 (i8*, ...) @child_log(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %1
%13 = tail call i32 (...) @getuid()
%14 = tail call i32 (...) @geteuid()
%15 = tail call i32 (i8*, ...) @child_log(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %14)
%16 = tail call i32 (i8*, ...) @child_log(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
ret void
}