#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_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
scalar_t__ ftruncate(int, int);
int *mmap(int /*<<< orphan*/, int, int, int /*<<< orphan*/, int,
          int /*<<< orphan*/);
int open(char *, int, int);
int map_score(int **m) {
  int fd;
  if ((fd = open("/tmp/askii-score", O_RDWR | O_CREAT, 0644)) < 0)
    return -1;
  if (ftruncate(fd, sizeof(**m)) != 0)
    return -1;
  *m = mmap(0, sizeof(**m), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  if (*m == MAP_FAILED)
    return -1;
  return fd;
}


x86 assembly (clang, -O0):
<map_score>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
mov    0x2eac(%rip),%rax
or     (%rax),%esi
lea    0xeab(%rip),%rdi
mov    $0x1a4,%edx
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1177 <map_score+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fc <map_score+0xcc>
mov    -0x14(%rbp),%edi
mov    $0x4,%esi
call   1040 <ftruncate@plt>
cmp    $0x0,%rax
je     119a <map_score+0x6a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fc <map_score+0xcc>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edx
mov    0x2e16(%rip),%rax
or     (%rax),%edx
mov    0x2e2d(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x4,%esi
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2dd7(%rip),%rcx
cmp    (%rcx),%rax
jne    11f6 <map_score+0xc6>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fc <map_score+0xcc>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<map_score>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2e92(%rip),%rax
mov    0x2eb3(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xeb0(%rip),%rdi
mov    $0x1a4,%edx
call   1050 <open@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     11ba <map_score+0x8a>
mov    %eax,%ebp
mov    %eax,%edi
mov    $0x4,%esi
call   1040 <ftruncate@plt>
test   %rax,%rax
jne    11ba <map_score+0x8a>
mov    0x2e73(%rip),%rax
mov    0x2e3c(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e51(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x4,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,(%r14)
mov    0x2e0b(%rip),%rcx
cmp    (%rcx),%rax
mov    $0xffffffff,%eax
cmove  %eax,%ebp
mov    %ebp,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"/tmp/askii-score\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i32* null
define i32 @map_score(i32** %0) {
%2 = alloca i32
%3 = alloca i32**
%4 = alloca i32
store i32** %0, i32*** %3
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_CREAT
%7 = or i32 %5, %6
%8 = call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %7, i32 420)
store i32 %8, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %31
11: ; preds = %1
%12 = load i32, i32* %4
%13 = call i64 @ftruncate(i32 %12, i32 4)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 -1, i32* %2
br label %31
16: ; preds = %11
%17 = load i32, i32* @PROT_READ
%18 = load i32, i32* @PROT_WRITE
%19 = or i32 %17, %18
%20 = load i32, i32* @MAP_SHARED
%21 = load i32, i32* %4
%22 = call i32* @mmap(i32 0, i32 4, i32 %19, i32 %20, i32 %21, i32 0)
%23 = load i32**, i32*** %3
store i32* %22, i32** %23
%24 = load i32**, i32*** %3
%25 = load i32*, i32** %24
%26 = load i32*, i32** @MAP_FAILED
%27 = icmp eq i32* %25, %26
br i1 %27, label %28, label %29
28: ; preds = %16
store i32 -1, i32* %2
br label %31
29: ; preds = %16
%30 = load i32, i32* %4
store i32 %30, i32* %2
br label %31
31: ; preds = %29, %28, %15, %10
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@.str = [17 x i8] c"/tmp/askii-score\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i32* null
define i32 @map_score(i32** nocapture writeonly %0) {
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %4, i32 420)
%6 = icmp slt i32 %5, 0
br i1 %6, label %19, label %7
7: ; preds = %1
%8 = tail call i64 @ftruncate(i32 %5, i32 4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = load i32, i32* @PROT_READ
%12 = load i32, i32* @PROT_WRITE
%13 = or i32 %12, %11
%14 = load i32, i32* @MAP_SHARED
%15 = tail call i32* @mmap(i32 0, i32 4, i32 %13, i32 %14, i32 %5, i32 0)
store i32* %15, i32** %0
%16 = load i32*, i32** @MAP_FAILED
%17 = icmp eq i32* %15, %16
%18 = select i1 %17, i32 -1, i32 %5
br label %19
19: ; preds = %10, %7, %1
%20 = phi i32 [ -1, %1 ], [ -1, %7 ], [ %18, %10 ]
ret i32 %20
}