#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 /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read_byte_data(int, int);
int updatebyte(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ write_byte_data(int, int, int);
void set_pin(uint8_t address, uint8_t pin, uint8_t value, uint8_t a_register,
             uint8_t b_register) {
  uint8_t reg = 0;
  uint8_t p = 0;
  if (pin >= 1 && pin <= 8) {
    reg = a_register;
    p = pin - 1;
  } else if (pin >= 9 && pin <= 16) {
    reg = b_register;
    p = pin - 9;
  } else {
    printf("pin out of range: 1 to 16");
  }
  if (value > 1) {
    printf("value out of range: 0 or 1");
  }
  uint8_t newval = updatebyte(read_byte_data(address, reg), p, value);
  write_byte_data(address, reg, newval);
}


x86 assembly (clang, -O0):
<set_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)
mov    %r8d,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jl     118e <set_pin+0x4e>
cmpl   $0x8,-0x8(%rbp)
jg     118e <set_pin+0x4e>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c7 <set_pin+0x87>
cmpl   $0x9,-0x8(%rbp)
jl     11b6 <set_pin+0x76>
cmpl   $0x10,-0x8(%rbp)
jg     11b6 <set_pin+0x76>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x9,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c2 <set_pin+0x82>
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
jmp    11c7 <set_pin+0x87>
cmpl   $0x1,-0xc(%rbp)
jle    11dd <set_pin+0x9d>
lea    0xe42(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <read_byte_data@plt>
mov    %eax,%edi
mov    -0x1c(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1060 <updatebyte@plt>
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1050 <write_byte_data@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_pin>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,%r15d
mov    %edi,%r14d
lea    -0x1(%rsi),%ebp
cmp    $0x8,%ebp
jb     1174 <set_pin+0x34>
add    $0xfffffff7,%esi
mov    %esi,%ebp
mov    %r8d,%ebx
cmp    $0x8,%esi
jb     1174 <set_pin+0x34>
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
xor    %ebp,%ebp
xor    %ebx,%ebx
cmp    $0x2,%r15d
jl     1186 <set_pin+0x46>
lea    0xe99(%rip),%rdi
call   1040 <printf@plt>
mov    %r14d,%edi
mov    %ebx,%esi
call   1030 <read_byte_data@plt>
mov    %eax,%edi
mov    %ebp,%esi
mov    %r15d,%edx
call   1060 <updatebyte@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <write_byte_data@plt>

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

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