#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*/ _IONBF;
char get_channel_state(int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ switch_channel(int, int);
int main(int argc, char **argv) {
  setvbuf(stdout, NULL, _IONBF, 0);
  uint8_t i2caddress = 0x70;
  uint8_t channel = 4;
  switch_channel(i2caddress, channel);
  char state = get_channel_state(i2caddress, channel);
  if (state == 1) {
    printf("%d\n", state);
    printf("I2C switch set to channel %d \n", channel);
  } else {
    printf("Failed to change I2C switch to channel %d \n", channel);
  }
  (void)argc;
  (void)argv;
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1050 <setvbuf@plt>
movl   $0x70,-0x14(%rbp)
movl   $0x4,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1060 <switch_channel@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <get_channel_state@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x1,%eax
jne    11cb <main+0x8b>
movsbl -0x19(%rbp),%esi
lea    0xe4e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
jmp    11da <main+0x9a>
mov    -0x18(%rbp),%esi
lea    0xe4e(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
mov    0x2e97(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1050 <setvbuf@plt>
mov    $0x70,%edi
mov    $0x4,%esi
call   1060 <switch_channel@plt>
mov    $0x70,%edi
mov    $0x4,%esi
call   1030 <get_channel_state@plt>
cmp    $0x1,%al
jne    1198 <main+0x58>
lea    0xe7b(%rip),%rdi
mov    $0x1,%esi
call   1040 <printf@plt>
lea    0xe6e(%rip),%rdi
jmp    119f <main+0x5f>
lea    0xe84(%rip),%rdi
mov    $0x4,%esi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [31 x i8] c"I2C switch set to channel %d \0A\00"
@.str.2 = [44 x i8] c"Failed to change I2C switch to channel %d \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @stdout
%10 = load i32, i32* @_IONBF
%11 = call i32 @setvbuf(i32 %9, i32* null, i32 %10, i32 0)
store i32 112, i32* %6
store i32 4, i32* %7
%12 = load i32, i32* %6
%13 = load i32, i32* %7
%14 = call i32 @switch_channel(i32 %12, i32 %13)
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = call signext i8 @get_channel_state(i32 %15, i32 %16)
store i8 %17, i8* %8
%18 = load i8, i8* %8
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %27
21: ; preds = %2
%22 = load i8, i8* %8
%23 = sext i8 %22 to i32
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %7
%26 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %30
27: ; preds = %2
%28 = load i32, i32* %7
%29 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %27, %21
%31 = load i32, i32* %4
%32 = load i8**, i8*** %5
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [31 x i8] c"I2C switch set to channel %d \0A\00"
@.str.2 = [44 x i8] c"Failed to change I2C switch to channel %d \0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @stdout
%4 = load i32, i32* @_IONBF
%5 = tail call i32 @setvbuf(i32 %3, i32* null, i32 %4, i32 0)
%6 = tail call i32 @switch_channel(i32 112, i32 4)
%7 = tail call signext i8 @get_channel_state(i32 112, i32 4)
%8 = icmp eq i8 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 1)
br label %11
11: ; preds = %2, %9
%12 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), %9 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), %2 ]
%13 = tail call i32 @printf(i8* %12, i32 4)
ret i32 0
}