#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 MAP_FILE;
int MAP_SHARED;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ close(int);
void *mmap(int /*<<< orphan*/, int, int, int, int, int);
int /*<<< orphan*/ printf(char *, char *, ...);
void *drvOCM_Mmap(int fd, int addr_base) {
  void *pntr = (void *)0;
  pntr = mmap(0, 0X40000, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd,
              addr_base);
  if (pntr == NULL) {
    printf("%s Can't Open mmap\n", "[drvOCM]");
    close(fd);
    return NULL;
  } else if (pntr == (void *)(-1)) {
    printf("%s Can't Open mmap\n", "[drvOCM]");
    printf("%s InValid addr : 0x%x\n", "[drvOCM]", pntr);
    close(fd);
    return NULL;
  } else {
    printf("%s Open Mmap Success\n", "[drvOCM]");
    printf("%s Valid addr : 0x%x\n", "[drvOCM]", pntr);
    return pntr;
  }
}


x86 assembly (clang, -O0):
<drvOCM_Mmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2eab(%rip),%rax
mov    (%rax),%edx
mov    0x2e72(%rip),%rax
or     (%rax),%edx
mov    0x2e79(%rip),%rax
mov    (%rax),%ecx
mov    0x2e80(%rip),%rax
or     (%rax),%ecx
mov    -0xc(%rbp),%r8d
mov    -0x10(%rbp),%r9d
xor    %edi,%edi
mov    $0x40000,%esi
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b7 <drvOCM_Mmap+0x87>
lea    0xe6c(%rip),%rdi
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
movq   $0x0,-0x8(%rbp)
jmp    1241 <drvOCM_Mmap+0x111>
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x18(%rbp)
jne    120b <drvOCM_Mmap+0xdb>
lea    0xe31(%rip),%rdi
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdx
lea    0xe35(%rip),%rdi
lea    0xe25(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
movq   $0x0,-0x8(%rbp)
jmp    1241 <drvOCM_Mmap+0x111>
lea    0xe23(%rip),%rdi
lea    0xdfb(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdx
lea    0xe20(%rip),%rdi
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drvOCM_Mmap>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r9d
mov    %edi,%ebp
mov    0x2eb8(%rip),%rax
mov    0x2e81(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e86(%rip),%rax
mov    0x2e8f(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x40000,%esi
mov    %ebp,%r8d
call   1030 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
je     1193 <drvOCM_Mmap+0x63>
mov    %rax,%rbx
test   %rax,%rax
jne    11ce <drvOCM_Mmap+0x9e>
lea    0xe7f(%rip),%rdi
lea    0xe8c(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c5 <drvOCM_Mmap+0x95>
lea    0xe66(%rip),%rdi
lea    0xe73(%rip),%r14
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe69(%rip),%rdi
mov    %r14,%rsi
mov    $0xffffffffffffffff,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    11fa <drvOCM_Mmap+0xca>
lea    0xe60(%rip),%rdi
lea    0xe38(%rip),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe5e(%rip),%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_FILE = global i32 0
@MAP_SHARED = global i32 0
@.str = [20 x i8] c"%s Can't Open mmap\0A\00"
@.str.1 = [9 x i8] c"[drvOCM]\00"
@.str.2 = [24 x i8] c"%s InValid addr : 0x%x\0A\00"
@.str.3 = [22 x i8] c"%s Open Mmap Success\0A\00"
@.str.4 = [22 x i8] c"%s Valid addr : 0x%x\0A\00"
define i8* @drvOCM_Mmap(i32 %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* null, i8** %6
%7 = load i32, i32* @PROT_READ
%8 = load i32, i32* @PROT_WRITE
%9 = or i32 %7, %8
%10 = load i32, i32* @MAP_FILE
%11 = load i32, i32* @MAP_SHARED
%12 = or i32 %10, %11
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = call i8* @mmap(i32 0, i32 262144, i32 %9, i32 %12, i32 %13, i32 %14)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* %4
%21 = call i32 @close(i32 %20)
store i8* null, i8** %3
br label %36
22: ; preds = %2
%23 = load i8*, i8** %6
%24 = icmp eq i8* %23, inttoptr (i64 -1 to i8*)
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%27 = load i8*, i8** %6
%28 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i32, i32* %4
%30 = call i32 @close(i32 %29)
store i8* null, i8** %3
br label %36
31: ; preds = %22
%32 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%33 = load i8*, i8** %6
%34 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = load i8*, i8** %6
store i8* %35, i8** %3
br label %36
36: ; preds = %31, %25, %18
%37 = load i8*, i8** %3
ret i8* %37
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_FILE = global i32 0
@MAP_SHARED = global i32 0
@.str = [20 x i8] c"%s Can't Open mmap\0A\00"
@.str.1 = [9 x i8] c"[drvOCM]\00"
@.str.2 = [24 x i8] c"%s InValid addr : 0x%x\0A\00"
@.str.3 = [22 x i8] c"%s Open Mmap Success\0A\00"
@.str.4 = [22 x i8] c"%s Valid addr : 0x%x\0A\00"
define i8* @drvOCM_Mmap(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_FILE
%7 = load i32, i32* @MAP_SHARED
%8 = or i32 %7, %6
%9 = tail call i8* @mmap(i32 0, i32 262144, i32 %5, i32 %8, i32 %0, i32 %1)
%10 = ptrtoint i8* %9 to i64
switch i64 %10, label %18 [
i64 0, label %11
i64 -1, label %14
]
11: ; preds = %2
%12 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @close(i32 %0)
br label %21
14: ; preds = %2
%15 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* inttoptr (i64 -1 to i8*))
%17 = tail call i32 @close(i32 %0)
br label %21
18: ; preds = %2
%19 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %21
21: ; preds = %18, %14, %11
%22 = phi i8* [ null, %11 ], [ null, %14 ], [ %9, %18 ]
ret i8* %22
}