#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 */
unsigned char *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ getpagesize();
unsigned char *mmap(int /*<<< orphan*/ *, int /*<<< orphan*/,
                    int /*<<< orphan*/, int /*<<< orphan*/, int, int);
int open(char *, int /*<<< orphan*/);
int main(void) {
  int fd;
  unsigned char *p;
  fd = open("/dev/gpiomem", O_RDONLY);
  if (fd < 0)
    err(1, "open");
  p = mmap(NULL, getpagesize(), PROT_READ, MAP_SHARED, fd, 0x10000);
  if (p == MAP_FAILED)
    err(1, "mmap");
  p[0] = 1;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1182 <main+0x42>
mov    $0x1,%edi
lea    0xe90(%rip),%rsi
call   1040 <err@plt>
mov    $0x0,%al
call   1060 <getpagesize@plt>
mov    %eax,%esi
mov    0x2e66(%rip),%rax
mov    (%rax),%edx
mov    0x2e4d(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x10000,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e09(%rip),%rcx
cmp    (%rcx),%rax
jne    11d9 <main+0x99>
mov    $0x1,%edi
lea    0xe3e(%rip),%rsi
call   1040 <err@plt>
mov    -0x10(%rbp),%rax
movb   $0x1,(%rax)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0xeaf(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    116d <main+0x2d>
lea    0xeaa(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
xor    %eax,%eax
call   1060 <getpagesize@plt>
mov    0x2e7d(%rip),%rcx
mov    (%rcx),%edx
mov    0x2e64(%rip),%rcx
mov    (%rcx),%ecx
xor    %edi,%edi
mov    %eax,%esi
mov    %ebx,%r8d
mov    $0x10000,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
mov    0x2e26(%rip),%rax
cmp    (%rax),%rbx
jne    11b8 <main+0x78>
lea    0xe64(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
movb   $0x1,(%rbx)
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/gpiomem\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [5 x i8] c"mmap\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = call i32 (...) @getpagesize()
%12 = load i32, i32* @PROT_READ
%13 = load i32, i32* @MAP_SHARED
%14 = load i32, i32* %2
%15 = call i8* @mmap(i32* null, i32 %11, i32 %12, i32 %13, i32 %14, i32 65536)
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = load i8*, i8** @MAP_FAILED
%18 = icmp eq i8* %16, %17
br i1 %18, label %19, label %21
19: ; preds = %10
%20 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %10
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 0
store i8 1, i8* %23
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/gpiomem\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [5 x i8] c"mmap\00"
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %4, %0
%7 = tail call i32 (...) @getpagesize()
%8 = load i32, i32* @PROT_READ
%9 = load i32, i32* @MAP_SHARED
%10 = tail call i8* @mmap(i32* null, i32 %7, i32 %8, i32 %9, i32 %2, i32 65536)
%11 = load i8*, i8** @MAP_FAILED
%12 = icmp eq i8* %10, %11
br i1 %12, label %13, label %15
13: ; preds = %6
%14 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %6
store i8 1, i8* %10
ret i32 0
}