#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 void uint64_t;
typedef int /*<<< orphan*/ nblocks;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *xfopen(char *, char *);
void *xmmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/, int /*<<< orphan*/,
            int /*<<< orphan*/, int /*<<< orphan*/);
uint64_t *load_block_map(char *file) {
  int nblocks;
  void *ptr;
  FILE *fp = xfopen(file, "r");
  fread(&nblocks, sizeof(nblocks), 1, fp);
  ptr = xmmap(NULL, nblocks * sizeof(uint64_t), PROT_READ, MAP_SHARED,
              fileno(fp), 0);
  return ptr + sizeof(nblocks);
}


x86 assembly (clang, -O0):
<load_block_map>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1040 <xfopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
lea    -0xc(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,-0x2c(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <fileno@plt>
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    %eax,%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1060 <xmmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x4,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_block_map>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeb2(%rip),%rsi
call   1040 <xfopen@plt>
mov    %rax,%rbx
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    0x4(%rsp),%r14d
mov    0x2e7f(%rip),%rax
mov    (%rax),%r15d
mov    0x2e65(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1050 <fileno@plt>
xor    %edi,%edi
mov    %r14d,%esi
mov    %r15d,%edx
mov    %ebp,%ecx
mov    %eax,%r8d
xor    %r9d,%r9d
call   1060 <xmmap@plt>
add    $0x4,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
define i8* @load_block_map(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @xfopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = call i32 @fread(i32* %3, i32 4, i32 1, i32* %8)
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 1
%13 = trunc i64 %12 to i32
%14 = load i32, i32* @PROT_READ
%15 = load i32, i32* @MAP_SHARED
%16 = load i32*, i32** %5
%17 = call i32 @fileno(i32* %16)
%18 = call i8* @xmmap(i32* null, i32 %13, i32 %14, i32 %15, i32 %17, i32 0)
store i8* %18, i8** %4
%19 = load i8*, i8** %4
%20 = getelementptr i8, i8* %19, i64 4
ret i8* %20
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
define i8* @load_block_map(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32* @xfopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @fread(i32* %2, i32 4, i32 1, i32* %4)
%6 = load i32, i32* %2
%7 = load i32, i32* @PROT_READ
%8 = load i32, i32* @MAP_SHARED
%9 = tail call i32 @fileno(i32* %4)
%10 = tail call i8* @xmmap(i32* null, i32 %6, i32 %7, i32 %8, i32 %9, i32 0)
%11 = getelementptr i8, i8* %10, i64 4
ret i8* %11
}