#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 geteuid();
int /*<<< orphan*/ getroot();
int getuid();
int /*<<< orphan*/ patch_libc(char *, int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  patch_libc("getuid", 0, "\x00\x00\xA0\xE3\x0E\xF0\xA0\xE1",
             sizeof("\x00\x00\xA0\xE3\x0E\xF0\xA0\xE1") - 1);
  patch_libc("geteuid", 0, "\x00\x00\xA0\xE3\x0E\xF0\xA0\xE1",
             sizeof("\x00\x00\xA0\xE3\x0E\xF0\xA0\xE1") - 1);
  printf("getuid() = %d\n", getuid());
  printf("geteuid() = %d\n", geteuid());
  getroot();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
xor    %esi,%esi
lea    0xeb8(%rip),%rdx
mov    $0x8,%ecx
call   1030 <patch_libc@plt>
lea    0xe80(%rip),%rdi
xor    %esi,%esi
lea    0xe9e(%rip),%rdx
mov    $0x8,%ecx
call   1030 <patch_libc@plt>
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %eax,%esi
lea    0xe65(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %eax,%esi
lea    0xe5f(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <getroot@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xea8(%rip),%rdi
lea    0xecf(%rip),%rbx
xor    %esi,%esi
mov    %rbx,%rdx
mov    $0x8,%ecx
call   1030 <patch_libc@plt>
lea    0xe92(%rip),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    $0x8,%ecx
call   1030 <patch_libc@plt>
xor    %eax,%eax
call   1040 <getuid@plt>
lea    0xe7d(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <geteuid@plt>
lea    0xe77(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <getroot@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"getuid\00"
@.str.1 = [9 x i8] c"\00\00\A0\E3\0E\F0\A0\E1\00"
@.str.2 = [8 x i8] c"geteuid\00"
@.str.3 = [15 x i8] c"getuid() = %d\0A\00"
@.str.4 = [16 x i8] c"geteuid() = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = call i32 @patch_libc(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%7 = call i32 @patch_libc(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%8 = call i32 (...) @getuid()
%9 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %8)
%10 = call i32 (...) @geteuid()
%11 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %10)
%12 = call i32 (...) @getroot()
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"getuid\00"
@.str.1 = [9 x i8] c"\00\00\A0\E3\0E\F0\A0\E1\00"
@.str.2 = [8 x i8] c"geteuid\00"
@.str.3 = [15 x i8] c"getuid() = %d\0A\00"
@.str.4 = [16 x i8] c"geteuid() = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @patch_libc(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%4 = tail call i32 @patch_libc(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%5 = tail call i32 (...) @getuid()
%6 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %5)
%7 = tail call i32 (...) @geteuid()
%8 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %7)
%9 = tail call i32 (...) @getroot()
ret i32 0
}