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

/* Variables and functions */
scalar_t__ EFAULT;
scalar_t__ EPERM;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int getresuid(int *, int *, int *);
int setresuid(int, int, int);
int test_get_set_uid(void) {
  uid_t ruid, euid, suid;
  int error;
  error = getresuid((void *)1, (void *)1, (void *)1);
  assert(error < 0 && errno == EFAULT);
  error = getresuid(&ruid, &euid, &suid);
  assert(error == 0);
  assert(ruid == 0 && euid == 0 && suid == 0);
  ruid = 1, euid = 2, suid = 3;
  error = setresuid(ruid, euid, suid);
  assert(error == 0);
  getresuid(&ruid, &euid, &suid);
  assert(ruid == 1 && euid == 2 && suid == 3);
  ruid = -1, euid = 3, suid = -1;
  error = setresuid(ruid, euid, suid);
  assert(error == 0);
  getresuid(&ruid, &euid, &suid);
  assert(ruid == 1 && euid == 3 && suid == 3);
  ruid = -1, euid = 2, suid = -1;
  error = setresuid(ruid, euid, suid);
  assert(error < 0 && errno == EPERM);
  getresuid(&ruid, &euid, &suid);
  assert(ruid == 1 && euid == 3 && suid == 3);
  return 0;
}


