#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 */
scalar_t__ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ munmap(void *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
scalar_t__ unlink(char *);
int free_filebacked_hugepage(void *addr, int size, int fd, char *filepath) {
  int ret = 0;
  if (munmap(addr, size)) {
    perror("munmap");
    ret = -1;
  }
  if (close(fd)) {
    perror("close");
    ret = -1;
  }
  if (filepath) {
    if (unlink(filepath)) {
      perror("unlink");
      ret = -1;
    }
  } else {
    fprintf(stderr, "Filepath not specified.\n");
    ret = -1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<free_filebacked_hugepage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <munmap@plt>
cmp    $0x0,%rax
je     1196 <free_filebacked_hugepage+0x46>
lea    0xe76(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
je     11bb <free_filebacked_hugepage+0x6b>
lea    0xe58(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11f1 <free_filebacked_hugepage+0xa1>
mov    -0x18(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     11ec <free_filebacked_hugepage+0x9c>
lea    0xe2d(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x1c(%rbp)
jmp    120d <free_filebacked_hugepage+0xbd>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<free_filebacked_hugepage>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %edx,%ebx
call   1060 <munmap@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    1191 <free_filebacked_hugepage+0x41>
mov    %ebx,%edi
call   1040 <close@plt>
test   %rax,%rax
jne    11a4 <free_filebacked_hugepage+0x54>
test   %r14,%r14
je     11ba <free_filebacked_hugepage+0x6a>
mov    %r14,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
je     11d4 <free_filebacked_hugepage+0x84>
lea    0xe83(%rip),%rdi
call   1070 <perror@plt>
jmp    11cf <free_filebacked_hugepage+0x7f>
lea    0xe68(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%ebp
jmp    1165 <free_filebacked_hugepage+0x15>
lea    0xe5c(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%ebp
test   %r14,%r14
jne    1176 <free_filebacked_hugepage+0x26>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"munmap\00"
@.str.1 = [6 x i8] c"close\00"
@.str.2 = [7 x i8] c"unlink\00"
@stderr = global i32 0
@.str.3 = [25 x i8] c"Filepath not specified.\0A\00"
define i32 @free_filebacked_hugepage(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
store i32 0, i32* %9
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = call i64 @munmap(i8* %10, i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %9
br label %16
16: ; preds = %14, %4
%17 = load i32, i32* %7
%18 = call i64 @close(i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %9
br label %22
22: ; preds = %20, %16
%23 = load i8*, i8** %8
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = load i8*, i8** %8
%27 = call i64 @unlink(i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %9
br label %31
31: ; preds = %29, %25
br label %35
32: ; preds = %22
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %9
br label %35
35: ; preds = %32, %31
%36 = load i32, i32* %9
ret i32 %36
}

LLVM IR (-O2):
@.str = [7 x i8] c"munmap\00"
@.str.1 = [6 x i8] c"close\00"
@.str.2 = [7 x i8] c"unlink\00"
@stderr = global i32 0
@.str.3 = [25 x i8] c"Filepath not specified.\0A\00"
define i32 @free_filebacked_hugepage(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = tail call i64 @munmap(i8* %0, i32 %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %4
%10 = phi i32 [ -1, %7 ], [ 0, %4 ]
%11 = tail call i64 @close(i32 %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
%16 = phi i32 [ -1, %13 ], [ %10, %9 ]
%17 = icmp eq i8* %3, null
br i1 %17, label %23, label %18
18: ; preds = %15
%19 = tail call i64 @unlink(i8* %3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %18
%22 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %26
23: ; preds = %15
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %18, %21, %23
%27 = phi i32 [ -1, %21 ], [ %16, %18 ], [ -1, %23 ]
ret i32 %27
}