#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 */
#define EBADF 130
#define EINVAL 129
#define ESPIPE 128
int /*<<< orphan*/ POSIX_FADV_DONTNEED;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int posix_fadvise(int, int /*<<< orphan*/, int /*<<< orphan*/,
                  int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void advise_dontneed(int fd) {
  int advise_error = posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
  if (advise_error != 0) {
    char *error_str;
    switch (advise_error) {
    case EBADF:
      error_str = "The fd argument was not a valid file descriptor.";
      break;
    case EINVAL:
      error_str = "An invalid value was specified for advice.";
      break;
    case ESPIPE:
      return;
    default:
      error_str = "Unknown error";
    }
    fprintf(stderr, "Failed to posix_fadvise() '%d': %s\n", fd, error_str);
  }
}


x86 assembly (clang, -O0):
<advise_dontneed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ebb(%rip),%rax
mov    (%rax),%ecx
xor    %edx,%edx
mov    %edx,%esi
call   1030 <posix_fadvise@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11d5 <advise_dontneed+0xb5>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x80,%eax
je     11a9 <advise_dontneed+0x89>
jmp    1163 <advise_dontneed+0x43>
mov    -0x14(%rbp),%eax
sub    $0x81,%eax
je     1199 <advise_dontneed+0x79>
jmp    1176 <advise_dontneed+0x56>
mov    -0x14(%rbp),%eax
sub    $0x82,%eax
jne    11ae <advise_dontneed+0x8e>
jmp    1189 <advise_dontneed+0x69>
lea    0xe70(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11b9 <advise_dontneed+0x99>
lea    0xe91(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11b9 <advise_dontneed+0x99>
jmp    11d5 <advise_dontneed+0xb5>
lea    0xea7(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0xe9a(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<advise_dontneed>:
push   %rbx
mov    %edi,%ebx
mov    0x2ec6(%rip),%rax
mov    (%rax),%ecx
xor    %esi,%esi
xor    %edx,%edx
call   1030 <posix_fadvise@plt>
cmp    $0x80,%eax
jg     1149 <advise_dontneed+0x29>
test   %eax,%eax
je     1147 <advise_dontneed+0x27>
cmp    $0x80,%eax
jne    1160 <advise_dontneed+0x40>
pop    %rbx
ret
cmp    $0x82,%eax
je     1169 <advise_dontneed+0x49>
cmp    $0x81,%eax
jne    1160 <advise_dontneed+0x40>
lea    0xed3(%rip),%rcx
jmp    1170 <advise_dontneed+0x50>
lea    0xef5(%rip),%rcx
jmp    1170 <advise_dontneed+0x50>
lea    0xe90(%rip),%rcx
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xeea(%rip),%rsi
mov    %ebx,%edx
pop    %rbx
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
@POSIX_FADV_DONTNEED = global i32 0
@.str = [49 x i8] c"The fd argument was not a valid file descriptor.\00"
@.str.1 = [43 x i8] c"An invalid value was specified for advice.\00"
@.str.2 = [14 x i8] c"Unknown error\00"
@stderr = global i32 0
@.str.3 = [36 x i8] c"Failed to posix_fadvise() '%d': %s\0A\00"
define void @advise_dontneed(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = load i32, i32* @POSIX_FADV_DONTNEED
%7 = call i32 @posix_fadvise(i32 %5, i32 0, i32 0, i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %1
%11 = load i32, i32* %3
switch i32 %11, label %15 [
i32 130, label %12
i32 129, label %13
i32 128, label %14
]
12: ; preds = %10
store i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8** %4
br label %16
13: ; preds = %10
store i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %16
14: ; preds = %10
br label %21
15: ; preds = %10
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8** %4
br label %16
16: ; preds = %15, %13, %12
%17 = load i32, i32* @stderr
%18 = load i32, i32* %2
%19 = load i8*, i8** %4
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %18, i8* %19)
br label %21
21: ; preds = %14, %16, %1
ret void
}

LLVM IR (-O2):
@POSIX_FADV_DONTNEED = global i32 0
@.str = [49 x i8] c"The fd argument was not a valid file descriptor.\00"
@.str.1 = [43 x i8] c"An invalid value was specified for advice.\00"
@.str.2 = [14 x i8] c"Unknown error\00"
@stderr = global i32 0
@.str.3 = [36 x i8] c"Failed to posix_fadvise() '%d': %s\0A\00"
define void @advise_dontneed(i32 %0) {
%2 = load i32, i32* @POSIX_FADV_DONTNEED
%3 = tail call i32 @posix_fadvise(i32 %0, i32 0, i32 0, i32 %2)
switch i32 %3, label %5 [
i32 0, label %10
i32 130, label %6
i32 129, label %4
i32 128, label %10
]
4: ; preds = %1
br label %6
5: ; preds = %1
br label %6
6: ; preds = %1, %5, %4
%7 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), %5 ], [ getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), %1 ]
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %0, i8* %7)
br label %10
10: ; preds = %1, %6, %1
ret void
}