#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*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ *xmalloc(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 = xmalloc((0x10000 / 8));
    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    119a <pbm_set+0x6a>
mov    $0x2000,%edi
call   1040 <xmalloc@plt>
mov    %rax,-0x28(%rbp)
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    116d <pbm_set+0x3d>
mov    %rdi,%r14
mov    $0x2000,%edi
call   1040 <xmalloc@plt>
mov    %rax,%rbx
mov    %rax,%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):
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 %27, label %19
19: ; preds = %2
%20 = call i32* @xmalloc(i32 8192)
store i32* %20, i32** %7
%21 = load i32*, i32** %7
%22 = call i32 @memset(i32* %21, i32 0, i32 8192)
%23 = load i32*, i32** %7
%24 = load i32**, i32*** %3
%25 = load i64, i64* %5
%26 = getelementptr inbounds i32*, i32** %24, i64 %25
store i32* %23, i32** %26
br label %27
27: ; preds = %19, %2
%28 = load i32**, i32*** %3
%29 = load i64, i64* %5
%30 = getelementptr inbounds i32*, i32** %28, i64 %29
%31 = load i32*, i32** %30
%32 = load i64, i64* %6
%33 = call i32 @bm_set(i32* %31, i64 %32)
ret void
}

LLVM IR (-O2):
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 %11
8: ; preds = %2
%9 = tail call i32* @xmalloc(i32 8192)
%10 = tail call i32 @memset(i32* %9, i32 0, i32 8192)
store i32* %9, i32** %5
br label %11
11: ; preds = %8, %2
%12 = phi i32* [ %9, %8 ], [ %6, %2 ]
%13 = and i32 %1, 65535
%14 = zext i32 %13 to i64
%15 = tail call i32 @bm_set(i32* %12, i64 %14)
ret void
}