#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fprintf(int /*<<< orphan*/ *, char *);
scalar_t__ geteuid();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ *stderr;
scalar_t__ system(char *);
int main(void) {
  printf("Flushing page cache, dentries and inodes...\n");
  if (geteuid() != 0) {
    fprintf(stderr, "flush-cache: Not root\n");
    exit(EXIT_FAILURE);
  }
  if (system("sync") != 0) {
    fprintf(stderr, "flush-cache: sync failed (first time)\n");
    exit(EXIT_FAILURE);
  }
  if (system("sync") != 0) {
    fprintf(stderr, "flush-cache: sync failed (second time)\n");
    exit(EXIT_FAILURE);
  }
  if (system("sync") != 0) {
    fprintf(stderr, "flush-cache: sync failed (third time)\n");
    exit(EXIT_FAILURE);
  }
  FILE *f;
  f = fopen("/proc/sys/vm/drop_caches", "w");
  if (f == NULL) {
    fprintf(stderr, "flush-cache: Couldn't open /proc/sys/vm/drop_caches\n");
    exit(EXIT_FAILURE);
  }
  if (fprintf(f, "3\n") != 2) {
    fprintf(stderr,
            "flush-cache: Couldn't write 3 to /proc/sys/vm/drop_caches\n");
    exit(EXIT_FAILURE);
  }
  fclose(f);
  printf("Done flushing.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <geteuid@plt>
cmp    $0x0,%rax
je     11c0 <main+0x50>
mov    0x2e3d(%rip),%rax
mov    (%rax),%rdi
lea    0xe80(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe7d(%rip),%rdi
call   1040 <system@plt>
cmp    $0x0,%rax
je     11fa <main+0x8a>
mov    0x2e03(%rip),%rax
mov    (%rax),%rdi
lea    0xe62(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe43(%rip),%rdi
call   1040 <system@plt>
cmp    $0x0,%rax
je     1234 <main+0xc4>
mov    0x2dc9(%rip),%rax
mov    (%rax),%rdi
lea    0xe4f(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe09(%rip),%rdi
call   1040 <system@plt>
cmp    $0x0,%rax
je     126e <main+0xfe>
mov    0x2d8f(%rip),%rax
mov    (%rax),%rdi
lea    0xe3d(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe4a(%rip),%rdi
lea    0xe5c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    12b4 <main+0x144>
mov    0x2d49(%rip),%rax
mov    (%rax),%rdi
lea    0xe39(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1070 <fprintf@plt>
cmp    $0x2,%eax
je     12f1 <main+0x181>
mov    0x2d0c(%rip),%rax
mov    (%rax),%rdi
lea    0xe34(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe4c(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xf98(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <geteuid@plt>
test   %rax,%rax
jne    122b <main+0xab>
lea    0xe73(%rip),%rdi
call   1050 <system@plt>
test   %rax,%rax
jne    1243 <main+0xc3>
lea    0xe5e(%rip),%rdi
call   1050 <system@plt>
test   %rax,%rax
jne    1256 <main+0xd6>
lea    0xe49(%rip),%rdi
call   1050 <system@plt>
test   %rax,%rax
jne    126e <main+0xee>
lea    0xeaf(%rip),%rdi
lea    0xec1(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1286 <main+0x106>
mov    %rax,%rbx
lea    0xee0(%rip),%rsi
mov    %rax,%rdi
call   1070 <fprintf@plt>
cmp    $0x2,%eax
jne    129e <main+0x11e>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xf2a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2dae(%rip),%rax
mov    (%rax),%rcx
lea    0xdc4(%rip),%rdi
mov    $0x16,%esi
jmp    12b4 <main+0x134>
mov    0x2d96(%rip),%rax
mov    (%rax),%rcx
lea    0xdc8(%rip),%rdi
jmp    127f <main+0xff>
mov    0x2d83(%rip),%rax
mov    (%rax),%rcx
lea    0xddc(%rip),%rdi
mov    $0x27,%esi
jmp    12b4 <main+0x134>
mov    0x2d6b(%rip),%rax
mov    (%rax),%rcx
lea    0xdec(%rip),%rdi
mov    $0x26,%esi
jmp    12b4 <main+0x134>
mov    0x2d53(%rip),%rax
mov    (%rax),%rcx
lea    0xe16(%rip),%rdi
mov    $0x34,%esi
jmp    12b4 <main+0x134>
mov    0x2d3b(%rip),%rax
mov    (%rax),%rcx
lea    0xe36(%rip),%rdi
mov    $0x3a,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"Flushing page cache, dentries and inodes...\0A\00"
@stderr = global i32* null
@.str.1 = [23 x i8] c"flush-cache: Not root\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"sync\00"
@.str.3 = [39 x i8] c"flush-cache: sync failed (first time)\0A\00"
@.str.4 = [40 x i8] c"flush-cache: sync failed (second time)\0A\00"
@.str.5 = [39 x i8] c"flush-cache: sync failed (third time)\0A\00"
@.str.6 = [25 x i8] c"/proc/sys/vm/drop_caches\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [53 x i8] c"flush-cache: Couldn't open /proc/sys/vm/drop_caches\0A\00"
@.str.9 = [3 x i8] c"3\0A\00"
@.str.10 = [59 x i8] c"flush-cache: Couldn't write 3 to /proc/sys/vm/drop_caches\0A\00"
@.str.11 = [16 x i8] c"Done flushing.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%4 = call i64 (...) @geteuid()
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i32*, i32** @stderr
%8 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = call i64 @system(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i32*, i32** @stderr
%16 = call i32 @fprintf(i32* %15, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %11
%20 = call i64 @system(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32*, i32** @stderr
%24 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %19
%28 = call i64 @system(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i32*, i32** @stderr
%32 = call i32 @fprintf(i32* %31, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %27
%36 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %36, i32** %2
%37 = load i32*, i32** %2
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load i32*, i32** @stderr
%41 = call i32 @fprintf(i32* %40, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.8, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %35
%45 = load i32*, i32** %2
%46 = call i32 @fprintf(i32* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%47 = icmp ne i32 %46, 2
br i1 %47, label %48, label %53
48: ; preds = %44
%49 = load i32*, i32** @stderr
%50 = call i32 @fprintf(i32* %49, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.10, i64 0, i64 0))
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %44
%54 = load i32*, i32** %2
%55 = call i32 @fclose(i32* %54)
%56 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32* null
@.str.1 = [23 x i8] c"flush-cache: Not root\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"sync\00"
@.str.3 = [39 x i8] c"flush-cache: sync failed (first time)\0A\00"
@.str.4 = [40 x i8] c"flush-cache: sync failed (second time)\0A\00"
@.str.5 = [39 x i8] c"flush-cache: sync failed (third time)\0A\00"
@.str.6 = [25 x i8] c"/proc/sys/vm/drop_caches\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [53 x i8] c"flush-cache: Couldn't open /proc/sys/vm/drop_caches\0A\00"
@.str.9 = [3 x i8] c"3\0A\00"
@.str.10 = [59 x i8] c"flush-cache: Couldn't write 3 to /proc/sys/vm/drop_caches\0A\00"
@str = [44 x i8] c"Flushing page cache, dentries and inodes...\00"
@str.12 = [15 x i8] c"Done flushing.\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%2 = tail call i64 (...) @geteuid()
%3 = icmp eq i64 %2, 0
br i1 %3, label %9, label %4
4: ; preds = %0
%5 = load i32*, i32** @stderr
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 22, i64 1, i32* %5)
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %0
%10 = tail call i64 @system(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = load i32*, i32** @stderr
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i64 38, i64 1, i32* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %9
%18 = tail call i64 @system(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %17
%21 = load i32*, i32** @stderr
%22 = tail call i64 @fwrite(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i64 39, i64 1, i32* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %17
%26 = tail call i64 @system(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %25
%29 = load i32*, i32** @stderr
%30 = tail call i64 @fwrite(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i64 38, i64 1, i32* %29)
%31 = load i32, i32* @EXIT_FAILURE
%32 = tail call i32 @exit(i32 %31)
unreachable
33: ; preds = %25
%34 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i32*, i32** @stderr
%38 = tail call i64 @fwrite(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.8, i64 0, i64 0), i64 52, i64 1, i32* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = tail call i32 @exit(i32 %39)
unreachable
41: ; preds = %33
%42 = tail call i32 @fprintf(i32* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%43 = icmp eq i32 %42, 2
br i1 %43, label %49, label %44
44: ; preds = %41
%45 = load i32*, i32** @stderr
%46 = tail call i64 @fwrite(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.10, i64 0, i64 0), i64 58, i64 1, i32* %45)
%47 = load i32, i32* @EXIT_FAILURE
%48 = tail call i32 @exit(i32 %47)
unreachable
49: ; preds = %41
%50 = tail call i32 @fclose(i32* %34)
%51 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.12, i64 0, i64 0))
ret i32 0
}