#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 WaitForXfer(void *);
int /*<<< orphan*/ bbm_read(void *, int, unsigned char *);
int /*<<< orphan*/ bbm_write(void *, int, int);
int /*<<< orphan*/ print_log(void *, char *, int);
signed int fci_i2c_transfer(void *handle, unsigned char cmd_type,
                            unsigned char chip, unsigned char addr[],
                            unsigned char addr_len, unsigned char data[],
                            unsigned char data_len) {
  signed int i;
  signed int result = 0;
  switch (cmd_type) {
  case 0:
    bbm_write(handle, 0x0035, chip | cmd_type);
    bbm_write(handle, 0x0036, 0x80 | 0x10);
    result = WaitForXfer(handle);
    if (result != 0)
      return result;
    if (addr && addr_len) {
      i = 0;
      while ((i < addr_len) && (result == 0)) {
        bbm_write(handle, 0x0035, addr[i]);
        bbm_write(handle, 0x0036, 0x10);
        result = WaitForXfer(handle);
        if (result != 0)
          return result;
        i++;
      }
    }
    i = 0;
    while ((i < data_len) && (result == 0)) {
      bbm_write(handle, 0x0035, data[i]);
      bbm_write(handle, 0x0036, 0x10);
      result = WaitForXfer(handle);
      if (result != 0)
        return result;
      i++;
    }
    bbm_write(handle, 0x0036, 0x40);
    result = WaitForXfer(handle);
    if (result != 0)
      return result;
    break;
  case 1:
    if (addr && addr_len) {
      bbm_write(handle, 0x0035, chip | 0);
      bbm_write(handle, 0x0036, 0x80 | 0x10);
      result = WaitForXfer(handle);
      if (result != 0)
        return result;
      i = 0;
      while ((i < addr_len) && (result == 0)) {
        bbm_write(handle, 0x0035, addr[i]);
        bbm_write(handle, 0x0036, 0x10);
        result = WaitForXfer(handle);
        if (result != 0)
          return result;
        i++;
      }
    }
    bbm_write(handle, 0x0035, chip | 1);
    bbm_write(handle, 0x0036, 0x80 | 0x10);
    result = WaitForXfer(handle);
    if (result != 0)
      return result;
    i = 0;
    while ((i < data_len) && (result == 0)) {
      if (i == data_len - 1) {
        bbm_write(handle, 0x0036, 0x20 | 0x08);
        result = WaitForXfer(handle);
        if ((result != 2) && (result != 0)) {
          print_log(handle, "NACK4-0[%02x]\n", result);
          return result;
        }
      } else {
        bbm_write(handle, 0x0036, 0x20);
        result = WaitForXfer(handle);
        if (result != 0) {
          print_log(handle, "NACK4-1[%02x]\n", result);
          return result;
        }
      }
      bbm_read(handle, 0x0033, &data[i]);
      i++;
    }
    bbm_write(handle, 0x0036, 0x40);
    result = WaitForXfer(handle);
    if ((result != 2) && (result != 0)) {
      print_log(handle, "NACK5[%02X]\n", result);
      return result;
    }
    break;
  default:
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<fci_i2c_transfer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %r8b,%al
mov    0x10(%rbp),%r8b
mov    %rdi,-0x10(%rbp)
mov    %sil,-0x11(%rbp)
mov    %dl,-0x12(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %al,-0x21(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
movzbl -0x11(%rbp),%eax
mov    %eax,-0x3c(%rbp)
test   %eax,%eax
je     1191 <fci_i2c_transfer+0x51>
jmp    1180 <fci_i2c_transfer+0x40>
mov    -0x3c(%rbp),%eax
sub    $0x1,%eax
je     1355 <fci_i2c_transfer+0x215>
jmp    15fb <fci_i2c_transfer+0x4bb>
mov    -0x10(%rbp),%rdi
movzbl -0x12(%rbp),%edx
movzbl -0x11(%rbp),%eax
or     %eax,%edx
mov    $0x35,%esi
call   1050 <bbm_write@plt>
mov    -0x10(%rbp),%rdi
mov    $0x36,%esi
mov    $0x90,%edx
call   1050 <bbm_write@plt>
mov    -0x10(%rbp),%rdi
call   1040 <WaitForXfer@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     11dd <fci_i2c_transfer+0x9d>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    160e <fci_i2c_transfer+0x4ce>
cmpq   $0x0,-0x20(%rbp)
je     128b <fci_i2c_transfer+0x14b>
movzbl -0x21(%rbp),%eax
cmp    $0x0,%eax
je     128b <fci_i2c_transfer+0x14b>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%ecx
movzbl -0x21(%rbp),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x3d(%rbp)
jge    121a <fci_i2c_transfer+0xda>
cmpl   $0x0,-0x38(%rbp)
sete   %al
mov    %al,-0x3d(%rbp)
mov    -0x3d(%rbp),%al
test   $0x1,%al
jne    122a <fci_i2c_transfer+0xea>
jmp    1286 <fci_i2c_transfer+0x146>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
mov    $0x35,%esi
call   1050 <bbm_write@plt>
mov    -0x10(%rbp),%rdi
mov    $0x36,%esi
mov    $0x10,%edx
call   1050 <bbm_write@plt>
mov    -0x10(%rbp),%rdi
call   1040 <WaitForXfer@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     1278 <fci_i2c_transfer+0x138>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    160e <fci_i2c_transfer+0x4ce>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11fc <fci_i2c_transfer+0xbc>
jmp    128b <fci_i2c_transfer+0x14b>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%ecx
movzbl 0x10(%rbp),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x3e(%rbp)
jge    12b0 <fci_i2c_transfer+0x170>
cmpl   $0x0,-0x38(%rbp)
sete   %al
mov    %al,-0x3e(%rbp)
mov    -0x3e(%rbp),%al
test   $0x1,%al
jne    12c0 <fci_i2c_transfer+0x180>
jmp    131c <fci_i2c_transfer+0x1dc>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
mov    $0x35,%esi
call   1050 <bbm_write@plt>
mov    -0x10(%rbp),%rdi
mov    $0x36,%esi
mov    $0x10,%edx
call   1050 <bbm_write@plt>
mov    -0x10(%rbp),%rdi
call   1040 <WaitForXfer@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     130e <fci_i2c_transfer+0x1ce>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    160e <fci_i2c_transfer+0x4ce>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1292 <fci_i2c_transfer+0x152>
mov    -0x10(%rbp),%rdi
mov    $0x36,%esi
mov    $0x40,%edx
call   1050 <bbm_write@plt>
mov    -0x10(%rbp),%rdi
call   1040 <WaitForXfer@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     1350 <fci_i2c_transfer+0x210>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    160e <fci_i2c_transfer+0x4ce>
jmp    1607 <fci_i2c_transfer+0x4c7>
cmpq   $0x0,-0x20(%rbp)
je     144c <fci_i2c_transfer+0x30c>
movzbl -0x21(%rbp),%eax
cmp    $0x0,%eax
je     144c <fci_i2c_transfer+0x30c>
mov    -0x10(%rbp),%rdi
movzbl -0x12(%rbp),%edx
or     $0x0,%edx
mov    $0x35,%esi
call   1050 <bbm_write@plt>
mov    -0x10(%rbp),%rdi
mov    $0x36,%esi
mov    $0x90,%edx
call   1050 <bbm_write@plt>
mov    -0x10(%rbp),%rdi
call   1040 <WaitForXfer@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     13b6 <fci_i2c_transfer+0x276>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    160e <fci_i2c_transfer+0x4ce>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%ecx
movzbl -0x21(%rbp),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x3f(%rbp)
jge    13db <fci_i2c_transfer+0x29b>
cmpl   $0x0,-0x38(%rbp)
sete   %al
mov    %al,-0x3f(%rbp)
mov    -0x3f(%rbp),%al
test   $0x1,%al
jne    13eb <fci_i2c_transfer+0x2ab>
jmp    1447 <fci_i2c_transfer+0x307>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
mov    $0x35,%esi
call   1050 <bbm_write@plt>
mov    -0x10(%rbp),%rdi
mov    $0x36,%esi
mov    $0x10,%edx
call   1050 <bbm_write@plt>
mov    -0x10(%rbp),%rdi
call   1040 <WaitForXfer@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     1439 <fci_i2c_transfer+0x2f9>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    160e <fci_i2c_transfer+0x4ce>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    13bd <fci_i2c_transfer+0x27d>
jmp    144c <fci_i2c_transfer+0x30c>
mov    -0x10(%rbp),%rdi
movzbl -0x12(%rbp),%edx
or     $0x1,%edx
mov    $0x35,%esi
call   1050 <bbm_write@plt>
mov    -0x10(%rbp),%rdi
mov    $0x36,%esi
mov    $0x90,%edx
call   1050 <bbm_write@plt>
mov    -0x10(%rbp),%rdi
call   1040 <WaitForXfer@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     1495 <fci_i2c_transfer+0x355>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    160e <fci_i2c_transfer+0x4ce>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%ecx
movzbl 0x10(%rbp),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x40(%rbp)
jge    14ba <fci_i2c_transfer+0x37a>
cmpl   $0x0,-0x38(%rbp)
sete   %al
mov    %al,-0x40(%rbp)
mov    -0x40(%rbp),%al
test   $0x1,%al
jne    14ca <fci_i2c_transfer+0x38a>
jmp    15a5 <fci_i2c_transfer+0x465>
mov    -0x34(%rbp),%eax
movzbl 0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1532 <fci_i2c_transfer+0x3f2>
mov    -0x10(%rbp),%rdi
mov    $0x36,%esi
mov    $0x28,%edx
call   1050 <bbm_write@plt>
mov    -0x10(%rbp),%rdi
call   1040 <WaitForXfer@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x2,-0x38(%rbp)
je     152d <fci_i2c_transfer+0x3ed>
cmpl   $0x0,-0x38(%rbp)
je     152d <fci_i2c_transfer+0x3ed>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%edx
lea    0xae3(%rip),%rsi
call   1030 <print_log@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    160e <fci_i2c_transfer+0x4ce>
jmp    157e <fci_i2c_transfer+0x43e>
mov    -0x10(%rbp),%rdi
mov    $0x36,%esi
mov    $0x20,%edx
call   1050 <bbm_write@plt>
mov    -0x10(%rbp),%rdi
call   1040 <WaitForXfer@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     1579 <fci_i2c_transfer+0x439>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%edx
lea    0xaa6(%rip),%rsi
call   1030 <print_log@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    160e <fci_i2c_transfer+0x4ce>
jmp    157e <fci_i2c_transfer+0x43e>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rdx
movslq -0x34(%rbp),%rax
add    %rax,%rdx
mov    $0x33,%esi
call   1060 <bbm_read@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    149c <fci_i2c_transfer+0x35c>
mov    -0x10(%rbp),%rdi
mov    $0x36,%esi
mov    $0x40,%edx
call   1050 <bbm_write@plt>
mov    -0x10(%rbp),%rdi
call   1040 <WaitForXfer@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x2,-0x38(%rbp)
je     15f6 <fci_i2c_transfer+0x4b6>
cmpl   $0x0,-0x38(%rbp)
je     15f6 <fci_i2c_transfer+0x4b6>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%edx
lea    0xa38(%rip),%rsi
call   1030 <print_log@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    160e <fci_i2c_transfer+0x4ce>
jmp    1607 <fci_i2c_transfer+0x4c7>
movl   $0x1,-0x4(%rbp)
jmp    160e <fci_i2c_transfer+0x4ce>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fci_i2c_transfer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,(%rsp)
mov    %r8d,%ebx
mov    %rcx,%r15
mov    %edx,%r12d
mov    %rdi,%r13
cmp    $0x1,%sil
je     1276 <fci_i2c_transfer+0x136>
mov    $0x1,%ebp
test   %sil,%sil
jne    1418 <fci_i2c_transfer+0x2d8>
movzbl %r12b,%edx
mov    %r13,%rdi
mov    $0x35,%esi
call   1050 <bbm_write@plt>
mov    %r13,%rdi
mov    $0x36,%esi
mov    $0x90,%edx
call   1050 <bbm_write@plt>
mov    %r13,%rdi
call   1040 <WaitForXfer@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1418 <fci_i2c_transfer+0x2d8>
test   %r15,%r15
mov    (%rsp),%r12
je     11fd <fci_i2c_transfer+0xbd>
test   %bl,%bl
je     11fd <fci_i2c_transfer+0xbd>
movzbl %bl,%r14d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%edx
mov    %r13,%rdi
mov    $0x35,%esi
call   1050 <bbm_write@plt>
mov    %r13,%rdi
mov    $0x36,%esi
mov    $0x10,%edx
call   1050 <bbm_write@plt>
mov    %r13,%rdi
call   1040 <WaitForXfer@plt>
test   %eax,%eax
jne    13e6 <fci_i2c_transfer+0x2a6>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11c0 <fci_i2c_transfer+0x80>
mov    0x40(%rsp),%al
test   %al,%al
je     124d <fci_i2c_transfer+0x10d>
movzbl %al,%r14d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%r12,%rbx,1),%edx
mov    %r13,%rdi
mov    $0x35,%esi
call   1050 <bbm_write@plt>
mov    %r13,%rdi
mov    $0x36,%esi
mov    $0x10,%edx
call   1050 <bbm_write@plt>
mov    %r13,%rdi
call   1040 <WaitForXfer@plt>
test   %eax,%eax
jne    13e6 <fci_i2c_transfer+0x2a6>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1210 <fci_i2c_transfer+0xd0>
mov    %r13,%rdi
mov    $0x36,%esi
mov    $0x40,%edx
call   1050 <bbm_write@plt>
mov    %r13,%rdi
call   1040 <WaitForXfer@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1418 <fci_i2c_transfer+0x2d8>
jmp    13ea <fci_i2c_transfer+0x2aa>
test   %r15,%r15
je     12fd <fci_i2c_transfer+0x1bd>
test   %bl,%bl
je     12fd <fci_i2c_transfer+0x1bd>
movzbl %r12b,%edx
mov    %r13,%rdi
mov    $0x35,%esi
call   1050 <bbm_write@plt>
mov    %r13,%rdi
mov    $0x36,%esi
mov    $0x90,%edx
call   1050 <bbm_write@plt>
mov    %r13,%rdi
call   1040 <WaitForXfer@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1418 <fci_i2c_transfer+0x2d8>
movzbl %bl,%r14d
xor    %ebx,%ebx
xchg   %ax,%ax
movzbl (%r15,%rbx,1),%edx
mov    %r13,%rdi
mov    $0x35,%esi
call   1050 <bbm_write@plt>
mov    %r13,%rdi
mov    $0x36,%esi
mov    $0x10,%edx
call   1050 <bbm_write@plt>
mov    %r13,%rdi
call   1040 <WaitForXfer@plt>
test   %eax,%eax
jne    13e6 <fci_i2c_transfer+0x2a6>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    12c0 <fci_i2c_transfer+0x180>
or     $0x1,%r12b
movzbl %r12b,%edx
mov    %r13,%rdi
mov    $0x35,%esi
call   1050 <bbm_write@plt>
mov    %r13,%rdi
mov    $0x36,%esi
mov    $0x90,%edx
call   1050 <bbm_write@plt>
mov    %r13,%rdi
call   1040 <WaitForXfer@plt>
mov    %eax,%ebp
test   %eax,%eax
mov    0x40(%rsp),%al
jne    1418 <fci_i2c_transfer+0x2d8>
test   %al,%al
je     13ba <fci_i2c_transfer+0x27a>
movzbl %al,%r12d
mov    %r12d,%ebx
add    $0xffffffff,%ebx
xor    %r14d,%r14d
nop
mov    %r13,%rdi
mov    $0x36,%esi
cmp    %r14,%rbx
jne    1380 <fci_i2c_transfer+0x240>
mov    $0x28,%edx
call   1050 <bbm_write@plt>
mov    %r13,%rdi
call   1040 <WaitForXfer@plt>
mov    %eax,%ebp
test   $0xfffffffd,%eax
je     1398 <fci_i2c_transfer+0x258>
jmp    13ee <fci_i2c_transfer+0x2ae>
nopw   0x0(%rax,%rax,1)
mov    $0x20,%edx
call   1050 <bbm_write@plt>
mov    %r13,%rdi
call   1040 <WaitForXfer@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    1401 <fci_i2c_transfer+0x2c1>
mov    (%rsp),%rax
lea    (%rax,%r14,1),%rdx
mov    %r13,%rdi
mov    $0x33,%esi
call   1060 <bbm_read@plt>
add    $0x1,%r14
cmp    %r12,%r14
jae    13ba <fci_i2c_transfer+0x27a>
test   %ebp,%ebp
je     1350 <fci_i2c_transfer+0x210>
mov    %r13,%rdi
mov    $0x36,%esi
mov    $0x40,%edx
call   1050 <bbm_write@plt>
mov    %r13,%rdi
call   1040 <WaitForXfer@plt>
test   $0xfffffffd,%eax
je     13ea <fci_i2c_transfer+0x2aa>
mov    %eax,%ebp
lea    0xc3a(%rip),%rsi
jmp    13f5 <fci_i2c_transfer+0x2b5>
mov    %eax,%ebp
jmp    1418 <fci_i2c_transfer+0x2d8>
xor    %ebp,%ebp
jmp    1418 <fci_i2c_transfer+0x2d8>
lea    0xc0b(%rip),%rsi
mov    %r13,%rdi
mov    %ebp,%edx
call   1030 <print_log@plt>
jmp    1418 <fci_i2c_transfer+0x2d8>
mov    %eax,%r15d
lea    0xc04(%rip),%rsi
mov    %r13,%rdi
mov    %eax,%edx
call   1030 <print_log@plt>
mov    %r15d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"NACK4-0[%02x]\0A\00"
@.str.1 = [15 x i8] c"NACK4-1[%02x]\0A\00"
@.str.2 = [13 x i8] c"NACK5[%02X]\0A\00"
define i32 @fci_i2c_transfer(i8* %0, i8 zeroext %1, i8 zeroext %2, i8* %3, i8 zeroext %4, i8* %5, i8 zeroext %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8
%11 = alloca i8
%12 = alloca i8*
%13 = alloca i8
%14 = alloca i8*
%15 = alloca i8
%16 = alloca i32
%17 = alloca i32
store i8* %0, i8** %9
store i8 %1, i8* %10
store i8 %2, i8* %11
store i8* %3, i8** %12
store i8 %4, i8* %13
store i8* %5, i8** %14
store i8 %6, i8* %15
store i32 0, i32* %17
%18 = load i8, i8* %10
%19 = zext i8 %18 to i32
switch i32 %19, label %254 [
i32 0, label %20
i32 1, label %116
]
20: ; preds = %7
%21 = load i8*, i8** %9
%22 = load i8, i8* %11
%23 = zext i8 %22 to i32
%24 = load i8, i8* %10
%25 = zext i8 %24 to i32
%26 = or i32 %23, %25
%27 = call i32 @bbm_write(i8* %21, i32 53, i32 %26)
%28 = load i8*, i8** %9
%29 = call i32 @bbm_write(i8* %28, i32 54, i32 144)
%30 = load i8*, i8** %9
%31 = call i32 @WaitForXfer(i8* %30)
store i32 %31, i32* %17
%32 = load i32, i32* %17
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %20
%35 = load i32, i32* %17
store i32 %35, i32* %8
br label %256
36: ; preds = %20
%37 = load i8*, i8** %12
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %75
39: ; preds = %36
%40 = load i8, i8* %13
%41 = zext i8 %40 to i32
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %75
43: ; preds = %39
store i32 0, i32* %16
br label %44
44: ; preds = %71, %43
%45 = load i32, i32* %16
%46 = load i8, i8* %13
%47 = zext i8 %46 to i32
%48 = icmp slt i32 %45, %47
br i1 %48, label %49, label %52
49: ; preds = %44
%50 = load i32, i32* %17
%51 = icmp eq i32 %50, 0
br label %52
52: ; preds = %49, %44
%53 = phi i1 [ false, %44 ], [ %51, %49 ]
br i1 %53, label %54, label %74
54: ; preds = %52
%55 = load i8*, i8** %9
%56 = load i8*, i8** %12
%57 = load i32, i32* %16
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = load i8, i8* %59
%61 = zext i8 %60 to i32
%62 = call i32 @bbm_write(i8* %55, i32 53, i32 %61)
%63 = load i8*, i8** %9
%64 = call i32 @bbm_write(i8* %63, i32 54, i32 16)
%65 = load i8*, i8** %9
%66 = call i32 @WaitForXfer(i8* %65)
store i32 %66, i32* %17
%67 = load i32, i32* %17
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %54
%70 = load i32, i32* %17
store i32 %70, i32* %8
br label %256
71: ; preds = %54
%72 = load i32, i32* %16
%73 = add nsw i32 %72, 1
store i32 %73, i32* %16
br label %44
74: ; preds = %52
br label %75
75: ; preds = %74, %39, %36
store i32 0, i32* %16
br label %76
76: ; preds = %103, %75
%77 = load i32, i32* %16
%78 = load i8, i8* %15
%79 = zext i8 %78 to i32
%80 = icmp slt i32 %77, %79
br i1 %80, label %81, label %84
81: ; preds = %76
%82 = load i32, i32* %17
%83 = icmp eq i32 %82, 0
br label %84
84: ; preds = %81, %76
%85 = phi i1 [ false, %76 ], [ %83, %81 ]
br i1 %85, label %86, label %106
86: ; preds = %84
%87 = load i8*, i8** %9
%88 = load i8*, i8** %14
%89 = load i32, i32* %16
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i8, i8* %88, i64 %90
%92 = load i8, i8* %91
%93 = zext i8 %92 to i32
%94 = call i32 @bbm_write(i8* %87, i32 53, i32 %93)
%95 = load i8*, i8** %9
%96 = call i32 @bbm_write(i8* %95, i32 54, i32 16)
%97 = load i8*, i8** %9
%98 = call i32 @WaitForXfer(i8* %97)
store i32 %98, i32* %17
%99 = load i32, i32* %17
%100 = icmp ne i32 %99, 0
br i1 %100, label %101, label %103
101: ; preds = %86
%102 = load i32, i32* %17
store i32 %102, i32* %8
br label %256
103: ; preds = %86
%104 = load i32, i32* %16
%105 = add nsw i32 %104, 1
store i32 %105, i32* %16
br label %76
106: ; preds = %84
%107 = load i8*, i8** %9
%108 = call i32 @bbm_write(i8* %107, i32 54, i32 64)
%109 = load i8*, i8** %9
%110 = call i32 @WaitForXfer(i8* %109)
store i32 %110, i32* %17
%111 = load i32, i32* %17
%112 = icmp ne i32 %111, 0
br i1 %112, label %113, label %115
113: ; preds = %106
%114 = load i32, i32* %17
store i32 %114, i32* %8
br label %256
115: ; preds = %106
br label %255
116: ; preds = %7
%117 = load i8*, i8** %12
%118 = icmp ne i8* %117, null
br i1 %118, label %119, label %169
119: ; preds = %116
%120 = load i8, i8* %13
%121 = zext i8 %120 to i32
%122 = icmp ne i32 %121, 0
br i1 %122, label %123, label %169
123: ; preds = %119
%124 = load i8*, i8** %9
%125 = load i8, i8* %11
%126 = zext i8 %125 to i32
%127 = or i32 %126, 0
%128 = call i32 @bbm_write(i8* %124, i32 53, i32 %127)
%129 = load i8*, i8** %9
%130 = call i32 @bbm_write(i8* %129, i32 54, i32 144)
%131 = load i8*, i8** %9
%132 = call i32 @WaitForXfer(i8* %131)
store i32 %132, i32* %17
%133 = load i32, i32* %17
%134 = icmp ne i32 %133, 0
br i1 %134, label %135, label %137
135: ; preds = %123
%136 = load i32, i32* %17
store i32 %136, i32* %8
br label %256
137: ; preds = %123
store i32 0, i32* %16
br label %138
138: ; preds = %165, %137
%139 = load i32, i32* %16
%140 = load i8, i8* %13
%141 = zext i8 %140 to i32
%142 = icmp slt i32 %139, %141
br i1 %142, label %143, label %146
143: ; preds = %138
%144 = load i32, i32* %17
%145 = icmp eq i32 %144, 0
br label %146
146: ; preds = %143, %138
%147 = phi i1 [ false, %138 ], [ %145, %143 ]
br i1 %147, label %148, label %168
148: ; preds = %146
%149 = load i8*, i8** %9
%150 = load i8*, i8** %12
%151 = load i32, i32* %16
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds i8, i8* %150, i64 %152
%154 = load i8, i8* %153
%155 = zext i8 %154 to i32
%156 = call i32 @bbm_write(i8* %149, i32 53, i32 %155)
%157 = load i8*, i8** %9
%158 = call i32 @bbm_write(i8* %157, i32 54, i32 16)
%159 = load i8*, i8** %9
%160 = call i32 @WaitForXfer(i8* %159)
store i32 %160, i32* %17
%161 = load i32, i32* %17
%162 = icmp ne i32 %161, 0
br i1 %162, label %163, label %165
163: ; preds = %148
%164 = load i32, i32* %17
store i32 %164, i32* %8
br label %256
165: ; preds = %148
%166 = load i32, i32* %16
%167 = add nsw i32 %166, 1
store i32 %167, i32* %16
br label %138
168: ; preds = %146
br label %169
169: ; preds = %168, %119, %116
%170 = load i8*, i8** %9
%171 = load i8, i8* %11
%172 = zext i8 %171 to i32
%173 = or i32 %172, 1
%174 = call i32 @bbm_write(i8* %170, i32 53, i32 %173)
%175 = load i8*, i8** %9
%176 = call i32 @bbm_write(i8* %175, i32 54, i32 144)
%177 = load i8*, i8** %9
%178 = call i32 @WaitForXfer(i8* %177)
store i32 %178, i32* %17
%179 = load i32, i32* %17
%180 = icmp ne i32 %179, 0
br i1 %180, label %181, label %183
181: ; preds = %169
%182 = load i32, i32* %17
store i32 %182, i32* %8
br label %256
183: ; preds = %169
store i32 0, i32* %16
br label %184
184: ; preds = %229, %183
%185 = load i32, i32* %16
%186 = load i8, i8* %15
%187 = zext i8 %186 to i32
%188 = icmp slt i32 %185, %187
br i1 %188, label %189, label %192
189: ; preds = %184
%190 = load i32, i32* %17
%191 = icmp eq i32 %190, 0
br label %192
192: ; preds = %189, %184
%193 = phi i1 [ false, %184 ], [ %191, %189 ]
br i1 %193, label %194, label %238
194: ; preds = %192
%195 = load i32, i32* %16
%196 = load i8, i8* %15
%197 = zext i8 %196 to i32
%198 = sub nsw i32 %197, 1
%199 = icmp eq i32 %195, %198
br i1 %199, label %200, label %216
200: ; preds = %194
%201 = load i8*, i8** %9
%202 = call i32 @bbm_write(i8* %201, i32 54, i32 40)
%203 = load i8*, i8** %9
%204 = call i32 @WaitForXfer(i8* %203)
store i32 %204, i32* %17
%205 = load i32, i32* %17
%206 = icmp ne i32 %205, 2
br i1 %206, label %207, label %215
207: ; preds = %200
%208 = load i32, i32* %17
%209 = icmp ne i32 %208, 0
br i1 %209, label %210, label %215
210: ; preds = %207
%211 = load i8*, i8** %9
%212 = load i32, i32* %17
%213 = call i32 @print_log(i8* %211, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %212)
%214 = load i32, i32* %17
store i32 %214, i32* %8
br label %256
215: ; preds = %207, %200
br label %229
216: ; preds = %194
%217 = load i8*, i8** %9
%218 = call i32 @bbm_write(i8* %217, i32 54, i32 32)
%219 = load i8*, i8** %9
%220 = call i32 @WaitForXfer(i8* %219)
store i32 %220, i32* %17
%221 = load i32, i32* %17
%222 = icmp ne i32 %221, 0
br i1 %222, label %223, label %228
223: ; preds = %216
%224 = load i8*, i8** %9
%225 = load i32, i32* %17
%226 = call i32 @print_log(i8* %224, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %225)
%227 = load i32, i32* %17
store i32 %227, i32* %8
br label %256
228: ; preds = %216
br label %229
229: ; preds = %228, %215
%230 = load i8*, i8** %9
%231 = load i8*, i8** %14
%232 = load i32, i32* %16
%233 = sext i32 %232 to i64
%234 = getelementptr inbounds i8, i8* %231, i64 %233
%235 = call i32 @bbm_read(i8* %230, i32 51, i8* %234)
%236 = load i32, i32* %16
%237 = add nsw i32 %236, 1
store i32 %237, i32* %16
br label %184
238: ; preds = %192
%239 = load i8*, i8** %9
%240 = call i32 @bbm_write(i8* %239, i32 54, i32 64)
%241 = load i8*, i8** %9
%242 = call i32 @WaitForXfer(i8* %241)
store i32 %242, i32* %17
%243 = load i32, i32* %17
%244 = icmp ne i32 %243, 2
br i1 %244, label %245, label %253
245: ; preds = %238
%246 = load i32, i32* %17
%247 = icmp ne i32 %246, 0
br i1 %247, label %248, label %253
248: ; preds = %245
%249 = load i8*, i8** %9
%250 = load i32, i32* %17
%251 = call i32 @print_log(i8* %249, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %250)
%252 = load i32, i32* %17
store i32 %252, i32* %8
br label %256
253: ; preds = %245, %238
br label %255
254: ; preds = %7
store i32 1, i32* %8
br label %256
255: ; preds = %253, %115
store i32 0, i32* %8
br label %256
256: ; preds = %255, %254, %248, %223, %210, %181, %163, %135, %113, %101, %69, %34
%257 = load i32, i32* %8
ret i32 %257
}

LLVM IR (-O2):
@.str = [15 x i8] c"NACK4-0[%02x]\0A\00"
@.str.1 = [15 x i8] c"NACK4-1[%02x]\0A\00"
@.str.2 = [13 x i8] c"NACK5[%02X]\0A\00"
define i32 @fci_i2c_transfer(i8* %0, i8 zeroext %1, i8 zeroext %2, i8* %3, i8 zeroext %4, i8* %5, i8 zeroext %6) {
switch i8 %1, label %122 [
i8 0, label %8
i8 1, label %52
]
8: ; preds = %7
%9 = zext i8 %2 to i32
%10 = tail call i32 @bbm_write(i8* %0, i32 53, i32 %9)
%11 = tail call i32 @bbm_write(i8* %0, i32 54, i32 144)
%12 = tail call i32 @WaitForXfer(i8* %0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %122
14: ; preds = %8
%15 = icmp ne i8* %3, null
%16 = icmp ne i8 %4, 0
%17 = and i1 %15, %16
br i1 %17, label %18, label %32
18: ; preds = %14
%19 = zext i8 %4 to i64
br label %22
20: ; preds = %22
%21 = icmp eq i64 %31, %19
br i1 %21, label %32, label %22
22: ; preds = %18, %20
%23 = phi i64 [ 0, %18 ], [ %31, %20 ]
%24 = getelementptr inbounds i8, i8* %3, i64 %23
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = tail call i32 @bbm_write(i8* %0, i32 53, i32 %26)
%28 = tail call i32 @bbm_write(i8* %0, i32 54, i32 16)
%29 = tail call i32 @WaitForXfer(i8* %0)
%30 = icmp eq i32 %29, 0
%31 = add nuw nsw i64 %23, 1
br i1 %30, label %20, label %122
32: ; preds = %20, %14
%33 = icmp eq i8 %6, 0
br i1 %33, label %48, label %34
34: ; preds = %32
%35 = zext i8 %6 to i64
br label %38
36: ; preds = %38
%37 = icmp eq i64 %47, %35
br i1 %37, label %48, label %38
38: ; preds = %34, %36
%39 = phi i64 [ 0, %34 ], [ %47, %36 ]
%40 = getelementptr inbounds i8, i8* %5, i64 %39
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = tail call i32 @bbm_write(i8* %0, i32 53, i32 %42)
%44 = tail call i32 @bbm_write(i8* %0, i32 54, i32 16)
%45 = tail call i32 @WaitForXfer(i8* %0)
%46 = icmp eq i32 %45, 0
%47 = add nuw nsw i64 %39, 1
br i1 %46, label %36, label %122
48: ; preds = %36, %32
%49 = tail call i32 @bbm_write(i8* %0, i32 54, i32 64)
%50 = tail call i32 @WaitForXfer(i8* %0)
%51 = icmp eq i32 %50, 0
br i1 %51, label %121, label %122
52: ; preds = %7
%53 = icmp ne i8* %3, null
%54 = icmp ne i8 %4, 0
%55 = and i1 %53, %54
br i1 %55, label %56, label %76
56: ; preds = %52
%57 = zext i8 %2 to i32
%58 = tail call i32 @bbm_write(i8* %0, i32 53, i32 %57)
%59 = tail call i32 @bbm_write(i8* %0, i32 54, i32 144)
%60 = tail call i32 @WaitForXfer(i8* %0)
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %122
62: ; preds = %56
%63 = zext i8 %4 to i64
br label %66
64: ; preds = %66
%65 = icmp eq i64 %75, %63
br i1 %65, label %76, label %66
66: ; preds = %62, %64
%67 = phi i64 [ 0, %62 ], [ %75, %64 ]
%68 = getelementptr inbounds i8, i8* %3, i64 %67
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = tail call i32 @bbm_write(i8* %0, i32 53, i32 %70)
%72 = tail call i32 @bbm_write(i8* %0, i32 54, i32 16)
%73 = tail call i32 @WaitForXfer(i8* %0)
%74 = icmp eq i32 %73, 0
%75 = add nuw nsw i64 %67, 1
br i1 %74, label %64, label %122
76: ; preds = %64, %52
%77 = or i8 %2, 1
%78 = zext i8 %77 to i32
%79 = tail call i32 @bbm_write(i8* %0, i32 53, i32 %78)
%80 = tail call i32 @bbm_write(i8* %0, i32 54, i32 144)
%81 = tail call i32 @WaitForXfer(i8* %0)
%82 = icmp eq i32 %81, 0
br i1 %82, label %83, label %122
83: ; preds = %76
%84 = icmp eq i8 %6, 0
br i1 %84, label %114, label %85
85: ; preds = %83
%86 = zext i8 %6 to i64
%87 = add nuw nsw i64 %86, 4294967295
%88 = and i64 %87, 4294967295
%89 = zext i8 %6 to i64
br label %90
90: ; preds = %85, %106
%91 = phi i64 [ 0, %85 ], [ %110, %106 ]
%92 = icmp eq i64 %91, %88
br i1 %92, label %93, label %100
93: ; preds = %90
%94 = tail call i32 @bbm_write(i8* %0, i32 54, i32 40)
%95 = tail call i32 @WaitForXfer(i8* %0)
%96 = and i32 %95, -3
%97 = icmp eq i32 %96, 0
br i1 %97, label %106, label %98
98: ; preds = %93
%99 = tail call i32 @print_log(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %95)
br label %122
100: ; preds = %90
%101 = tail call i32 @bbm_write(i8* %0, i32 54, i32 32)
%102 = tail call i32 @WaitForXfer(i8* %0)
%103 = icmp eq i32 %102, 0
br i1 %103, label %106, label %104
104: ; preds = %100
%105 = tail call i32 @print_log(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %102)
br label %122
106: ; preds = %100, %93
%107 = phi i32 [ %95, %93 ], [ 0, %100 ]
%108 = getelementptr inbounds i8, i8* %5, i64 %91
%109 = tail call i32 @bbm_read(i8* %0, i32 51, i8* %108)
%110 = add nuw nsw i64 %91, 1
%111 = icmp ult i64 %110, %89
%112 = icmp eq i32 %107, 0
%113 = select i1 %111, i1 %112, i1 false
br i1 %113, label %90, label %114
114: ; preds = %106, %83
%115 = tail call i32 @bbm_write(i8* %0, i32 54, i32 64)
%116 = tail call i32 @WaitForXfer(i8* %0)
%117 = and i32 %116, -3
%118 = icmp eq i32 %117, 0
br i1 %118, label %121, label %119
119: ; preds = %114
%120 = tail call i32 @print_log(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %116)
br label %122
121: ; preds = %114, %48
br label %122
122: ; preds = %66, %22, %38, %7, %76, %56, %48, %8, %121, %119, %104, %98
%123 = phi i32 [ %95, %98 ], [ %102, %104 ], [ %116, %119 ], [ 0, %121 ], [ %12, %8 ], [ %50, %48 ], [ %60, %56 ], [ %81, %76 ], [ 1, %7 ], [ %45, %38 ], [ %29, %22 ], [ %73, %66 ]
ret i32 %123
}