#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 */
char checkbit(char, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char read_byte_data(int);
int /*<<< orphan*/ stderr;
char get_channel_state(uint8_t address, uint8_t channel) {
  if (address < 0x70 || address > 0x77) {
    fprintf(stderr, "I2C address out of range. 0x70 - 0x77\n");
    return (-1);
  }
  if (channel < 1 || channel > 4) {
    fprintf(stderr, "channel out of range. 1 - 4\n");
    return (-1);
  }
  char cval = read_byte_data(address);
  return (checkbit(cval, channel - 1));
}


x86 assembly (clang, -O0):
<get_channel_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x70,-0x8(%rbp)
jl     1152 <get_channel_state+0x22>
cmpl   $0x77,-0x8(%rbp)
jle    1170 <get_channel_state+0x40>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
lea    0xe9e(%rip),%rsi
call   1040 <fprintf@plt>
movb   $0xff,-0x1(%rbp)
jmp    11c1 <get_channel_state+0x91>
cmpl   $0x1,-0xc(%rbp)
jl     1184 <get_channel_state+0x54>
cmpl   $0x4,-0xc(%rbp)
jle    11a2 <get_channel_state+0x72>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe93(%rip),%rsi
call   1040 <fprintf@plt>
movb   $0xff,-0x1(%rbp)
jmp    11c1 <get_channel_state+0x91>
mov    -0x8(%rbp),%edi
call   1030 <read_byte_data@plt>
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
movsbl %al,%edi
call   1050 <checkbit@plt>
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_channel_state>:
push   %rbx
lea    -0x78(%rdi),%eax
cmp    $0xfffffff7,%eax
ja     114b <get_channel_state+0x1b>
mov    0x2ea0(%rip),%rax
mov    (%rax),%edi
lea    0xeb7(%rip),%rsi
jmp    1165 <get_channel_state+0x35>
mov    %esi,%ebx
lea    -0x5(%rbx),%eax
cmp    $0xfffffffb,%eax
ja     116e <get_channel_state+0x3e>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
lea    0xec2(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xff,%al
pop    %rbx
ret
call   1030 <read_byte_data@plt>
add    $0xffffffff,%ebx
movsbl %al,%edi
mov    %ebx,%esi
pop    %rbx
jmp    1050 <checkbit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"I2C address out of range. 0x70 - 0x77\0A\00"
@.str.1 = [29 x i8] c"channel out of range. 1 - 4\0A\00"
define signext i8 @get_channel_state(i32 %0, i32 %1) {
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 112
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 119
br i1 %11, label %12, label %15
12: ; preds = %9, %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i8 -1, i8* %3
br label %31
15: ; preds = %9
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 1
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* %5
%20 = icmp sgt i32 %19, 4
br i1 %20, label %21, label %24
21: ; preds = %18, %15
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i8 -1, i8* %3
br label %31
24: ; preds = %18
%25 = load i32, i32* %4
%26 = call signext i8 @read_byte_data(i32 %25)
store i8 %26, i8* %6
%27 = load i8, i8* %6
%28 = load i32, i32* %5
%29 = sub nsw i32 %28, 1
%30 = call signext i8 @checkbit(i8 signext %27, i32 %29)
store i8 %30, i8* %3
br label %31
31: ; preds = %24, %21, %12
%32 = load i8, i8* %3
ret i8 %32
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"I2C address out of range. 0x70 - 0x77\0A\00"
@.str.1 = [29 x i8] c"channel out of range. 1 - 4\0A\00"
define signext i8 @get_channel_state(i32 %0, i32 %1) {
%3 = add i32 %0, -120
%4 = icmp ult i32 %3, -8
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %18
8: ; preds = %2
%9 = add i32 %1, -5
%10 = icmp ult i32 %9, -4
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %18
14: ; preds = %8
%15 = tail call signext i8 @read_byte_data(i32 %0)
%16 = add nsw i32 %1, -1
%17 = tail call signext i8 @checkbit(i8 signext %15, i32 %16)
br label %18
18: ; preds = %14, %11, %5
%19 = phi i8 [ -1, %5 ], [ -1, %11 ], [ %17, %14 ]
ret i8 %19
}