#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, unsigned long, unsigned long long);
int pc_test_bit(unsigned long int nr, unsigned long *bitmap,
                unsigned long long total) {
  if (!bitmap)
    return -1;
  if (nr >= total) {
    printf("test block %lu out of boundary(%llu)\n", nr, total);
    exit(1);
  }
  unsigned long offset = nr / (((int)sizeof(unsigned long)) * 8);
  unsigned long bit = nr & ((((int)sizeof(unsigned long)) * 8) - 1);
  return (bitmap[offset] >> bit) & 1;
}


x86 assembly (clang, -O0):
<pc_test_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    114b <pc_test_bit+0x2b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <pc_test_bit+0x89>
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jb     1177 <pc_test_bit+0x57>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x10(%rbp),%rax
shr    $0x6,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
and    $0x3f,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x30(%rbp),%rcx
shr    %cl,%rax
and    $0x1,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pc_test_bit>:
push   %rax
test   %rsi,%rsi
je     1141 <pc_test_bit+0x21>
mov    %rdi,%rcx
cmp    %rdx,%rdi
jae    1148 <pc_test_bit+0x28>
mov    %rcx,%rax
shr    $0x6,%rax
mov    (%rsi,%rax,8),%rax
shr    %cl,%rax
and    $0x1,%eax
pop    %rcx
ret
mov    $0xffffffff,%eax
pop    %rcx
ret
lea    0xeb1(%rip),%rdi
mov    %rcx,%rsi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"test block %lu out of boundary(%llu)\0A\00"
define i32 @pc_test_bit(i64 %0, i64* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i64 %0, i64* %5
store i64* %1, i64** %6
store i64 %2, i64* %7
%10 = load i64*, i64** %6
%11 = icmp ne i64* %10, null
br i1 %11, label %13, label %12
12: ; preds = %3
store i32 -1, i32* %4
br label %35
13: ; preds = %3
%14 = load i64, i64* %5
%15 = load i64, i64* %7
%16 = icmp uge i64 %14, %15
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i64, i64* %5
%19 = load i64, i64* %7
%20 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i64 %18, i64 %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = load i64, i64* %5
%24 = udiv i64 %23, 64
store i64 %24, i64* %8
%25 = load i64, i64* %5
%26 = and i64 %25, 63
store i64 %26, i64* %9
%27 = load i64*, i64** %6
%28 = load i64, i64* %8
%29 = getelementptr inbounds i64, i64* %27, i64 %28
%30 = load i64, i64* %29
%31 = load i64, i64* %9
%32 = lshr i64 %30, %31
%33 = and i64 %32, 1
%34 = trunc i64 %33 to i32
store i32 %34, i32* %4
br label %35
35: ; preds = %22, %12
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
@.str = [38 x i8] c"test block %lu out of boundary(%llu)\0A\00"
define i32 @pc_test_bit(i64 %0, i64* %1, i64 %2) {
%4 = icmp eq i64* %1, null
br i1 %4, label %18, label %5
5: ; preds = %3
%6 = icmp ult i64 %0, %2
br i1 %6, label %10, label %7
7: ; preds = %5
%8 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i64 %0, i64 %2)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %5
%11 = lshr i64 %0, 6
%12 = and i64 %0, 63
%13 = getelementptr inbounds i64, i64* %1, i64 %11
%14 = load i64, i64* %13
%15 = lshr i64 %14, %12
%16 = trunc i64 %15 to i32
%17 = and i32 %16, 1
br label %18
18: ; preds = %3, %10
%19 = phi i32 [ %17, %10 ], [ -1, %3 ]
ret i32 %19
}