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

/* Variables and functions */
int /*<<< orphan*/ bm_set(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ log_fatal(char *, char *);
int /*<<< orphan*/ *malloc(int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
void pbm_set(uint64_t **b, uint32_t v) {
  uint32_t top = v >> 16;
  uint32_t bottom = v & 0xFFFF;
  if (!b[top]) {
    uint64_t *bm = malloc(0xFFFF);
    if (!bm) {
      log_fatal("bpm", "unable to allocate memory for new bitmap page");
    }
    memset(bm, 0, 0xFFFF);
    b[top] = bm;
  }
  bm_set(b[top], bottom);
}


x86 assembly (clang, -O0):
<pbm_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x10,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
and    $0xffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11c2 <pbm_set+0x82>
mov    $0xffff,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a2 <pbm_set+0x62>
lea    0xe6a(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1060 <log_fatal@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xffff,%edx
call   1030 <memset@plt>
mov    -0x20(%rbp),%rdx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x14(%rbp),%esi
call   1050 <bm_set@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pbm_set>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %esi,%eax
sar    $0x10,%eax
movslq %eax,%r15
mov    (%rdi,%r15,8),%rbx
test   %rbx,%rbx
jne    1195 <pbm_set+0x55>
mov    %rdi,%r14
mov    $0xffff,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1182 <pbm_set+0x42>
lea    0xe8a(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1060 <log_fatal@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xffff,%edx
call   1030 <memset@plt>
mov    %rbx,(%r14,%r15,8)
movzwl %bp,%esi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <bm_set@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"bpm\00"
@.str.1 = [46 x i8] c"unable to allocate memory for new bitmap page\00"
define void @pbm_set(i32** %0, i32 %1) {
%3 = alloca i32**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i32** %0, i32*** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = ashr i32 %8, 16
store i32 %9, i32* %5
%10 = load i32, i32* %4
%11 = and i32 %10, 65535
store i32 %11, i32* %6
%12 = load i32**, i32*** %3
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32*, i32** %12, i64 %14
%16 = load i32*, i32** %15
%17 = icmp ne i32* %16, null
br i1 %17, label %32, label %18
18: ; preds = %2
%19 = call i32* @malloc(i32 65535)
store i32* %19, i32** %7
%20 = load i32*, i32** %7
%21 = icmp ne i32* %20, null
br i1 %21, label %24, label %22
22: ; preds = %18
%23 = call i32 @log_fatal(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
%25 = load i32*, i32** %7
%26 = call i32 @memset(i32* %25, i32 0, i32 65535)
%27 = load i32*, i32** %7
%28 = load i32**, i32*** %3
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32*, i32** %28, i64 %30
store i32* %27, i32** %31
br label %32
32: ; preds = %24, %2
%33 = load i32**, i32*** %3
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32*, i32** %33, i64 %35
%37 = load i32*, i32** %36
%38 = load i32, i32* %6
%39 = call i32 @bm_set(i32* %37, i32 %38)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"bpm\00"
@.str.1 = [46 x i8] c"unable to allocate memory for new bitmap page\00"
define void @pbm_set(i32** nocapture %0, i32 %1) {
%3 = ashr i32 %1, 16
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i32*, i32** %0, i64 %4
%6 = load i32*, i32** %5
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %15
8: ; preds = %2
%9 = tail call i32* @malloc(i32 65535)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @log_fatal(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
%14 = tail call i32 @memset(i32* %9, i32 0, i32 65535)
store i32* %9, i32** %5
br label %15
15: ; preds = %13, %2
%16 = phi i32* [ %9, %13 ], [ %6, %2 ]
%17 = and i32 %1, 65535
%18 = tail call i32 @bm_set(i32* %16, i32 %17)
ret void
}