#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 */
typedef scalar_t__ caddr_t;

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ exit(int);
void *mmap(scalar_t__, int, int, int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
void *ipc_map(int fd, int size) {
  void *data;
  data = mmap((caddr_t)0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  if ((caddr_t)data == (caddr_t)(-1)) {
    printf("\n*** error mapping ipc data file\r\n");
    perror("mmap");
    printf("*** terminating program\n\n");
    exit(1);
  }
  printf("file mapped to memory\n");
  return data;
}


x86 assembly (clang, -O0):
<ipc_map>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%esi
mov    0x2ea0(%rip),%rax
mov    (%rax),%edx
mov    0x2e6f(%rip),%rax
or     (%rax),%edx
mov    0x2e7e(%rip),%rax
mov    (%rax),%ecx
mov    -0x4(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    $0xffffffffffffffff,%rax
jne    11bc <ipc_map+0x7c>
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
lea    0xe82(%rip),%rdi
call   1050 <perror@plt>
lea    0xe7b(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xe7f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipc_map>:
push   %rbx
mov    %edi,%r8d
mov    0x2ead(%rip),%rax
mov    0x2e7e(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e8b(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
xor    %r9d,%r9d
call   1040 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
je     1183 <ipc_map+0x43>
mov    %rax,%rbx
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rax
pop    %rbx
ret
lea    0xe91(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6a(%rip),%rdi
call   1050 <perror@plt>
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str = [35 x i8] c"\0A*** error mapping ipc data file\0D\0A\00"
@.str.1 = [5 x i8] c"mmap\00"
@.str.2 = [26 x i8] c"*** terminating program\0A\0A\00"
@.str.3 = [23 x i8] c"file mapped to memory\0A\00"
define i8* @ipc_map(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = load i32, i32* @PROT_READ
%8 = load i32, i32* @PROT_WRITE
%9 = or i32 %7, %8
%10 = load i32, i32* @MAP_SHARED
%11 = load i32, i32* %3
%12 = call i8* @mmap(i64 0, i32 %6, i32 %9, i32 %10, i32 %11, i32 0)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = ptrtoint i8* %13 to i64
%15 = icmp eq i64 %14, -1
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%23 = load i8*, i8** %5
ret i8* %23
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.1 = [5 x i8] c"mmap\00"
@str = [22 x i8] c"file mapped to memory\00"
@str.4 = [34 x i8] c"\0A*** error mapping ipc data file\0D\00"
@str.5 = [25 x i8] c"*** terminating program\0A\00"
define i8* @ipc_map(i32 %0, i32 %1) {
%3 = load i32, i32* @PROT_READ
%4 = load i32, i32* @PROT_WRITE
%5 = or i32 %4, %3
%6 = load i32, i32* @MAP_SHARED
%7 = tail call i8* @mmap(i64 0, i32 %1, i32 %5, i32 %6, i32 %0, i32 0)
%8 = icmp eq i8* %7, inttoptr (i64 -1 to i8*)
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.4, i64 0, i64 0))
%11 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.5, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
ret i8* %7
}