#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 uint8_t;
typedef int uint32_t;

/* Variables and functions */
uint32_t *bitband(uint32_t *address, uint8_t bit) {
  uint32_t bitband_addr = (uint32_t)address;
  if (bitband_addr > 0x40000000) {
    bitband_addr -= 0x40000000;
    bitband_addr <<= 5;
    bitband_addr += 0x42000000;
  } else {
    bitband_addr -= 0x20000000;
    bitband_addr <<= 5;
    bitband_addr += 0x22000000;
  }
  bitband_addr += (bit << 2);
  return (uint32_t *)bitband_addr;
}


x86 assembly (clang, -O0):
<bitband>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,-0x10(%rbp)
cmpl   $0x40000000,-0x10(%rbp)
jle    1143 <bitband+0x43>
mov    -0x10(%rbp),%eax
sub    $0x40000000,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x5,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x42000000,%eax
mov    %eax,-0x10(%rbp)
jmp    1162 <bitband+0x62>
mov    -0x10(%rbp),%eax
sub    $0x20000000,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x5,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x22000000,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x2,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
movslq -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitband>:
xor    %eax,%eax
cmp    $0x40000001,%edi
setge  %al
shl    $0x5,%edi
shl    $0x1d,%eax
lea    (%rdi,%rsi,4),%ecx
add    %ecx,%eax
add    $0x22000000,%eax
cltq
ret

LLVM IR (-O0):
define i32* @bitband(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = load i32*, i32** %3
%7 = ptrtoint i32* %6 to i32
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp sgt i32 %8, 1073741824
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* %5
%12 = sub nsw i32 %11, 1073741824
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = shl i32 %13, 5
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 1107296256
store i32 %16, i32* %5
br label %24
17: ; preds = %2
%18 = load i32, i32* %5
%19 = sub nsw i32 %18, 536870912
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = shl i32 %20, 5
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 570425344
store i32 %23, i32* %5
br label %24
24: ; preds = %17, %10
%25 = load i32, i32* %4
%26 = shl i32 %25, 2
%27 = load i32, i32* %5
%28 = add nsw i32 %27, %26
store i32 %28, i32* %5
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = inttoptr i64 %30 to i32*
ret i32* %31
}

LLVM IR (-O2):
define i32* @bitband(i32* %0, i32 %1) {
%3 = ptrtoint i32* %0 to i64
%4 = trunc i64 %3 to i32
%5 = icmp sgt i32 %4, 1073741824
%6 = shl i32 %4, 5
%7 = select i1 %5, i32 1107296256, i32 570425344
%8 = shl i32 %1, 2
%9 = add i32 %6, %8
%10 = add i32 %9, %7
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i32*
ret i32* %12
}