#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 int /*<<< orphan*/ off_t;

/* Variables and functions */
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
void *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void *my_fb_map(int shm_fd) {
  void *shm_buf;
  if (shm_fd > 0) {
    shm_buf = mmap(NULL, 320 * 200 * 3, PROT_READ | PROT_WRITE, MAP_SHARED,
                   shm_fd, (off_t)0);
    if (shm_buf == MAP_FAILED) {
      fprintf(stderr, "mmap failed: %s\n", strerror(errno));
      shm_buf = NULL;
    }
  } else {
    fprintf(stderr, "shm_open failed: %s\n", strerror(errno));
  }
  return shm_buf;
}


x86 assembly (clang, -O0):
<my_fb_map>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    11c6 <my_fb_map+0x96>
mov    0x2eac(%rip),%rax
mov    (%rax),%edx
mov    0x2e6b(%rip),%rax
or     (%rax),%edx
mov    0x2e8a(%rip),%rax
mov    (%rax),%ecx
mov    -0x4(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x2ee00,%esi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e34(%rip),%rcx
cmp    (%rcx),%rax
jne    11c1 <my_fb_map+0x91>
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe4c(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x10(%rbp)
jmp    11f2 <my_fb_map+0xc2>
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe24(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_fb_map>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
jle    1179 <my_fb_map+0x49>
mov    %edi,%r8d
mov    0x2eb7(%rip),%rax
mov    0x2e78(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e95(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x2ee00,%esi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2e4d(%rip),%rcx
cmp    (%rcx),%rax
jne    11a6 <my_fb_map+0x76>
lea    0xe89(%rip),%rbx
jmp    1180 <my_fb_map+0x50>
lea    0xe91(%rip),%rbx
mov    0x2e49(%rip),%rax
mov    (%rax),%ebp
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@stderr = global i32 0
@.str = [17 x i8] c"mmap failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [21 x i8] c"shm_open failed: %s\0A\00"
define i8* @my_fb_map(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %22
6: ; preds = %1
%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* %2
%12 = call i8* @mmap(i32* null, i32 192000, i32 %9, i32 %10, i32 %11, i32 0)
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = load i8*, i8** @MAP_FAILED
%15 = icmp eq i8* %13, %14
br i1 %15, label %16, label %21
16: ; preds = %6
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %19)
store i8* null, i8** %3
br label %21
21: ; preds = %16, %6
br label %27
22: ; preds = %1
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %22, %21
%28 = load i8*, i8** %3
ret i8* %28
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@stderr = global i32 0
@.str = [17 x i8] c"mmap failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [21 x i8] c"shm_open failed: %s\0A\00"
define i8* @my_fb_map(i32 %0) {
%2 = icmp sgt i32 %0, 0
br i1 %2, label %3, label %11
3: ; preds = %1
%4 = load i32, i32* @PROT_READ
%5 = load i32, i32* @PROT_WRITE
%6 = or i32 %5, %4
%7 = load i32, i32* @MAP_SHARED
%8 = tail call i8* @mmap(i32* null, i32 192000, i32 %6, i32 %7, i32 %0, i32 0)
%9 = load i8*, i8** @MAP_FAILED
%10 = icmp eq i8* %8, %9
br i1 %10, label %11, label %17
11: ; preds = %1, %3
%12 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), %1 ]
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = tail call i32 @fprintf(i32 %13, i8* %12, i8* %15)
br label %17
17: ; preds = %11, %3
%18 = phi i8* [ %8, %3 ], [ null, %11 ]
ret i8* %18
}