#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*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ close(int);
scalar_t__ mmap(int /*<<< orphan*/, int, int, int /*<<< orphan*/, int,
                int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int main(void) {
  int fd;
  int i;
  char pix[4] = {0x00, 0xff, 0x00, 0xff};
  char *fb;
  i = 10000;
  fd = open("/dev/cdata", O_RDWR);
  fb = (char *)mmap(0, 1024, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xec2(%rip),%eax
mov    %eax,-0xc(%rbp)
movl   $0x2710,-0x8(%rbp)
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xeac(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%edx
mov    0x2e58(%rip),%rax
or     (%rax),%edx
mov    0x2e6f(%rip),%rax
mov    (%rax),%ecx
mov    -0x4(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x400,%esi
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    0xebf(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
mov    0x2ea9(%rip),%rax
mov    0x2e72(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e87(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x400,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.pix = [4 x i8] c"\00\FF\00\FF"
@.str = [11 x i8] c"/dev/cdata\00"
@O_RDWR = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4 x i8]
%4 = alloca i8*
%5 = bitcast [4 x i8]* %3 to i8*
store i32 10000, i32* %2
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %1
%8 = load i32, i32* @PROT_READ
%9 = load i32, i32* @PROT_WRITE
%10 = or i32 %8, %9
%11 = load i32, i32* @MAP_SHARED
%12 = load i32, i32* %1
%13 = call i64 @mmap(i32 0, i32 1024, i32 %10, i32 %11, i32 %12, i32 0)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %4
%15 = load i32, i32* %1
%16 = call i32 @close(i32 %15)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/cdata\00"
@O_RDWR = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 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 i64 @mmap(i32 0, i32 1024, i32 %5, i32 %6, i32 %2, i32 0)
%8 = tail call i32 @close(i32 %2)
ret i32 0
}