#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*/ POSIX_FADV_DONTNEED;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int open(char const *, int /*<<< orphan*/);
int posix_fadvise(int, size_t, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int unmap_log(const char *fpath, size_t start, size_t len) {
  int fd = open(fpath, O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "Failed to open %s\n", fpath);
    return 1;
  }
  int r = posix_fadvise(fd, start, len, POSIX_FADV_DONTNEED);
  if (r != 0) {
    fprintf(stderr, "posix_fadvice failed for %s\n", fpath);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<unmap_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1198 <unmap_log+0x58>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe79(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e6 <unmap_log+0xa6>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    0x2e46(%rip),%rax
mov    (%rax),%ecx
call   1040 <posix_fadvise@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     11d7 <unmap_log+0x97>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe41(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unmap_log>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     11a1 <unmap_log+0x61>
mov    %eax,%ebp
mov    0x2e85(%rip),%rax
mov    (%rax),%ecx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <posix_fadvise@plt>
test   %eax,%eax
je     1196 <unmap_log+0x56>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    %ebp,%edi
call   1030 <close@plt>
xor    %eax,%eax
jmp    11be <unmap_log+0x7e>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"Failed to open %s\0A\00"
@POSIX_FADV_DONTNEED = global i32 0
@.str.1 = [29 x i8] c"posix_fadvice failed for %s\0A\00"
define i32 @unmap_log(i8* %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%10 = load i8*, i8** %5
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %5
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 1, i32* %4
br label %34
19: ; preds = %3
%20 = load i32, i32* %8
%21 = load i64, i64* %6
%22 = load i64, i64* %7
%23 = load i32, i32* @POSIX_FADV_DONTNEED
%24 = call i32 @posix_fadvise(i32 %20, i64 %21, i64 %22, i32 %23)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %19
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %5
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %27, %19
%32 = load i32, i32* %8
%33 = call i32 @close(i32 %32)
store i32 0, i32* %4
br label %34
34: ; preds = %31, %15
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"Failed to open %s\0A\00"
@POSIX_FADV_DONTNEED = global i32 0
@.str.1 = [29 x i8] c"posix_fadvice failed for %s\0A\00"
define i32 @unmap_log(i8* %0, i64 %1, i64 %2) {
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %19
10: ; preds = %3
%11 = load i32, i32* @POSIX_FADV_DONTNEED
%12 = tail call i32 @posix_fadvise(i32 %5, i64 %1, i64 %2, i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %17
17: ; preds = %14, %10
%18 = tail call i32 @close(i32 %5)
br label %19
19: ; preds = %17, %7
%20 = phi i32 [ 1, %7 ], [ 0, %17 ]
ret i32 %20
}