#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 getuid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ system(char *);
int main() {
  printf("Escalate permission from %d to root\n", getuid());
  setuid(0);
  printf("Reload psmouse with uid: %d\n", getuid());
  system("modprobe -r psmouse");
  system("modprobe psmouse");
  printf("Done\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,%esi
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <setuid@plt>
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,%esi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeb7(%rip),%rdi
call   1040 <system@plt>
lea    0xebf(%rip),%rdi
call   1040 <system@plt>
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1040 <getuid@plt>
lea    0xea1(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1070 <setuid@plt>
xor    %eax,%eax
call   1040 <getuid@plt>
lea    0xea8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xeb5(%rip),%rdi
call   1050 <system@plt>
lea    0xebd(%rip),%rdi
call   1050 <system@plt>
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Escalate permission from %d to root\0A\00"
@.str.1 = [29 x i8] c"Reload psmouse with uid: %d\0A\00"
@.str.2 = [20 x i8] c"modprobe -r psmouse\00"
@.str.3 = [17 x i8] c"modprobe psmouse\00"
@.str.4 = [6 x i8] c"Done\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 (...) @getuid()
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = call i32 @setuid(i32 0)
%5 = call i32 (...) @getuid()
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = call i32 @system(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @system(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [37 x i8] c"Escalate permission from %d to root\0A\00"
@.str.1 = [29 x i8] c"Reload psmouse with uid: %d\0A\00"
@.str.2 = [20 x i8] c"modprobe -r psmouse\00"
@.str.3 = [17 x i8] c"modprobe psmouse\00"
@str = [5 x i8] c"Done\00"
define i32 @main() {
%1 = tail call i32 (...) @getuid()
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 @setuid(i32 0)
%4 = tail call i32 (...) @getuid()
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = tail call i32 @system(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @system(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
ret i32 0
}