x86 assembly (clang, -O0):
<test_get_set_uid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x1,%edx
mov    %rdx,%rdi
mov    %rdx,%rsi
call   1050 <getresuid@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jge    1174 <test_get_set_uid+0x44>
mov    0x2e77(%rip),%rax
mov    (%rax),%rax
mov    0x2e8d(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0x4(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <getresuid@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x12(%rbp)
jne    11ce <test_get_set_uid+0x9e>
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x12(%rbp)
jne    11ce <test_get_set_uid+0x9e>
cmpl   $0x0,-0xc(%rbp)
sete   %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0x3,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <setresuid@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0x4(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <getresuid@plt>
xor    %eax,%eax
cmpl   $0x1,-0x4(%rbp)
mov    %al,-0x13(%rbp)
jne    124b <test_get_set_uid+0x11b>
xor    %eax,%eax
cmpl   $0x2,-0x8(%rbp)
mov    %al,-0x13(%rbp)
jne    124b <test_get_set_uid+0x11b>
cmpl   $0x3,-0xc(%rbp)
sete   %al
mov    %al,-0x13(%rbp)
mov    -0x13(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x3,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <setresuid@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0x4(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <getresuid@plt>
xor    %eax,%eax
cmpl   $0x1,-0x4(%rbp)
mov    %al,-0x14(%rbp)
jne    12c8 <test_get_set_uid+0x198>
xor    %eax,%eax
cmpl   $0x3,-0x8(%rbp)
mov    %al,-0x14(%rbp)
jne    12c8 <test_get_set_uid+0x198>
cmpl   $0x3,-0xc(%rbp)
sete   %al
mov    %al,-0x14(%rbp)
mov    -0x14(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <setresuid@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x15(%rbp)
jge    1324 <test_get_set_uid+0x1f4>
mov    0x2cc7(%rip),%rax
mov    (%rax),%rax
mov    0x2cad(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0x4(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <getresuid@plt>
xor    %eax,%eax
cmpl   $0x1,-0x4(%rbp)
mov    %al,-0x16(%rbp)
jne    136a <test_get_set_uid+0x23a>
xor    %eax,%eax
cmpl   $0x3,-0x8(%rbp)
mov    %al,-0x16(%rbp)
jne    136a <test_get_set_uid+0x23a>
cmpl   $0x3,-0xc(%rbp)
sete   %al
mov    %al,-0x16(%rbp)
mov    -0x16(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_get_set_uid>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x1,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1050 <getresuid@plt>
test   %eax,%eax
sets   %al
mov    0x2e7d(%rip),%r12
mov    (%r12),%rcx
mov    0x2e92(%rip),%rdx
cmp    (%rdx),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
lea    0x14(%rsp),%rbx
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r15
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <getresuid@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    0x14(%rsp),%eax
or     0x10(%rsp),%eax
xor    %edi,%edi
or     0xc(%rsp),%eax
sete   %dil
call   1040 <assert@plt>
movl   $0x1,0x14(%rsp)
movl   $0x2,0x10(%rsp)
movl   $0x3,0xc(%rsp)
mov    $0x1,%edi
mov    $0x2,%esi
mov    $0x3,%edx
call   1030 <setresuid@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <getresuid@plt>
mov    0x14(%rsp),%eax
xor    $0x1,%eax
mov    0x10(%rsp),%ecx
xor    $0x2,%ecx
or     %eax,%ecx
mov    0xc(%rsp),%eax
xor    $0x3,%eax
xor    %edi,%edi
or     %ecx,%eax
sete   %dil
call   1040 <assert@plt>
movl   $0xffffffff,0x14(%rsp)
ff
movl   $0x3,0x10(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
mov    $0xffffffff,%edi
mov    $0x3,%esi
mov    $0xffffffff,%edx
call   1030 <setresuid@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <getresuid@plt>
mov    0x14(%rsp),%eax
xor    $0x1,%eax
mov    0x10(%rsp),%ecx
xor    $0x3,%ecx
or     %eax,%ecx
mov    0xc(%rsp),%eax
xor    $0x3,%eax
xor    %edi,%edi
or     %ecx,%eax
sete   %dil
call   1040 <assert@plt>
movl   $0xffffffff,0x14(%rsp)
ff
movl   $0x2,0x10(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
mov    $0xffffffff,%edi
mov    $0x2,%esi
mov    $0xffffffff,%edx
call   1030 <setresuid@plt>
test   %eax,%eax
sets   %al
mov    (%r12),%rcx
mov    0x2cff(%rip),%rdx
cmp    (%rdx),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <getresuid@plt>
mov    0x14(%rsp),%eax
xor    $0x1,%eax
mov    0x10(%rsp),%ecx
xor    $0x3,%ecx
or     %eax,%ecx
mov    0xc(%rsp),%eax
xor    $0x3,%eax
xor    %edi,%edi
or     %ecx,%eax
sete   %dil
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@EFAULT = global i64 0
@EPERM = global i64 0
define i32 @test_get_set_uid() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 @getresuid(i32* inttoptr (i64 1 to i32*), i32* inttoptr (i64 1 to i32*), i32* inttoptr (i64 1 to i32*))
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i64, i64* @errno
%10 = load i64, i64* @EFAULT
%11 = icmp eq i64 %9, %10
br label %12
12: ; preds = %8, %0
%13 = phi i1 [ false, %0 ], [ %11, %8 ]
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = call i32 @getresuid(i32* %1, i32* %2, i32* %3)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* %1
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %12
%24 = load i32, i32* %2
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %3
%28 = icmp eq i32 %27, 0
br label %29
29: ; preds = %26, %23, %12
%30 = phi i1 [ false, %23 ], [ false, %12 ], [ %28, %26 ]
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
store i32 1, i32* %1
store i32 2, i32* %2
store i32 3, i32* %3
%33 = load i32, i32* %1
%34 = load i32, i32* %2
%35 = load i32, i32* %3
%36 = call i32 @setresuid(i32 %33, i32 %34, i32 %35)
store i32 %36, i32* %4
%37 = load i32, i32* %4
%38 = icmp eq i32 %37, 0
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = call i32 @getresuid(i32* %1, i32* %2, i32* %3)
%42 = load i32, i32* %1
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %50
44: ; preds = %29
%45 = load i32, i32* %2
%46 = icmp eq i32 %45, 2
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i32, i32* %3
%49 = icmp eq i32 %48, 3
br label %50
50: ; preds = %47, %44, %29
%51 = phi i1 [ false, %44 ], [ false, %29 ], [ %49, %47 ]
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
store i32 -1, i32* %1
store i32 3, i32* %2
store i32 -1, i32* %3
%54 = load i32, i32* %1
%55 = load i32, i32* %2
%56 = load i32, i32* %3
%57 = call i32 @setresuid(i32 %54, i32 %55, i32 %56)
store i32 %57, i32* %4
%58 = load i32, i32* %4
%59 = icmp eq i32 %58, 0
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
%62 = call i32 @getresuid(i32* %1, i32* %2, i32* %3)
%63 = load i32, i32* %1
%64 = icmp eq i32 %63, 1
br i1 %64, label %65, label %71
65: ; preds = %50
%66 = load i32, i32* %2
%67 = icmp eq i32 %66, 3
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load i32, i32* %3
%70 = icmp eq i32 %69, 3
br label %71
71: ; preds = %68, %65, %50
%72 = phi i1 [ false, %65 ], [ false, %50 ], [ %70, %68 ]
%73 = zext i1 %72 to i32
%74 = call i32 @assert(i32 %73)
store i32 -1, i32* %1
store i32 2, i32* %2
store i32 -1, i32* %3
%75 = load i32, i32* %1
%76 = load i32, i32* %2
%77 = load i32, i32* %3
%78 = call i32 @setresuid(i32 %75, i32 %76, i32 %77)
store i32 %78, i32* %4
%79 = load i32, i32* %4
%80 = icmp slt i32 %79, 0
br i1 %80, label %81, label %85
81: ; preds = %71
%82 = load i64, i64* @errno
%83 = load i64, i64* @EPERM
%84 = icmp eq i64 %82, %83
br label %85
85: ; preds = %81, %71
%86 = phi i1 [ false, %71 ], [ %84, %81 ]
%87 = zext i1 %86 to i32
%88 = call i32 @assert(i32 %87)
%89 = call i32 @getresuid(i32* %1, i32* %2, i32* %3)
%90 = load i32, i32* %1
%91 = icmp eq i32 %90, 1
br i1 %91, label %92, label %98
92: ; preds = %85
%93 = load i32, i32* %2
%94 = icmp eq i32 %93, 3
br i1 %94, label %95, label %98
95: ; preds = %92
%96 = load i32, i32* %3
%97 = icmp eq i32 %96, 3
br label %98
98: ; preds = %95, %92, %85
%99 = phi i1 [ false, %92 ], [ false, %85 ], [ %97, %95 ]
%100 = zext i1 %99 to i32
%101 = call i32 @assert(i32 %100)
ret i32 0
}

LLVM IR (-O2):
@errno = global i64 0
@EFAULT = global i64 0
@EPERM = global i64 0
define i32 @test_get_set_uid() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 @getresuid(i32* inttoptr (i64 1 to i32*), i32* inttoptr (i64 1 to i32*), i32* inttoptr (i64 1 to i32*))
%8 = icmp slt i32 %7, 0
%9 = load i64, i64* @errno
%10 = load i64, i64* @EFAULT
%11 = icmp eq i64 %9, %10
%12 = select i1 %8, i1 %11, i1 false
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = call i32 @getresuid(i32* %1, i32* %2, i32* %3)
%16 = icmp eq i32 %15, 0
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32, i32* %1
%20 = icmp eq i32 %19, 0
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, 0
%23 = select i1 %20, i1 %22, i1 false
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 0
%26 = select i1 %23, i1 %25, i1 false
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
store i32 1, i32* %1
store i32 2, i32* %2
store i32 3, i32* %3
%29 = call i32 @setresuid(i32 1, i32 2, i32 3)
%30 = icmp eq i32 %29, 0
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = call i32 @getresuid(i32* %1, i32* %2, i32* %3)
%34 = load i32, i32* %1
%35 = icmp eq i32 %34, 1
%36 = load i32, i32* %2
%37 = icmp eq i32 %36, 2
%38 = select i1 %35, i1 %37, i1 false
%39 = load i32, i32* %3
%40 = icmp eq i32 %39, 3
%41 = select i1 %38, i1 %40, i1 false
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
store i32 -1, i32* %1
store i32 3, i32* %2
store i32 -1, i32* %3
%44 = call i32 @setresuid(i32 -1, i32 3, i32 -1)
%45 = icmp eq i32 %44, 0
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = call i32 @getresuid(i32* %1, i32* %2, i32* %3)
%49 = load i32, i32* %1
%50 = icmp eq i32 %49, 1
%51 = load i32, i32* %2
%52 = icmp eq i32 %51, 3
%53 = select i1 %50, i1 %52, i1 false
%54 = load i32, i32* %3
%55 = icmp eq i32 %54, 3
%56 = select i1 %53, i1 %55, i1 false
%57 = zext i1 %56 to i32
%58 = call i32 @assert(i32 %57)
store i32 -1, i32* %1
store i32 2, i32* %2
store i32 -1, i32* %3
%59 = call i32 @setresuid(i32 -1, i32 2, i32 -1)
%60 = icmp slt i32 %59, 0
%61 = load i64, i64* @errno
%62 = load i64, i64* @EPERM
%63 = icmp eq i64 %61, %62
%64 = select i1 %60, i1 %63, i1 false
%65 = zext i1 %64 to i32
%66 = call i32 @assert(i32 %65)
%67 = call i32 @getresuid(i32* %1, i32* %2, i32* %3)
%68 = load i32, i32* %1
%69 = icmp eq i32 %68, 1
%70 = load i32, i32* %2
%71 = icmp eq i32 %70, 3
%72 = select i1 %69, i1 %71, i1 false
%73 = load i32, i32* %3
%74 = icmp eq i32 %73, 3
%75 = select i1 %72, i1 %74, i1 false
%76 = zext i1 %75 to i32
%77 = call i32 @assert(i32 %76)
ret i32 0
}