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

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
int write(int, char *, int);
void drop_caches(void) {
  int fd;
  int ret;
  char buf[] = "3\n";
  fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
  if (fd < 0) {
    printf("error: "
           "failed to open /proc/sys/vm/drop_caches"
           ": %s"
           "\n",
           strerror(errno));
    exit(-1);
  };
  ret = write(fd, buf, sizeof(buf));
  if (ret < 0) {
    printf("error: "
           "failed to write to /proc/sys/vm/drop_caches"
           ": %s"
           "\n",
           strerror(errno));
    exit(-1);
  };
}


x86 assembly (clang, -O0):
<drop_caches>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0xea1(%rip),%ax
mov    %ax,-0xb(%rbp)
mov    0xe99(%rip),%al
mov    %al,-0x9(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11b5 <drop_caches+0x65>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,%rsi
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%edi
lea    -0xb(%rbp),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11fa <drop_caches+0xaa>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,%rsi
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drop_caches>:
push   %rax
movb   $0x0,0x6(%rsp)
movw   $0xa33,0x4(%rsp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
lea    0xe96(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     118d <drop_caches+0x3d>
lea    0x4(%rsp),%rsi
mov    %eax,%edi
mov    $0x3,%edx
call   1030 <write@plt>
test   %eax,%eax
js     11a4 <drop_caches+0x54>
pop    %rax
ret
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe7a(%rip),%rdi
jmp    11b9 <drop_caches+0x69>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe97(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@__const.drop_caches.buf = [3 x i8] c"3\0A\00"
@.str = [25 x i8] c"/proc/sys/vm/drop_caches\00"
@O_WRONLY = global i32 0
@.str.1 = [52 x i8] c"error: failed to open /proc/sys/vm/drop_caches: %s\0A\00"
@errno = global i32 0
@.str.2 = [56 x i8] c"error: failed to write to /proc/sys/vm/drop_caches: %s\0A\00"
define void @drop_caches() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [3 x i8]
%4 = bitcast [3 x i8]* %3 to i8*
%5 = load i32, i32* @O_WRONLY
%6 = call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %0
%15 = load i32, i32* %1
%16 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%17 = call i32 @write(i32 %15, i8* %16, i32 3)
store i32 %17, i32* %2
%18 = load i32, i32* %2
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %14
ret void
}

LLVM IR (-O2):
@__const.drop_caches.buf = [3 x i8] c"3\0A\00"
@.str = [25 x i8] c"/proc/sys/vm/drop_caches\00"
@O_WRONLY = global i32 0
@.str.1 = [52 x i8] c"error: failed to open /proc/sys/vm/drop_caches: %s\0A\00"
@errno = global i32 0
@.str.2 = [56 x i8] c"error: failed to write to /proc/sys/vm/drop_caches: %s\0A\00"
define void @drop_caches() {
%1 = alloca [3 x i8]
%2 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %0
%12 = call i32 @write(i32 %4, i8* %2, i32 3)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i32, i32* @errno
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %11
ret void
}