#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(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *stderr;
void dropCaches() {
  FILE *fp = fopen("/proc/sys/vm/drop_caches", "wt");
  if (fp == NULL) {
    fprintf(stderr, "error: you need sudo/root permission to drop caches\n");
    exit(-1);
  }
  if (fprintf(fp, "3\n") < 1) {
    fprintf(stderr, "error: you need sudo/root permission to drop caches\n");
    exit(-1);
  }
  fflush(fp);
  fclose(fp);
  fprintf(stderr,
          "*info* echo 3 > /proc/sys/vm/drop_caches ; # caches dropped\n");
}


x86 assembly (clang, -O0):
<dropCaches>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    119a <dropCaches+0x4a>
mov    0x2e5f(%rip),%rax
mov    (%rax),%rdi
lea    0xe91(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    0xeac(%rip),%rsi
call   1040 <fprintf@plt>
cmp    $0x1,%eax
jge    11d3 <dropCaches+0x83>
mov    0x2e26(%rip),%rax
mov    (%rax),%rdi
lea    0xe58(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fflush@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%rdi
lea    0xe5e(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dropCaches>:
push   %rbx
lea    0xe98(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c0 <dropCaches+0x60>
mov    %rax,%rbx
lea    0xece(%rip),%rsi
mov    %rax,%rdi
call   1040 <fprintf@plt>
test   %eax,%eax
jle    11c0 <dropCaches+0x60>
mov    %rbx,%rdi
call   1050 <fflush@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%rcx
lea    0xea4(%rip),%rdi
mov    $0x3c,%esi
mov    $0x1,%edx
pop    %rbx
jmp    1080 <fwrite@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%rcx
lea    0xe4b(%rip),%rdi
mov    $0x34,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"/proc/sys/vm/drop_caches\00"
@.str.1 = [3 x i8] c"wt\00"
@stderr = global i32* null
@.str.2 = [53 x i8] c"error: you need sudo/root permission to drop caches\0A\00"
@.str.3 = [3 x i8] c"3\0A\00"
@.str.4 = [61 x i8] c"*info* echo 3 > /proc/sys/vm/drop_caches ; # caches dropped\0A\00"
define void @dropCaches() {
%1 = alloca i32*
%2 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %2, i32** %1
%3 = load i32*, i32** %1
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = load i32*, i32** @stderr
%7 = call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @exit(i32 -1)
unreachable
9: ; preds = %0
%10 = load i32*, i32** %1
%11 = call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32*, i32** @stderr
%15 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %9
%18 = load i32*, i32** %1
%19 = call i32 @fflush(i32* %18)
%20 = load i32*, i32** %1
%21 = call i32 @fclose(i32* %20)
%22 = load i32*, i32** @stderr
%23 = call i32 @fprintf(i32* %22, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"/proc/sys/vm/drop_caches\00"
@.str.1 = [3 x i8] c"wt\00"
@stderr = global i32* null
@.str.2 = [53 x i8] c"error: you need sudo/root permission to drop caches\0A\00"
@.str.3 = [3 x i8] c"3\0A\00"
@.str.4 = [61 x i8] c"*info* echo 3 > /proc/sys/vm/drop_caches ; # caches dropped\0A\00"
define void @dropCaches() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = load i32*, i32** @stderr
%5 = tail call i64 @fwrite(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i64 52, i64 1, i32* %4)
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %0
%8 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%9 = icmp slt i32 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i32*, i32** @stderr
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i64 52, i64 1, i32* %11)
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %7
%15 = tail call i32 @fflush(i32* %1)
%16 = tail call i32 @fclose(i32* %1)
%17 = load i32*, i32** @stderr
%18 = tail call i64 @fwrite(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0), i64 60, i64 1, i32* %17)
ret void
}