#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 pin, uint8_t a_register, uint8_t b_register) {
  uint8_t value = 0;
  if (pin >= 1 && pin <= 8) {
    value = checkbit(read_byte_data(0x20, a_register), pin - 1);
  } else if (pin >= 9 && pin <= 16) {
    value = checkbit(read_byte_data(0x20, 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    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x1,-0x4(%rbp)
jl     117e <get_pin+0x4e>
cmpl   $0x8,-0x4(%rbp)
jg     117e <get_pin+0x4e>
mov    -0x8(%rbp),%esi
mov    $0x20,%edi
call   1030 <read_byte_data@plt>
mov    %eax,%edi
mov    -0x4(%rbp),%esi
sub    $0x1,%esi
call   1050 <checkbit@plt>
mov    %eax,-0x10(%rbp)
jmp    11c5 <get_pin+0x95>
cmpl   $0x9,-0x4(%rbp)
jl     11b4 <get_pin+0x84>
cmpl   $0x10,-0x4(%rbp)
jg     11b4 <get_pin+0x84>
mov    -0xc(%rbp),%esi
mov    $0x20,%edi
call   1030 <read_byte_data@plt>
mov    %eax,%edi
mov    -0x4(%rbp),%esi
sub    $0x9,%esi
call   1050 <checkbit@plt>
mov    %eax,-0x10(%rbp)
jmp    11c0 <get_pin+0x90>
lea    0xe45(%rip),%rdi
call   1040 <printf@plt>
jmp    11c5 <get_pin+0x95>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_pin>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
lea    -0x1(%rbx),%ebp
cmp    $0x7,%ebp
ja     114d <get_pin+0x1d>
mov    $0x20,%edi
call   1030 <read_byte_data@plt>
mov    %eax,%edi
mov    %ebp,%esi
jmp    1165 <get_pin+0x35>
add    $0xfffffff7,%ebx
cmp    $0x7,%ebx
ja     1170 <get_pin+0x40>
mov    $0x20,%edi
mov    %edx,%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    0xe89(%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) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = icmp sge i32 %8, 1
br i1 %9, label %10, label %19
10: ; preds = %3
%11 = load i32, i32* %4
%12 = icmp sle i32 %11, 8
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i32, i32* %5
%15 = call i32 @read_byte_data(i32 32, i32 %14)
%16 = load i32, i32* %4
%17 = sub nsw i32 %16, 1
%18 = call i32 @checkbit(i32 %15, i32 %17)
store i32 %18, i32* %7
br label %34
19: ; preds = %10, %3
%20 = load i32, i32* %4
%21 = icmp sge i32 %20, 9
br i1 %21, label %22, label %31
22: ; preds = %19
%23 = load i32, i32* %4
%24 = icmp sle i32 %23, 16
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i32, i32* %6
%27 = call i32 @read_byte_data(i32 32, i32 %26)
%28 = load i32, i32* %4
%29 = sub nsw i32 %28, 9
%30 = call i32 @checkbit(i32 %27, i32 %29)
store i32 %30, i32* %7
br label %33
31: ; preds = %22, %19
%32 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %31, %25
br label %34
34: ; preds = %33, %13
%35 = load i32, i32* %7
ret i32 %35
}

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) {
%4 = add i32 %0, -1
%5 = icmp ult i32 %4, 8
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @read_byte_data(i32 32, i32 %1)
%8 = tail call i32 @checkbit(i32 %7, i32 %4)
br label %17
9: ; preds = %3
%10 = add i32 %0, -9
%11 = icmp ult i32 %10, 8
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i32 @read_byte_data(i32 32, i32 %2)
%14 = tail call i32 @checkbit(i32 %13, i32 %10)
br label %17
15: ; preds = %9
%16 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %12, %15, %6
%18 = phi i32 [ %8, %6 ], [ %14, %12 ], [ 0, %15 ]
ret i32 %18
}