#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 */
char i2c_check_ack();
int /*<<< orphan*/ i2c_send_raw_data(char);
int /*<<< orphan*/ i2c_send_slave_adrs(char, int /*<<< orphan*/);
int /*<<< orphan*/ i2c_start_cond();
int /*<<< orphan*/ i2c_stop_cond();
int i2c_send_byte_2(char slave_adrs, char ctrl_byte, char cmddat_byte) {
  char d;
  int status;
  i2c_start_cond();
  i2c_send_slave_adrs(slave_adrs, 0);
  d = i2c_check_ack();
  if (d != 0) {
    status = -1;
    goto I2C_SEND_BYTE_2_RETURN;
  }
  i2c_send_raw_data(ctrl_byte);
  d = i2c_check_ack();
  if (d != 0) {
    status = -2;
    goto I2C_SEND_BYTE_2_RETURN;
  }
  i2c_send_raw_data(cmddat_byte);
  d = i2c_check_ack();
  if (d != 0) {
    status = -3;
    goto I2C_SEND_BYTE_2_RETURN;
  }
  status = 0;
I2C_SEND_BYTE_2_RETURN:
  i2c_stop_cond();
  return status;
}


x86 assembly (clang, -O0):
<i2c_send_byte_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %dil,%dl
mov    %dl,-0x1(%rbp)
mov    %cl,-0x2(%rbp)
mov    %al,-0x3(%rbp)
mov    $0x0,%al
call   1030 <i2c_start_cond@plt>
xor    %esi,%esi
movsbl -0x1(%rbp),%edi
call   1050 <i2c_send_slave_adrs@plt>
mov    $0x0,%al
call   1060 <i2c_check_ack@plt>
mov    %al,-0x4(%rbp)
movsbl -0x4(%rbp),%eax
cmp    $0x0,%eax
je     119e <i2c_send_byte_2+0x4e>
movl   $0xffffffff,-0x8(%rbp)
jmp    11fd <i2c_send_byte_2+0xad>
movsbl -0x2(%rbp),%edi
call   1070 <i2c_send_raw_data@plt>
mov    $0x0,%al
call   1060 <i2c_check_ack@plt>
mov    %al,-0x4(%rbp)
movsbl -0x4(%rbp),%eax
cmp    $0x0,%eax
je     11ca <i2c_send_byte_2+0x7a>
movl   $0xfffffffe,-0x8(%rbp)
jmp    11fd <i2c_send_byte_2+0xad>
movsbl -0x3(%rbp),%edi
call   1070 <i2c_send_raw_data@plt>
mov    $0x0,%al
call   1060 <i2c_check_ack@plt>
mov    %al,-0x4(%rbp)
movsbl -0x4(%rbp),%eax
cmp    $0x0,%eax
je     11f6 <i2c_send_byte_2+0xa6>
movl   $0xfffffffd,-0x8(%rbp)
jmp    11fd <i2c_send_byte_2+0xad>
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <i2c_stop_cond@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2c_send_byte_2>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <i2c_start_cond@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <i2c_send_slave_adrs@plt>
xor    %eax,%eax
call   1060 <i2c_check_ack@plt>
mov    $0xffffffff,%ebx
test   %al,%al
jne    11b1 <i2c_send_byte_2+0x61>
movsbl %bpl,%edi
call   1070 <i2c_send_raw_data@plt>
xor    %eax,%eax
call   1060 <i2c_check_ack@plt>
mov    $0xfffffffe,%ebx
test   %al,%al
jne    11b1 <i2c_send_byte_2+0x61>
movsbl %r14b,%edi
call   1070 <i2c_send_raw_data@plt>
xor    %eax,%eax
call   1060 <i2c_check_ack@plt>
xor    %ecx,%ecx
test   %al,%al
sete   %cl
lea    (%rcx,%rcx,2),%ebx
add    $0xfffffffd,%ebx
xor    %eax,%eax
call   1040 <i2c_stop_cond@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @i2c_send_byte_2(i8 signext %0, i8 signext %1, i8 signext %2) {
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca i32
store i8 %0, i8* %4
store i8 %1, i8* %5
store i8 %2, i8* %6
%9 = call i32 (...) @i2c_start_cond()
%10 = load i8, i8* %4
%11 = call i32 @i2c_send_slave_adrs(i8 signext %10, i32 0)
%12 = call signext i8 (...) @i2c_check_ack()
store i8 %12, i8* %7
%13 = load i8, i8* %7
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 -1, i32* %8
br label %34
17: ; preds = %3
%18 = load i8, i8* %5
%19 = call i32 @i2c_send_raw_data(i8 signext %18)
%20 = call signext i8 (...) @i2c_check_ack()
store i8 %20, i8* %7
%21 = load i8, i8* %7
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %17
store i32 -2, i32* %8
br label %34
25: ; preds = %17
%26 = load i8, i8* %6
%27 = call i32 @i2c_send_raw_data(i8 signext %26)
%28 = call signext i8 (...) @i2c_check_ack()
store i8 %28, i8* %7
%29 = load i8, i8* %7
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %25
store i32 -3, i32* %8
br label %34
33: ; preds = %25
store i32 0, i32* %8
br label %34
34: ; preds = %33, %32, %24, %16
%35 = call i32 (...) @i2c_stop_cond()
%36 = load i32, i32* %8
ret i32 %36
}

LLVM IR (-O2):
define i32 @i2c_send_byte_2(i8 signext %0, i8 signext %1, i8 signext %2) {
%4 = tail call i32 (...) @i2c_start_cond()
%5 = tail call i32 @i2c_send_slave_adrs(i8 signext %0, i32 0)
%6 = tail call signext i8 (...) @i2c_check_ack()
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %3
%9 = tail call i32 @i2c_send_raw_data(i8 signext %1)
%10 = tail call signext i8 (...) @i2c_check_ack()
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = tail call i32 @i2c_send_raw_data(i8 signext %2)
%14 = tail call signext i8 (...) @i2c_check_ack()
%15 = icmp eq i8 %14, 0
%16 = select i1 %15, i32 0, i32 -3
br label %17
17: ; preds = %12, %8, %3
%18 = phi i32 [ -1, %3 ], [ -2, %8 ], [ %16, %12 ]
%19 = tail call i32 (...) @i2c_stop_cond()
ret i32 %18
}