#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*/ O_RDWR;
int /*<<< orphan*/ W_OK;
int access(char *, int /*<<< orphan*/);
int geteuid();
int getuid();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ seteuid(int);
void main() {
  printf("Real      UID = %d\n", getuid());
  printf("Effective UID = %d\n", geteuid());
  printf("open: %d\n", open("/etc/hosts", O_RDWR));
  printf("access: %d\n", access("/etc/hosts", W_OK));
  seteuid(getuid());
  printf("Real      UID = %d\n", getuid());
  printf("Effective UID = %d\n", geteuid());
  printf("open: %d\n", open("/etc/hosts", O_RDWR));
  printf("access: %d\n", access("/etc/hosts", W_OK));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,%esi
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %eax,%esi
lea    0xe8b(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
lea    0xe94(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%esi
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
call   1070 <access@plt>
mov    %eax,%esi
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,%edi
call   1080 <seteuid@plt>
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,%esi
lea    0xe0e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %eax,%esi
lea    0xe0d(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
lea    0xe16(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%esi
lea    0xdfe(%rip),%rdi
call   1040 <printf@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
lea    0xdf3(%rip),%rdi
call   1070 <access@plt>
mov    %eax,%esi
lea    0xdf0(%rip),%rdi
call   1040 <printf@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <getuid@plt>
lea    0xe87(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <geteuid@plt>
lea    0xe86(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x2e49(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0xe89(%rip),%rbx
mov    %rbx,%rdi
call   1060 <open@plt>
lea    0xe70(%rip),%r12
mov    %r12,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x2e17(%rip),%r14
mov    (%r14),%esi
mov    %rbx,%rdi
call   1070 <access@plt>
lea    0xe62(%rip),%r13
mov    %r13,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <getuid@plt>
mov    %eax,%edi
call   1080 <seteuid@plt>
xor    %eax,%eax
call   1030 <getuid@plt>
lea    0xdff(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <geteuid@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
call   1070 <access@plt>
mov    %r13,%rdi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"Real UID = %d\0A\00"
@.str.1 = [20 x i8] c"Effective UID = %d\0A\00"
@.str.2 = [10 x i8] c"open: %d\0A\00"
@.str.3 = [11 x i8] c"/etc/hosts\00"
@O_RDWR = global i32 0
@.str.4 = [12 x i8] c"access: %d\0A\00"
@W_OK = global i32 0
define void @main() {
%1 = call i32 (...) @getuid()
%2 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = call i32 (...) @geteuid()
%4 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @O_RDWR
%6 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %5)
%7 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = load i32, i32* @W_OK
%9 = call i32 @access(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %9)
%11 = call i32 (...) @getuid()
%12 = call i32 @seteuid(i32 %11)
%13 = call i32 (...) @getuid()
%14 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 (...) @geteuid()
%16 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @O_RDWR
%18 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i32, i32* @W_OK
%21 = call i32 @access(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %21)
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"Real UID = %d\0A\00"
@.str.1 = [20 x i8] c"Effective UID = %d\0A\00"
@.str.2 = [10 x i8] c"open: %d\0A\00"
@.str.3 = [11 x i8] c"/etc/hosts\00"
@O_RDWR = global i32 0
@.str.4 = [12 x i8] c"access: %d\0A\00"
@W_OK = global i32 0
define void @main() {
%1 = tail call i32 (...) @getuid()
%2 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 (...) @geteuid()
%4 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %5)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = load i32, i32* @W_OK
%9 = tail call i32 @access(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %8)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %9)
%11 = tail call i32 (...) @getuid()
%12 = tail call i32 @seteuid(i32 %11)
%13 = tail call i32 (...) @getuid()
%14 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = tail call i32 (...) @geteuid()
%16 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @O_RDWR
%18 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i32, i32* @W_OK
%21 = tail call i32 @access(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %21)
ret void
}