#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 */

/* Variables and functions */
int /*<<< orphan*/ acknowledge_routine();
int check_ACK();
int /*<<< orphan*/ error_routine();
int /*<<< orphan*/ fin_routine();
int read_byte();
int /*<<< orphan*/ send_start_sequence();
int /*<<< orphan*/ send_stop_sequence();
int /*<<< orphan*/ write_byte(int);
int read_byte_from_slave(int slave_address, int register_address) {
  int acknowledge = 0;
  send_start_sequence();
  write_byte((slave_address) << 1);
  acknowledge = check_ACK();
  if (acknowledge == 0) {
    error_routine();
  } else {
    acknowledge_routine();
    write_byte(register_address);
    acknowledge = check_ACK();
    if (acknowledge == 0) {
      error_routine();
    } else {
      acknowledge_routine();
      send_start_sequence();
      write_byte(((slave_address) << 1) | 1);
      acknowledge = check_ACK();
      if (acknowledge == 0) {
        error_routine();
      } else {
        acknowledge_routine();
        int data = read_byte();
        fin_routine();
        send_stop_sequence();
        return data;
      }
    }
  }
}


x86 assembly (clang, -O0):
<read_byte_from_slave>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1080 <send_start_sequence@plt>
mov    -0x8(%rbp),%edi
shl    $0x1,%edi
call   10a0 <write_byte@plt>
mov    $0x0,%al
call   1090 <check_ACK@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11c7 <read_byte_from_slave+0x47>
mov    $0x0,%al
call   1040 <error_routine@plt>
jmp    1266 <read_byte_from_slave+0xe6>
mov    $0x0,%al
call   1070 <acknowledge_routine@plt>
mov    -0xc(%rbp),%edi
call   10a0 <write_byte@plt>
mov    $0x0,%al
call   1090 <check_ACK@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11f6 <read_byte_from_slave+0x76>
mov    $0x0,%al
call   1040 <error_routine@plt>
jmp    1261 <read_byte_from_slave+0xe1>
mov    $0x0,%al
call   1070 <acknowledge_routine@plt>
mov    $0x0,%al
call   1080 <send_start_sequence@plt>
mov    -0x8(%rbp),%edi
shl    $0x1,%edi
or     $0x1,%edi
call   10a0 <write_byte@plt>
mov    $0x0,%al
call   1090 <check_ACK@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1232 <read_byte_from_slave+0xb2>
mov    $0x0,%al
call   1040 <error_routine@plt>
jmp    125c <read_byte_from_slave+0xdc>
mov    $0x0,%al
call   1070 <acknowledge_routine@plt>
mov    $0x0,%al
call   1030 <read_byte@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1050 <fin_routine@plt>
mov    $0x0,%al
call   1060 <send_stop_sequence@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1266 <read_byte_from_slave+0xe6>
jmp    1261 <read_byte_from_slave+0xe1>
jmp    1266 <read_byte_from_slave+0xe6>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_byte_from_slave>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
xor    %eax,%eax
call   1080 <send_start_sequence@plt>
add    %ebx,%ebx
mov    %ebx,%edi
call   10a0 <write_byte@plt>
xor    %eax,%eax
call   1090 <check_ACK@plt>
test   %eax,%eax
je     1200 <read_byte_from_slave+0x80>
xor    %eax,%eax
call   1070 <acknowledge_routine@plt>
mov    %ebp,%edi
call   10a0 <write_byte@plt>
xor    %eax,%eax
call   1090 <check_ACK@plt>
test   %eax,%eax
je     1200 <read_byte_from_slave+0x80>
xor    %eax,%eax
call   1070 <acknowledge_routine@plt>
xor    %eax,%eax
call   1080 <send_start_sequence@plt>
or     $0x1,%ebx
mov    %ebx,%edi
call   10a0 <write_byte@plt>
xor    %eax,%eax
call   1090 <check_ACK@plt>
test   %eax,%eax
je     1200 <read_byte_from_slave+0x80>
xor    %eax,%eax
call   1070 <acknowledge_routine@plt>
xor    %eax,%eax
call   1030 <read_byte@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <fin_routine@plt>
xor    %eax,%eax
call   1060 <send_stop_sequence@plt>
mov    %ebx,%eax
jmp    1207 <read_byte_from_slave+0x87>
xor    %eax,%eax
call   1040 <error_routine@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_byte_from_slave(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %6
%8 = call i32 (...) @send_start_sequence()
%9 = load i32, i32* %4
%10 = shl i32 %9, 1
%11 = call i32 @write_byte(i32 %10)
%12 = call i32 (...) @check_ACK()
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (...) @error_routine()
br label %46
17: ; preds = %2
%18 = call i32 (...) @acknowledge_routine()
%19 = load i32, i32* %5
%20 = call i32 @write_byte(i32 %19)
%21 = call i32 (...) @check_ACK()
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = call i32 (...) @error_routine()
br label %45
26: ; preds = %17
%27 = call i32 (...) @acknowledge_routine()
%28 = call i32 (...) @send_start_sequence()
%29 = load i32, i32* %4
%30 = shl i32 %29, 1
%31 = or i32 %30, 1
%32 = call i32 @write_byte(i32 %31)
%33 = call i32 (...) @check_ACK()
store i32 %33, i32* %6
%34 = load i32, i32* %6
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %26
%37 = call i32 (...) @error_routine()
br label %44
38: ; preds = %26
%39 = call i32 (...) @acknowledge_routine()
%40 = call i32 (...) @read_byte()
store i32 %40, i32* %7
%41 = call i32 (...) @fin_routine()
%42 = call i32 (...) @send_stop_sequence()
%43 = load i32, i32* %7
store i32 %43, i32* %3
br label %46
44: ; preds = %36
br label %45
45: ; preds = %44, %24
br label %46
46: ; preds = %38, %45, %15
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
define i32 @read_byte_from_slave(i32 %0, i32 %1) {
%3 = tail call i32 (...) @send_start_sequence()
%4 = shl i32 %0, 1
%5 = tail call i32 @write_byte(i32 %4)
%6 = tail call i32 (...) @check_ACK()
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 (...) @error_routine()
br label %31
10: ; preds = %2
%11 = tail call i32 (...) @acknowledge_routine()
%12 = tail call i32 @write_byte(i32 %1)
%13 = tail call i32 (...) @check_ACK()
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i32 (...) @error_routine()
br label %31
17: ; preds = %10
%18 = tail call i32 (...) @acknowledge_routine()
%19 = tail call i32 (...) @send_start_sequence()
%20 = or i32 %4, 1
%21 = tail call i32 @write_byte(i32 %20)
%22 = tail call i32 (...) @check_ACK()
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = tail call i32 (...) @error_routine()
br label %31
26: ; preds = %17
%27 = tail call i32 (...) @acknowledge_routine()
%28 = tail call i32 (...) @read_byte()
%29 = tail call i32 (...) @fin_routine()
%30 = tail call i32 (...) @send_stop_sequence()
br label %31
31: ; preds = %8, %24, %15, %26
%32 = phi i32 [ %28, %26 ], [ undef, %15 ], [ undef, %24 ], [ undef, %8 ]
ret i32 %32
}