#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 close(int);
int ioctl(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
void purge_cache(char *name) {
  int fd, ret;
  fd = open(name, O_RDONLY, 0);
  if (fd < 0) {
    perror("cannot open %s");
    return;
  }
  ret = ioctl(fd, 4705, 0);
  if (ret == -1) {
    perror("cannot flush buffers for %s");
  }
  ret = close(fd);
  if (ret == -1) {
    perror("failed to close %s");
  }
}


x86 assembly (clang, -O0):
<purge_cache>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    117e <purge_cache+0x3e>
lea    0xe8c(%rip),%rdi
call   1060 <perror@plt>
jmp    11c7 <purge_cache+0x87>
mov    -0xc(%rbp),%edi
mov    $0x1261,%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11a6 <purge_cache+0x66>
lea    0xe6e(%rip),%rdi
call   1060 <perror@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11c7 <purge_cache+0x87>
lea    0xe69(%rip),%rdi
call   1060 <perror@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<purge_cache>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <open@plt>
test   %eax,%eax
js     1178 <purge_cache+0x38>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x1261,%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1185 <purge_cache+0x45>
mov    %ebx,%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
je     1193 <purge_cache+0x53>
pop    %rbx
ret
lea    0xe81(%rip),%rdi
pop    %rbx
jmp    1060 <perror@plt>
lea    0xe83(%rip),%rdi
call   1060 <perror@plt>
jmp    116a <purge_cache+0x2a>
lea    0xe91(%rip),%rdi
pop    %rbx
jmp    1060 <perror@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [15 x i8] c"cannot open %s\00"
@.str.1 = [28 x i8] c"cannot flush buffers for %s\00"
@.str.2 = [19 x i8] c"failed to close %s\00"
define void @purge_cache(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* %5, i32 %6, i32 0)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %26
12: ; preds = %1
%13 = load i32, i32* %3
%14 = call i32 @ioctl(i32 %13, i32 4705, i32 0)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
%20 = load i32, i32* %3
%21 = call i32 @close(i32 %20)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %10, %24, %19
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [15 x i8] c"cannot open %s\00"
@.str.1 = [28 x i8] c"cannot flush buffers for %s\00"
@.str.2 = [19 x i8] c"failed to close %s\00"
define void @purge_cache(i8* nocapture %0) {
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* %0, i32 %2, i32 0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %13, label %5
5: ; preds = %1
%6 = tail call i32 @ioctl(i32 %3, i32 4705, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
%11 = tail call i32 @close(i32 %3)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %10, %1
%14 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), %10 ]
%15 = tail call i32 @perror(i8* %14)
br label %16
16: ; preds = %13, %10
ret void
}