#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 */
struct fb_fix_screeninfo {
  int /*<<< orphan*/ smem_len;
};
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int PROT_READ;
int PROT_WRITE;
scalar_t__ mmap(int /*<<< orphan*/ *, int /*<<< orphan*/, int,
                int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
void *fb_mmap(int fbfp, struct fb_fix_screeninfo *scinfo) {
  void *buf;
  if ((buf =
           (unsigned char *)mmap(NULL, scinfo->smem_len, PROT_READ | PROT_WRITE,
                                 MAP_SHARED, fbfp, (off_t)0)) == MAP_FAILED) {
    perror("mmap error");
    return NULL;
  }
  return buf;
}


x86 assembly (clang, -O0):
<fb_mmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    0x2ebc(%rip),%rax
mov    (%rax),%edx
mov    0x2e8b(%rip),%rax
or     (%rax),%edx
mov    0x2e9a(%rip),%rax
mov    (%rax),%ecx
mov    -0xc(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e5d(%rip),%rcx
cmp    (%rcx),%rax
jne    118d <fb_mmap+0x6d>
lea    0xe85(%rip),%rdi
call   1040 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    1195 <fb_mmap+0x75>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fb_mmap>:
push   %rax
mov    %edi,%r8d
mov    (%rsi),%esi
mov    0x2ecb(%rip),%rax
mov    0x2e9c(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2ea9(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2e76(%rip),%rcx
cmp    %rax,(%rcx)
je     1159 <fb_mmap+0x39>
pop    %rcx
ret
lea    0xea0(%rip),%rdi
call   1040 <perror@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.fb_fix_screeninfo = type { i32 }
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str = [11 x i8] c"mmap error\00"
define i8* @fb_mmap(i32 %0, %struct.fb_fix_screeninfo* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.fb_fix_screeninfo*
%6 = alloca i8*
store i32 %0, i32* %4
store %struct.fb_fix_screeninfo* %1, %struct.fb_fix_screeninfo** %5
%7 = load %struct.fb_fix_screeninfo*, %struct.fb_fix_screeninfo** %5
%8 = getelementptr inbounds %struct.fb_fix_screeninfo, %struct.fb_fix_screeninfo* %7, i32 0, i32 0
%9 = load i32, i32* %8
%10 = load i32, i32* @PROT_READ
%11 = load i32, i32* @PROT_WRITE
%12 = or i32 %10, %11
%13 = load i32, i32* @MAP_SHARED
%14 = load i32, i32* %4
%15 = call i64 @mmap(i32* null, i32 %9, i32 %12, i32 %13, i32 %14, i32 0)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %6
%17 = load i8*, i8** @MAP_FAILED
%18 = icmp eq i8* %16, %17
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %3
br label %23
21: ; preds = %2
%22 = load i8*, i8** %6
store i8* %22, i8** %3
br label %23
23: ; preds = %21, %19
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
%struct.fb_fix_screeninfo = type { i32 }
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str = [11 x i8] c"mmap error\00"
define i8* @fb_mmap(i32 %0, %struct.fb_fix_screeninfo* nocapture %1) {
%3 = getelementptr inbounds %struct.fb_fix_screeninfo, %struct.fb_fix_screeninfo* %1, i64 0, i32 0
%4 = load i32, i32* %3
%5 = load i32, i32* @PROT_READ
%6 = load i32, i32* @PROT_WRITE
%7 = or i32 %6, %5
%8 = load i32, i32* @MAP_SHARED
%9 = tail call i64 @mmap(i32* null, i32 %4, i32 %7, i32 %8, i32 %0, i32 0)
%10 = inttoptr i64 %9 to i8*
%11 = load i8*, i8** @MAP_FAILED
%12 = icmp eq i8* %11, %10
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %2, %13
%16 = phi i8* [ null, %13 ], [ %10, %2 ]
ret i8* %16
}