#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;

/* Variables and functions */
int checkbit(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read_byte_data(int, int);
uint8_t get_pin(uint8_t address, uint8_t pin, uint8_t a_register,
                uint8_t b_register) {
  uint8_t value = 0;
  if (pin >= 1 && pin <= 8) {
    value = checkbit(read_byte_data(address, a_register), pin - 1);
  } else if (pin >= 9 && pin <= 16) {
    value = checkbit(read_byte_data(address, b_register), pin - 9);
  } else {
    printf("pin out of range: 1 to 16");
  }
  return value;
}


x86 assembly (clang, -O0):
<get_pin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jl     117f <get_pin+0x4f>
cmpl   $0x8,-0x8(%rbp)
jg     117f <get_pin+0x4f>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <read_byte_data@plt>
mov    %eax,%edi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1050 <checkbit@plt>
mov    %eax,-0x14(%rbp)
jmp    11c4 <get_pin+0x94>
cmpl   $0x9,-0x8(%rbp)
jl     11b3 <get_pin+0x83>
cmpl   $0x10,-0x8(%rbp)
jg     11b3 <get_pin+0x83>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <read_byte_data@plt>
mov    %eax,%edi
mov    -0x8(%rbp),%esi
sub    $0x9,%esi
call   1050 <checkbit@plt>
mov    %eax,-0x14(%rbp)
jmp    11bf <get_pin+0x8f>
lea    0xe46(%rip),%rdi
call   1040 <printf@plt>
jmp    11c4 <get_pin+0x94>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_pin>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
lea    -0x1(%rbx),%ebp
cmp    $0x7,%ebp
ja     114a <get_pin+0x1a>
mov    %edx,%esi
call   1030 <read_byte_data@plt>
mov    %eax,%edi
mov    %ebp,%esi
jmp    115d <get_pin+0x2d>
add    $0xfffffff7,%ebx
cmp    $0x7,%ebx
ja     1168 <get_pin+0x38>
mov    %ecx,%esi
call   1030 <read_byte_data@plt>
mov    %eax,%edi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <checkbit@plt>
lea    0xe91(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"pin out of range: 1 to 16\00"
define i32 @get_pin(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
%10 = load i32, i32* %6
%11 = icmp sge i32 %10, 1
br i1 %11, label %12, label %22
12: ; preds = %4
%13 = load i32, i32* %6
%14 = icmp sle i32 %13, 8
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i32, i32* %5
%17 = load i32, i32* %7
%18 = call i32 @read_byte_data(i32 %16, i32 %17)
%19 = load i32, i32* %6
%20 = sub nsw i32 %19, 1
%21 = call i32 @checkbit(i32 %18, i32 %20)
store i32 %21, i32* %9
br label %38
22: ; preds = %12, %4
%23 = load i32, i32* %6
%24 = icmp sge i32 %23, 9
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = load i32, i32* %6
%27 = icmp sle i32 %26, 16
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = load i32, i32* %5
%30 = load i32, i32* %8
%31 = call i32 @read_byte_data(i32 %29, i32 %30)
%32 = load i32, i32* %6
%33 = sub nsw i32 %32, 9
%34 = call i32 @checkbit(i32 %31, i32 %33)
store i32 %34, i32* %9
br label %37
35: ; preds = %25, %22
%36 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %35, %28
br label %38
38: ; preds = %37, %15
%39 = load i32, i32* %9
ret i32 %39
}

LLVM IR (-O2):
@.str = [26 x i8] c"pin out of range: 1 to 16\00"
define i32 @get_pin(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = add i32 %1, -1
%6 = icmp ult i32 %5, 8
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i32 @read_byte_data(i32 %0, i32 %2)
%9 = tail call i32 @checkbit(i32 %8, i32 %5)
br label %18
10: ; preds = %4
%11 = add i32 %1, -9
%12 = icmp ult i32 %11, 8
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = tail call i32 @read_byte_data(i32 %0, i32 %3)
%15 = tail call i32 @checkbit(i32 %14, i32 %11)
br label %18
16: ; preds = %10
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %13, %16, %7
%19 = phi i32 [ %9, %7 ], [ %15, %13 ], [ 0, %16 ]
ret i32 %19
}