#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_WRONLY;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void drop_caches(void) {
  int fd;
  char buf[] = "1\n";
  fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
  assert(fd >= 0);
  write(fd, buf, strlen(buf));
  close(fd);
}


x86 assembly (clang, -O0):
<drop_caches>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xea1(%rip),%ax
mov    %ax,-0x7(%rbp)
mov    0xe99(%rip),%al
mov    %al,-0x5(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    -0x7(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x7(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drop_caches>:
push   %r14
push   %rbx
push   %rax
movb   $0x0,0x6(%rsp)
movw   $0xa31,0x4(%rsp)
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
lea    0xe93(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1060 <assert@plt>
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.drop_caches.buf = [3 x i8] c"1\0A\00"
@.str = [25 x i8] c"/proc/sys/vm/drop_caches\00"
@O_WRONLY = global i32 0
define void @drop_caches() {
%1 = alloca i32
%2 = alloca [3 x i8]
%3 = bitcast [3 x i8]* %2 to i8*
%4 = load i32, i32* @O_WRONLY
%5 = call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = icmp sge i32 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* %1
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
%14 = call i32 @write(i32 %10, i8* %11, i32 %13)
%15 = load i32, i32* %1
%16 = call i32 @close(i32 %15)
ret void
}

LLVM IR (-O2):
@__const.drop_caches.buf = [3 x i8] c"1\0A\00"
@.str = [25 x i8] c"/proc/sys/vm/drop_caches\00"
@O_WRONLY = global i32 0
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 = xor i32 %4, -1
%6 = lshr i32 %5, 31
%7 = tail call i32 @assert(i32 %6)
%8 = call i32 @strlen(i8* %2)
%9 = call i32 @write(i32 %4, i8* %2, i32 %8)
%10 = call i32 @close(i32 %4)
ret void
}