#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;
typedef int /*<<< orphan*/ gid_t;

/* Variables and functions */
int geteuid();
int getuid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int);
scalar_t__ seteuid(int);
int main(void) {
  uid_t ruid, euid;
  printf("sizeof(uid_t) = %d  sizeof(gid_t) = %d\n", sizeof(uid_t),
         sizeof(gid_t));
  ruid = getuid();
  euid = geteuid();
  printf("Start: ruid=%d euid=%d\n", ruid, euid);
  if (seteuid(9999) != 0)
    perror("seteuid(9999)");
  ruid = getuid();
  euid = geteuid();
  printf("After set: ruid=%d euid=%d\n", ruid, euid);
  if (seteuid(0) != 0)
    perror("seteuid(0)");
  ruid = getuid();
  euid = geteuid();
  printf("After restore: ruid=%d euid=%d\n", ruid, euid);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x4,%edx
mov    %edx,%esi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
mov    $0x270f,%edi
call   1070 <seteuid@plt>
cmp    $0x0,%rax
je     11b8 <main+0x68>
lea    0xe8d(%rip),%rdi
call   1060 <perror@plt>
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe75(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <seteuid@plt>
cmp    $0x0,%rax
je     11fb <main+0xab>
lea    0xe74(%rip),%rdi
call   1060 <perror@plt>
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xea8(%rip),%rdi
mov    $0x4,%esi
mov    $0x4,%edx
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <getuid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <geteuid@plt>
lea    0xeaa(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    $0x270f,%edi
call   1070 <seteuid@plt>
test   %rax,%rax
jne    11e6 <main+0x96>
xor    %eax,%eax
call   1030 <getuid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <geteuid@plt>
lea    0xea1(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <seteuid@plt>
test   %rax,%rax
jne    11f4 <main+0xa4>
xor    %eax,%eax
call   1030 <getuid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <geteuid@plt>
lea    0xe9c(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe53(%rip),%rdi
call   1060 <perror@plt>
jmp    1196 <main+0x46>
lea    0xe6f(%rip),%rdi
call   1060 <perror@plt>
jmp    11c2 <main+0x72>

LLVM IR (-O0):
@.str = [40 x i8] c"sizeof(uid_t) = %d sizeof(gid_t) = %d\0A\00"
@.str.1 = [24 x i8] c"Start: ruid=%d euid=%d\0A\00"
@.str.2 = [14 x i8] c"seteuid(9999)\00"
@.str.3 = [28 x i8] c"After set: ruid=%d euid=%d\0A\00"
@.str.4 = [11 x i8] c"seteuid(0)\00"
@.str.5 = [32 x i8] c"After restore: ruid=%d euid=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 4, i32 4)
%5 = call i32 (...) @getuid()
store i32 %5, i32* %2
%6 = call i32 (...) @geteuid()
store i32 %6, i32* %3
%7 = load i32, i32* %2
%8 = load i32, i32* %3
%9 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %8)
%10 = call i64 @seteuid(i32 9999)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %0
%15 = call i32 (...) @getuid()
store i32 %15, i32* %2
%16 = call i32 (...) @geteuid()
store i32 %16, i32* %3
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %17, i32 %18)
%20 = call i64 @seteuid(i32 0)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %24
24: ; preds = %22, %14
%25 = call i32 (...) @getuid()
store i32 %25, i32* %2
%26 = call i32 (...) @geteuid()
store i32 %26, i32* %3
%27 = load i32, i32* %2
%28 = load i32, i32* %3
%29 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %27, i32 %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [40 x i8] c"sizeof(uid_t) = %d sizeof(gid_t) = %d\0A\00"
@.str.1 = [24 x i8] c"Start: ruid=%d euid=%d\0A\00"
@.str.2 = [14 x i8] c"seteuid(9999)\00"
@.str.3 = [28 x i8] c"After set: ruid=%d euid=%d\0A\00"
@.str.4 = [11 x i8] c"seteuid(0)\00"
@.str.5 = [32 x i8] c"After restore: ruid=%d euid=%d\0A\00"
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 4, i32 4)
%2 = tail call i32 (...) @getuid()
%3 = tail call i32 (...) @geteuid()
%4 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 %3)
%5 = tail call i64 @seteuid(i32 9999)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = tail call i32 (...) @getuid()
%11 = tail call i32 (...) @geteuid()
%12 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %10, i32 %11)
%13 = tail call i64 @seteuid(i32 0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %9
%16 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %17
17: ; preds = %15, %9
%18 = tail call i32 (...) @getuid()
%19 = tail call i32 (...) @geteuid()
%20 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %18, i32 %19)
ret i32 0
}