#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*/ assert(int);
int seteuid(scalar_t__);
int setuid(scalar_t__);
int /*<<< orphan*/ warn(char *);
int setresuid(uid_t ruid, uid_t euid, uid_t suid) {
  assert(ruid == euid && euid == suid);
  if (seteuid(euid) == -1) {
    warn("seteuid");
    return -1;
  } else if (setuid(euid) == -1) {
    warn("setuid");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<setresuid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x21(%rbp)
jne    1175 <setresuid+0x35>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1060 <seteuid@plt>
cmp    $0xffffffff,%eax
jne    11ac <setresuid+0x6c>
lea    0xe65(%rip),%rdi
call   1030 <warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <setresuid+0xa2>
mov    -0x18(%rbp),%rdi
call   1050 <setuid@plt>
cmp    $0xffffffff,%eax
jne    11d6 <setresuid+0x96>
lea    0xe43(%rip),%rdi
call   1030 <warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <setresuid+0xa2>
jmp    11db <setresuid+0x9b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setresuid>:
push   %rbx
mov    %rsi,%rbx
xor    %rsi,%rdi
xor    %rsi,%rdx
xor    %eax,%eax
or     %rdi,%rdx
sete   %al
mov    %eax,%edi
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1060 <seteuid@plt>
cmp    $0xffffffff,%eax
je     1179 <setresuid+0x39>
mov    %rbx,%rdi
call   1050 <setuid@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     1182 <setresuid+0x42>
pop    %rbx
ret
lea    0xe80(%rip),%rdi
jmp    1189 <setresuid+0x49>
lea    0xe7f(%rip),%rdi
call   1030 <warn@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"seteuid\00"
@.str.1 = [7 x i8] c"setuid\00"
define i32 @setresuid(i64 %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i64 %0, i64* %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%8 = load i64, i64* %5
%9 = load i64, i64* %6
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = load i64, i64* %6
%13 = load i64, i64* %7
%14 = icmp eq i64 %12, %13
br label %15
15: ; preds = %11, %3
%16 = phi i1 [ false, %3 ], [ %14, %11 ]
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i64, i64* %6
%20 = call i32 @seteuid(i64 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 @warn(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %32
24: ; preds = %15
%25 = load i64, i64* %6
%26 = call i32 @setuid(i64 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %32
30: ; preds = %24
br label %31
31: ; preds = %30
store i32 0, i32* %4
br label %32
32: ; preds = %31, %28, %22
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@.str = [8 x i8] c"seteuid\00"
@.str.1 = [7 x i8] c"setuid\00"
define i32 @setresuid(i64 %0, i64 %1, i64 %2) {
%4 = icmp eq i64 %0, %1
%5 = icmp eq i64 %1, %2
%6 = and i1 %4, %5
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i32 @seteuid(i64 %1)
%10 = icmp eq i32 %9, -1
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = tail call i32 @setuid(i64 %1)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %11, %3
%15 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %11 ]
%16 = tail call i32 @warn(i8* %15)
br label %17
17: ; preds = %14, %11
%18 = phi i32 [ 0, %11 ], [ -1, %14 ]
ret i32 %18
}