#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*/ EXIT_FAILURE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int munmap(void *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
void ipc_close(int fd, void *data, int size) {
  if (munmap(data, size) == -1)
    do {
      perror("munmap");
      exit(EXIT_FAILURE);
    } while (0);
  close(fd);
  printf("  ipc_close: file unmapped\n");
  return;
}


x86 assembly (clang, -O0):
<ipc_close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <munmap@plt>
cmp    $0xffffffff,%eax
jne    1196 <ipc_close+0x46>
jmp    117c <ipc_close+0x2c>
lea    0xe7d(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipc_close>:
push   %rbx
mov    %edi,%ebx
mov    %rsi,%rdi
mov    %edx,%esi
call   1050 <munmap@plt>
cmp    $0xffffffff,%eax
je     1176 <ipc_close+0x26>
mov    %ebx,%edi
call   1040 <close@plt>
lea    0xe97(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>
lea    0xe83(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"munmap\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [28 x i8] c" ipc_close: file unmapped\0A\00"
define void @ipc_close(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load i8*, i8** %5
%8 = load i32, i32* %6
%9 = call i32 @munmap(i8* %7, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %17
11: ; preds = %3
br label %12
12: ; preds = %11
%13 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; No predecessors!
br label %17
17: ; preds = %16, %3
%18 = load i32, i32* %4
%19 = call i32 @close(i32 %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"munmap\00"
@EXIT_FAILURE = global i32 0
@str = [27 x i8] c" ipc_close: file unmapped\00"
define void @ipc_close(i32 %0, i8* %1, i32 %2) {
%4 = tail call i32 @munmap(i8* %1, i32 %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %3
%11 = tail call i32 @close(i32 %0)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
ret void
}