#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*/ uint8_t;
typedef int uint32_t;
typedef size_t uint16_t;

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


x86 assembly (clang, -O0):
<pbm_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x10,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
and    $0xffff,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11c8 <pbm_set+0x88>
mov    $0x2000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a8 <pbm_set+0x68>
lea    0xe64(%rip),%rdi
lea    0xe61(%rip),%rsi
call   1060 <log_fatal@plt>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1030 <memset@plt>
mov    -0x28(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <bm_set@plt>
add    $0x30,%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    $0x2000,%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    $0x2000,%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 i64
%6 = alloca i64
%7 = alloca i32*
store i32** %0, i32*** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = ashr i32 %8, 16
%10 = sext i32 %9 to i64
store i64 %10, i64* %5
%11 = load i32, i32* %4
%12 = and i32 %11, 65535
%13 = sext i32 %12 to i64
store i64 %13, i64* %6
%14 = load i32**, i32*** %3
%15 = load i64, i64* %5
%16 = getelementptr inbounds i32*, i32** %14, i64 %15
%17 = load i32*, i32** %16
%18 = icmp ne i32* %17, null
br i1 %18, label %32, label %19
19: ; preds = %2
%20 = call i32* @malloc(i32 8192)
store i32* %20, i32** %7
%21 = load i32*, i32** %7
%22 = icmp ne i32* %21, null
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = 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 %25
25: ; preds = %23, %19
%26 = load i32*, i32** %7
%27 = call i32 @memset(i32* %26, i32 0, i32 8192)
%28 = load i32*, i32** %7
%29 = load i32**, i32*** %3
%30 = load i64, i64* %5
%31 = getelementptr inbounds i32*, i32** %29, i64 %30
store i32* %28, i32** %31
br label %32
32: ; preds = %25, %2
%33 = load i32**, i32*** %3
%34 = load i64, i64* %5
%35 = getelementptr inbounds i32*, i32** %33, i64 %34
%36 = load i32*, i32** %35
%37 = load i64, i64* %6
%38 = call i32 @bm_set(i32* %36, i64 %37)
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 8192)
%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 8192)
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 = zext i32 %17 to i64
%19 = tail call i32 @bm_set(i32* %16, i64 %18)
ret void
}