#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*/ register_val;

/* Variables and functions */
int /*<<< orphan*/ print_bits(unsigned char);
int /*<<< orphan*/ printf(char *, ...);
unsigned char read_bit(unsigned char);
int main(void) {
  unsigned char register_val[] = {
      0x00,
      0xff,
      (1 << 5) | (1 << (5 + 1)) | (1 << (5 - 1)),
      (1 << (5 + 1)) | (1 << (5 - 1)),
  };
  for (int i = 0; i < (sizeof(register_val) / sizeof(unsigned char)); i++) {
    unsigned char result = read_bit(register_val[i]);
    printf("When register is 0x%02x, the result is ", register_val[i]);
    print_bits(result);
    printf("%s", "\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xebb(%rip),%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x4,%rax
jae    11b1 <main+0x81>
movslq -0xc(%rbp),%rax
movzbl -0x8(%rbp,%rax,1),%edi
call   1050 <read_bit@plt>
mov    %al,-0xd(%rbp)
movslq -0xc(%rbp),%rax
movzbl -0x8(%rbp,%rax,1),%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0xd(%rbp),%edi
call   1040 <print_bits@plt>
lea    0xe97(%rip),%rdi
lea    0xe93(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114f <main+0x1f>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1060 <read_bit@plt>
mov    %eax,%ebx
lea    0xeac(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %bl,%edi
call   1050 <print_bits@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xff,%edi
call   1060 <read_bit@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    $0xff,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %bl,%edi
call   1050 <print_bits@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x70,%edi
call   1060 <read_bit@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    $0x70,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %bl,%edi
call   1050 <print_bits@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x50,%edi
call   1060 <read_bit@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    $0x50,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %bl,%edi
call   1050 <print_bits@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.register_val = [4 x i8] c"\00\FFpP"
@.str = [40 x i8] c"When register is 0x%02x, the result is \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i8]
%3 = alloca i32
%4 = alloca i8
store i32 0, i32* %1
%5 = bitcast [4 x i8]* %2 to i8*
store i32 0, i32* %3
br label %6
6: ; preds = %25, %0
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = icmp ult i64 %8, 4
br i1 %9, label %10, label %28
10: ; preds = %6
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = call zeroext i8 @read_bit(i8 zeroext %14)
store i8 %15, i8* %4
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i8, i8* %4
%23 = call i32 @print_bits(i8 zeroext %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %10
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %6
28: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str = [40 x i8] c"When register is 0x%02x, the result is \00"
define i32 @main() {
%1 = tail call zeroext i8 @read_bit(i8 zeroext 0)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 0)
%3 = tail call i32 @print_bits(i8 zeroext %1)
%4 = tail call i32 @putchar(i32 10)
%5 = tail call zeroext i8 @read_bit(i8 zeroext -1)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 255)
%7 = tail call i32 @print_bits(i8 zeroext %5)
%8 = tail call i32 @putchar(i32 10)
%9 = tail call zeroext i8 @read_bit(i8 zeroext 112)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 112)
%11 = tail call i32 @print_bits(i8 zeroext %9)
%12 = tail call i32 @putchar(i32 10)
%13 = tail call zeroext i8 @read_bit(i8 zeroext 80)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 80)
%15 = tail call i32 @print_bits(i8 zeroext %13)
%16 = tail call i32 @putchar(i32 10)
ret i32 0
}