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

/* Variables and functions */
int CTL_VM;
int VM_DROP_PAGECACHE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ sync();
int sysctl(int *, int, int /*<<< orphan*/ *, int /*<<< orphan*/, int *, int);
int main(int argc, char **argv) {
  int name[] = {CTL_VM, VM_DROP_PAGECACHE};
  int namelen = 2;
  int error;
  int newval[1] = {3};
  int newlen = sizeof(newval);
  uid_t super_user = 0;
  if (0 != setuid(super_user)) {
    perror("Unable to switch to super user");
    exit(1);
  }
  sync();
  sync();
  sync();
  error = sysctl(name, namelen, NULL, 0, newval, newlen);
  if (error) {
    fprintf(stderr, "%s: sysctl(): %s\n", argv[0], strerror(errno));
    exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x2,-0x1c(%rbp)
mov    0xe55(%rip),%eax
mov    %eax,-0x24(%rbp)
movl   $0x4,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1080 <setuid@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11e8 <main+0x78>
lea    0xe2b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1040 <sync@plt>
mov    $0x0,%al
call   1040 <sync@plt>
mov    $0x0,%al
call   1040 <sync@plt>
lea    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x24(%rbp),%r8
mov    -0x28(%rbp),%r9d
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <sysctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1269 <main+0xf9>
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xdc9(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
movl   $0x3,0xc(%rsp)
xor    %edi,%edi
call   1080 <setuid@plt>
test   %rax,%rax
jne    11e5 <main+0x75>
xor    %eax,%eax
call   1040 <sync@plt>
xor    %eax,%eax
call   1040 <sync@plt>
xor    %eax,%eax
call   1040 <sync@plt>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%r8
mov    $0x2,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1050 <sysctl@plt>
test   %eax,%eax
jne    11fb <main+0x8b>
xor    %edi,%edi
call   1070 <exit@plt>
lea    0xe14(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rbx
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe03(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@CTL_VM = global i32 0
@VM_DROP_PAGECACHE = global i32 0
@__const.main.newval = [1 x i32] [i32 3]
@.str = [31 x i8] c"Unable to switch to super user\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"%s: sysctl(): %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca [1 x i32]
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%13 = load i32, i32* @CTL_VM
store i32 %13, i32* %12
%14 = getelementptr inbounds i32, i32* %12, i64 1
%15 = load i32, i32* @VM_DROP_PAGECACHE
store i32 %15, i32* %14
store i32 2, i32* %7
%16 = bitcast [1 x i32]* %9 to i8*
store i32 4, i32* %10
store i32 0, i32* %11
%17 = load i32, i32* %11
%18 = call i64 @setuid(i32 %17)
%19 = icmp ne i64 0, %18
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = call i32 (...) @sync()
%25 = call i32 (...) @sync()
%26 = call i32 (...) @sync()
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%28 = load i32, i32* %7
%29 = getelementptr inbounds [1 x i32], [1 x i32]* %9, i64 0, i64 0
%30 = load i32, i32* %10
%31 = call i32 @sysctl(i32* %27, i32 %28, i32* null, i32 0, i32* %29, i32 %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %43
34: ; preds = %23
%35 = load i32, i32* @stderr
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 0
%38 = load i8*, i8** %37
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %38, i8* %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %23
%44 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@CTL_VM = global i32 0
@VM_DROP_PAGECACHE = global i32 0
@.str = [31 x i8] c"Unable to switch to super user\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"%s: sysctl(): %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = alloca [1 x i32]
%5 = bitcast [2 x i32]* %3 to i8*
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%7 = load i32, i32* @CTL_VM
store i32 %7, i32* %6
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%9 = load i32, i32* @VM_DROP_PAGECACHE
store i32 %9, i32* %8
%10 = bitcast [1 x i32]* %4 to i8*
%11 = getelementptr inbounds [1 x i32], [1 x i32]* %4, i64 0, i64 0
store i32 3, i32* %11
%12 = tail call i64 @setuid(i32 0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = tail call i32 (...) @sync()
%19 = tail call i32 (...) @sync()
%20 = tail call i32 (...) @sync()
%21 = call i32 @sysctl(i32* %6, i32 2, i32* null, i32 0, i32* %11, i32 4)
%22 = icmp eq i32 %21, 0
br i1 %22, label %30, label %23
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %1
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %25, i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %17
%31 = call i32 @exit(i32 0)
unreachable
}