#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
char updatebyte(char, int, int);
int /*<<< orphan*/ write_byte_data(int, char);
char switch_channel(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 = 0;
  cval = updatebyte(cval, channel - 1, 1);
  write_byte_data(address, cval);
  return (0);
}


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

x86 assembly (clang, -O2):
<switch_channel>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
lea    -0x78(%rbx),%eax
cmp    $0xfffffff7,%eax
ja     114f <switch_channel+0x1f>
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
lea    0xeb3(%rip),%rsi
jmp    1167 <switch_channel+0x37>
lea    -0x5(%rsi),%eax
cmp    $0xfffffffb,%eax
ja     1171 <switch_channel+0x41>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
lea    0xec0(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xff,%bpl
jmp    118c <switch_channel+0x5c>
add    $0xffffffff,%esi
xor    %ebp,%ebp
xor    %edi,%edi
mov    $0x1,%edx
call   1050 <updatebyte@plt>
movsbl %al,%esi
mov    %ebx,%edi
call   1040 <write_byte_data@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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 @switch_channel(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 %32
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 %32
24: ; preds = %18
store i8 0, i8* %6
%25 = load i8, i8* %6
%26 = load i32, i32* %5
%27 = sub nsw i32 %26, 1
%28 = call signext i8 @updatebyte(i8 signext %25, i32 %27, i32 1)
store i8 %28, i8* %6
%29 = load i32, i32* %4
%30 = load i8, i8* %6
%31 = call i32 @write_byte_data(i32 %29, i8 signext %30)
store i8 0, i8* %3
br label %32
32: ; preds = %24, %21, %12
%33 = load i8, i8* %3
ret i8 %33
}

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 @switch_channel(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 = add nsw i32 %1, -1
%16 = tail call signext i8 @updatebyte(i8 signext 0, i32 %15, i32 1)
%17 = tail call i32 @write_byte_data(i32 %0, i8 signext %16)
br label %18
18: ; preds = %14, %11, %5
%19 = phi i8 [ -1, %5 ], [ -1, %11 ], [ 0, %14 ]
ret i8 %19
}