#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 /*<<< orphan*/ send_start_sequence();
int /*<<< orphan*/ send_stop_sequence();
int /*<<< orphan*/ write_byte(int);
void write_byte_to_slave(int slave_address, int register_address,
                         int data_byte) {
  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();
      write_byte(data_byte);
      acknowledge = check_ACK();
      if (acknowledge == 0) {
        error_routine();
      } else {
        fin_routine();
        send_stop_sequence();
      }
    }
  }
}


x86 assembly (clang, -O0):
<write_byte_to_slave>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1070 <send_start_sequence@plt>
mov    -0x4(%rbp),%edi
shl    $0x1,%edi
call   1090 <write_byte@plt>
mov    $0x0,%al
call   1080 <check_ACK@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11ba <write_byte_to_slave+0x4a>
mov    $0x0,%al
call   1030 <error_routine@plt>
jmp    1230 <write_byte_to_slave+0xc0>
mov    $0x0,%al
call   1060 <acknowledge_routine@plt>
mov    -0x8(%rbp),%edi
call   1090 <write_byte@plt>
mov    $0x0,%al
call   1080 <check_ACK@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11e9 <write_byte_to_slave+0x79>
mov    $0x0,%al
call   1030 <error_routine@plt>
jmp    122b <write_byte_to_slave+0xbb>
mov    $0x0,%al
call   1060 <acknowledge_routine@plt>
mov    -0xc(%rbp),%edi
call   1090 <write_byte@plt>
mov    $0x0,%al
call   1080 <check_ACK@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1218 <write_byte_to_slave+0xa8>
mov    $0x0,%al
call   1030 <error_routine@plt>
jmp    1226 <write_byte_to_slave+0xb6>
mov    $0x0,%al
call   1040 <fin_routine@plt>
mov    $0x0,%al
call   1050 <send_stop_sequence@plt>
jmp    122b <write_byte_to_slave+0xbb>
jmp    1230 <write_byte_to_slave+0xc0>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_byte_to_slave>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
xor    %eax,%eax
call   1070 <send_start_sequence@plt>
add    %ebx,%ebx
mov    %ebx,%edi
call   1090 <write_byte@plt>
xor    %eax,%eax
call   1080 <check_ACK@plt>
test   %eax,%eax
je     11db <write_byte_to_slave+0x6b>
xor    %eax,%eax
call   1060 <acknowledge_routine@plt>
mov    %ebp,%edi
call   1090 <write_byte@plt>
xor    %eax,%eax
call   1080 <check_ACK@plt>
test   %eax,%eax
je     11db <write_byte_to_slave+0x6b>
xor    %eax,%eax
call   1060 <acknowledge_routine@plt>
mov    %r14d,%edi
call   1090 <write_byte@plt>
xor    %eax,%eax
call   1080 <check_ACK@plt>
test   %eax,%eax
je     11db <write_byte_to_slave+0x6b>
xor    %eax,%eax
call   1040 <fin_routine@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <send_stop_sequence@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <error_routine@plt>

LLVM IR (-O0):
define void @write_byte_to_slave(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%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* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 (...) @error_routine()
br label %40
17: ; preds = %3
%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* %7
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = call i32 (...) @error_routine()
br label %39
26: ; preds = %17
%27 = call i32 (...) @acknowledge_routine()
%28 = load i32, i32* %6
%29 = call i32 @write_byte(i32 %28)
%30 = call i32 (...) @check_ACK()
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 (...) @error_routine()
br label %38
35: ; preds = %26
%36 = call i32 (...) @fin_routine()
%37 = call i32 (...) @send_stop_sequence()
br label %38
38: ; preds = %35, %33
br label %39
39: ; preds = %38, %24
br label %40
40: ; preds = %39, %15
ret void
}

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