#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sync();
int /*<<< orphan*/ write(int, char *, int);
void drop_cache(void) {
  int fd;
  sync();
  fd = open("/proc/sys/vm/drop_caches", O_RDONLY);
  if (fd < 0) {
    perror("open of drop_caches");
    exit(1);
  }
  write(fd, "3\n", 2);
  close(fd);
}


x86 assembly (clang, -O0):
<drop_cache>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <sync@plt>
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11a7 <drop_cache+0x47>
lea    0xe81(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x4(%rbp),%edi
lea    0xe7c(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drop_cache>:
push   %rbx
xor    %eax,%eax
call   1050 <sync@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     119e <drop_cache+0x3e>
mov    %eax,%ebx
lea    0xea3(%rip),%rsi
mov    %eax,%edi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %ebx,%edi
pop    %rbx
jmp    1040 <close@plt>
lea    0xe74(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"/proc/sys/vm/drop_caches\00"
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"open of drop_caches\00"
@.str.2 = [3 x i8] c"3\0A\00"
define void @drop_cache() {
%1 = alloca i32
%2 = call i32 (...) @sync()
%3 = load i32, i32* @O_RDONLY
%4 = call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i32, i32* %1
%12 = call i32 @write(i32 %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%13 = load i32, i32* %1
%14 = call i32 @close(i32 %13)
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"/proc/sys/vm/drop_caches\00"
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"open of drop_caches\00"
@.str.2 = [3 x i8] c"3\0A\00"
define void @drop_cache() {
%1 = tail call i32 (...) @sync()
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = tail call i32 @write(i32 %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%10 = tail call i32 @close(i32 %3)
ret void
}