#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;
struct flashrom_flashctx {
  int dummy;
};

/* Variables and functions */
int get_fd_from_context(struct flashrom_flashctx const *);
int realtek_mst_i2c_spi_read_register(int, int, unsigned char *);
int realtek_mst_i2c_spi_wait_command_done(int, int, int, int /*<<< orphan*/,
                                          int);
int realtek_mst_i2c_spi_write_register(int, int, unsigned char const);
int realtek_mst_i2c_spi_send_command(const struct flashrom_flashctx *flash,
                                     unsigned int writecnt,
                                     unsigned int readcnt,
                                     const unsigned char *writearr,
                                     unsigned char *readarr) {
  unsigned i;
  int max_timeout_mul = 1;
  int ret = 0;
  if (writecnt > 4 || readcnt > 3 || writecnt == 0) {
    return -1;
  }
  int fd = get_fd_from_context(flash);
  if (fd < 0)
    return -1;
  writecnt--;
  uint8_t ctrl_reg_val = (writecnt << 3) | (readcnt << 1);
  switch (writearr[0]) {
  case 0x06:
    return 0;
  case 0x01:
    ctrl_reg_val |= (1 << 5);
    ctrl_reg_val |= (2 << 5);
    break;
  case 0xc7:
    max_timeout_mul *= 20;
  case 0x60:
  case 0x52:
  case 0xd8:
  case 0xd7:
  case 0x20:
    ctrl_reg_val |= (1 << 5);
    ctrl_reg_val |= (4 << 5);
    break;
  default:
    ctrl_reg_val |= (2 << 5);
  }
  ret |= realtek_mst_i2c_spi_write_register(fd, 0x60, ctrl_reg_val);
  ret |= realtek_mst_i2c_spi_write_register(fd, 0x61, writearr[0]);
  for (i = 0; i < writecnt; ++i)
    ret |= realtek_mst_i2c_spi_write_register(fd, 0x64 + i, writearr[i + 1]);
  ret |= realtek_mst_i2c_spi_write_register(fd, 0x60, ctrl_reg_val | 0x1);
  if (ret)
    return ret;
  ret =
      realtek_mst_i2c_spi_wait_command_done(fd, 0x60, 0x01, 0, max_timeout_mul);
  if (ret)
    return ret;
  for (i = 0; i < readcnt; ++i)
    ret |= realtek_mst_i2c_spi_read_register(fd, 0x67 + i, &readarr[i]);
  return ret;
}


x86 assembly (clang, -O0):
<realtek_mst_i2c_spi_send_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x1,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x4,-0x14(%rbp)
ja     1186 <realtek_mst_i2c_spi_send_command+0x46>
cmpl   $0x3,-0x18(%rbp)
ja     1186 <realtek_mst_i2c_spi_send_command+0x46>
cmpl   $0x0,-0x14(%rbp)
jne    1192 <realtek_mst_i2c_spi_send_command+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    13bc <realtek_mst_i2c_spi_send_command+0x27c>
mov    -0x10(%rbp),%rdi
call   1030 <get_fd_from_context@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    11b4 <realtek_mst_i2c_spi_send_command+0x74>
movl   $0xffffffff,-0x4(%rbp)
jmp    13bc <realtek_mst_i2c_spi_send_command+0x27c>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x3,%eax
mov    -0x18(%rbp),%ecx
add    %ecx,%ecx
or     %ecx,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x40(%rbp)
sub    $0x1,%eax
je     125e <realtek_mst_i2c_spi_send_command+0x11e>
jmp    11e5 <realtek_mst_i2c_spi_send_command+0xa5>
mov    -0x40(%rbp),%eax
sub    $0x6,%eax
je     1252 <realtek_mst_i2c_spi_send_command+0x112>
jmp    11f6 <realtek_mst_i2c_spi_send_command+0xb6>
mov    -0x40(%rbp),%eax
sub    $0x20,%eax
je     127c <realtek_mst_i2c_spi_send_command+0x13c>
jmp    1207 <realtek_mst_i2c_spi_send_command+0xc7>
mov    -0x40(%rbp),%eax
sub    $0x52,%eax
je     127c <realtek_mst_i2c_spi_send_command+0x13c>
jmp    1218 <realtek_mst_i2c_spi_send_command+0xd8>
mov    -0x40(%rbp),%eax
sub    $0x60,%eax
je     127c <realtek_mst_i2c_spi_send_command+0x13c>
jmp    1229 <realtek_mst_i2c_spi_send_command+0xe9>
mov    -0x40(%rbp),%eax
sub    $0xc7,%eax
je     1275 <realtek_mst_i2c_spi_send_command+0x135>
jmp    123c <realtek_mst_i2c_spi_send_command+0xfc>
mov    -0x40(%rbp),%eax
add    $0xffffff29,%eax
sub    $0x2,%eax
jb     127c <realtek_mst_i2c_spi_send_command+0x13c>
jmp    1295 <realtek_mst_i2c_spi_send_command+0x155>
movl   $0x0,-0x4(%rbp)
jmp    13bc <realtek_mst_i2c_spi_send_command+0x27c>
mov    -0x3c(%rbp),%eax
or     $0x20,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
or     $0x40,%eax
mov    %eax,-0x3c(%rbp)
jmp    129e <realtek_mst_i2c_spi_send_command+0x15e>
imul   $0x14,-0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x3c(%rbp),%eax
or     $0x20,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
or     $0x80,%eax
mov    %eax,-0x3c(%rbp)
jmp    129e <realtek_mst_i2c_spi_send_command+0x15e>
mov    -0x3c(%rbp),%eax
or     $0x40,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x3c(%rbp),%eax
mov    $0x60,%esi
movzbl %al,%edx
call   1060 <realtek_mst_i2c_spi_write_register@plt>
or     -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    $0x61,%esi
movzbl (%rax),%edx
call   1060 <realtek_mst_i2c_spi_write_register@plt>
or     -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1316 <realtek_mst_i2c_spi_send_command+0x1d6>
mov    -0x38(%rbp),%edi
mov    -0x2c(%rbp),%esi
add    $0x64,%esi
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%edx
call   1060 <realtek_mst_i2c_spi_write_register@plt>
or     -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12d8 <realtek_mst_i2c_spi_send_command+0x198>
mov    -0x38(%rbp),%edi
mov    -0x3c(%rbp),%eax
or     $0x1,%eax
mov    $0x60,%esi
movzbl %al,%edx
call   1060 <realtek_mst_i2c_spi_write_register@plt>
or     -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1347 <realtek_mst_i2c_spi_send_command+0x207>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13bc <realtek_mst_i2c_spi_send_command+0x27c>
mov    -0x38(%rbp),%edi
mov    -0x30(%rbp),%r8d
mov    $0x60,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <realtek_mst_i2c_spi_wait_command_done@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1377 <realtek_mst_i2c_spi_send_command+0x237>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13bc <realtek_mst_i2c_spi_send_command+0x27c>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    13b6 <realtek_mst_i2c_spi_send_command+0x276>
mov    -0x38(%rbp),%edi
mov    -0x2c(%rbp),%esi
add    $0x67,%esi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%eax
add    %rax,%rdx
call   1050 <realtek_mst_i2c_spi_read_register@plt>
or     -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    137e <realtek_mst_i2c_spi_send_command+0x23e>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<realtek_mst_i2c_spi_send_command>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
lea    -0x5(%rbp),%eax
mov    $0xffffffff,%r15d
cmp    $0xfffffffc,%eax
jb     130b <realtek_mst_i2c_spi_send_command+0x1cb>
cmp    $0x3,%edx
ja     130b <realtek_mst_i2c_spi_send_command+0x1cb>
mov    %r8,%rbx
mov    %rcx,%r12
mov    %rdx,0x8(%rsp)
call   1030 <get_fd_from_context@plt>
test   %eax,%eax
js     130b <realtek_mst_i2c_spi_send_command+0x1cb>
mov    %eax,%r13d
mov    (%r12),%al
cmp    $0x5,%al
jg     11b7 <realtek_mst_i2c_spi_send_command+0x77>
lea    0x29(%rax),%ecx
cmp    $0x2,%cl
jb     11ff <realtek_mst_i2c_spi_send_command+0xbf>
cmp    $0xc7,%al
je     120e <realtek_mst_i2c_spi_send_command+0xce>
movl   $0x1,0x4(%rsp)
mov    $0x60,%ecx
cmp    $0x1,%al
mov    0x8(%rsp),%rdx
jne    11f3 <realtek_mst_i2c_spi_send_command+0xb3>
mov    %rbx,0x10(%rsp)
jmp    1225 <realtek_mst_i2c_spi_send_command+0xe5>
cmp    $0x51,%al
jg     11de <realtek_mst_i2c_spi_send_command+0x9e>
movl   $0x1,0x4(%rsp)
xor    %r15d,%r15d
cmp    $0x6,%al
je     130b <realtek_mst_i2c_spi_send_command+0x1cb>
cmp    $0x20,%al
mov    0x8(%rsp),%rdx
jne    11f3 <realtek_mst_i2c_spi_send_command+0xb3>
mov    %rbx,0x10(%rsp)
jmp    1220 <realtek_mst_i2c_spi_send_command+0xe0>
movl   $0x1,0x4(%rsp)
cmp    $0x52,%al
je     1207 <realtek_mst_i2c_spi_send_command+0xc7>
cmp    $0x60,%al
mov    0x8(%rsp),%rdx
je     11d7 <realtek_mst_i2c_spi_send_command+0x97>
mov    %rbx,0x10(%rsp)
mov    $0x40,%ecx
jmp    1225 <realtek_mst_i2c_spi_send_command+0xe5>
movl   $0x1,0x4(%rsp)
mov    %rbx,0x10(%rsp)
jmp    121b <realtek_mst_i2c_spi_send_command+0xdb>
mov    %rbx,0x10(%rsp)
movl   $0x14,0x4(%rsp)
mov    0x8(%rsp),%rdx
mov    $0xa0,%ecx
mov    %ebp,%eax
add    $0xffffffff,%ebp
lea    -0x8(,%rax,8),%eax
lea    (%rdx,%rdx,1),%r15d
or     %eax,%r15d
or     %ecx,%r15d
movzbl %r15b,%edx
mov    %r13d,%edi
mov    $0x60,%esi
call   1060 <realtek_mst_i2c_spi_write_register@plt>
mov    %eax,%ebx
movzbl (%r12),%edx
mov    %r13d,%edi
mov    $0x61,%esi
call   1060 <realtek_mst_i2c_spi_write_register@plt>
mov    %eax,%r14d
or     %ebx,%r14d
test   %ebp,%ebp
je     128d <realtek_mst_i2c_spi_send_command+0x14d>
mov    %ebp,%ebp
xor    %ebx,%ebx
xchg   %ax,%ax
lea    0x64(%rbx),%esi
movzbl 0x1(%r12,%rbx,1),%edx
add    $0x1,%rbx
mov    %r13d,%edi
call   1060 <realtek_mst_i2c_spi_write_register@plt>
or     %eax,%r14d
cmp    %rbx,%rbp
jne    1270 <realtek_mst_i2c_spi_send_command+0x130>
or     $0x1,%r15b
movzbl %r15b,%edx
mov    %r13d,%edi
mov    $0x60,%esi
call   1060 <realtek_mst_i2c_spi_write_register@plt>
mov    %eax,%r15d
or     %r14d,%r15d
mov    0x10(%rsp),%r14
jne    130b <realtek_mst_i2c_spi_send_command+0x1cb>
mov    %r13d,%edi
mov    $0x60,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
mov    0x4(%rsp),%r8d
call   1040 <realtek_mst_i2c_spi_wait_command_done@plt>
mov    %eax,%r15d
test   %eax,%eax
jne    130b <realtek_mst_i2c_spi_send_command+0x1cb>
mov    $0x0,%r15d
cmpl   $0x0,0x8(%rsp)
je     130b <realtek_mst_i2c_spi_send_command+0x1cb>
mov    0x8(%rsp),%ebx
xor    %ebp,%ebp
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x67(%rbp),%esi
lea    (%r14,%rbp,1),%rdx
mov    %r13d,%edi
call   1050 <realtek_mst_i2c_spi_read_register@plt>
or     %eax,%r15d
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    12f0 <realtek_mst_i2c_spi_send_command+0x1b0>
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.flashrom_flashctx = type { i32 }
define i32 @realtek_mst_i2c_spi_send_command(%struct.flashrom_flashctx* %0, i32 %1, i32 %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca %struct.flashrom_flashctx*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store %struct.flashrom_flashctx* %0, %struct.flashrom_flashctx** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i32 1, i32* %13
store i32 0, i32* %14
%17 = load i32, i32* %8
%18 = icmp ugt i32 %17, 4
br i1 %18, label %25, label %19
19: ; preds = %5
%20 = load i32, i32* %9
%21 = icmp ugt i32 %20, 3
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* %8
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22, %19, %5
store i32 -1, i32* %6
br label %136
26: ; preds = %22
%27 = load %struct.flashrom_flashctx*, %struct.flashrom_flashctx** %7
%28 = call i32 @get_fd_from_context(%struct.flashrom_flashctx* %27)
store i32 %28, i32* %15
%29 = load i32, i32* %15
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
store i32 -1, i32* %6
br label %136
32: ; preds = %26
%33 = load i32, i32* %8
%34 = add i32 %33, -1
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = shl i32 %35, 3
%37 = load i32, i32* %9
%38 = shl i32 %37, 1
%39 = or i32 %36, %38
store i32 %39, i32* %16
%40 = load i8*, i8** %10
%41 = getelementptr inbounds i8, i8* %40, i64 0
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
switch i32 %43, label %58 [
i32 6, label %44
i32 1, label %45
i32 199, label %50
i32 96, label %53
i32 82, label %53
i32 216, label %53
i32 215, label %53
i32 32, label %53
]
44: ; preds = %32
store i32 0, i32* %6
br label %136
45: ; preds = %32
%46 = load i32, i32* %16
%47 = or i32 %46, 32
store i32 %47, i32* %16
%48 = load i32, i32* %16
%49 = or i32 %48, 64
store i32 %49, i32* %16
br label %61
50: ; preds = %32
%51 = load i32, i32* %13
%52 = mul nsw i32 %51, 20
store i32 %52, i32* %13
br label %53
53: ; preds = %32, %32, %32, %32, %32, %50
%54 = load i32, i32* %16
%55 = or i32 %54, 32
store i32 %55, i32* %16
%56 = load i32, i32* %16
%57 = or i32 %56, 128
store i32 %57, i32* %16
br label %61
58: ; preds = %32
%59 = load i32, i32* %16
%60 = or i32 %59, 64
store i32 %60, i32* %16
br label %61
61: ; preds = %58, %53, %45
%62 = load i32, i32* %15
%63 = load i32, i32* %16
%64 = trunc i32 %63 to i8
%65 = call i32 @realtek_mst_i2c_spi_write_register(i32 %62, i32 96, i8 zeroext %64)
%66 = load i32, i32* %14
%67 = or i32 %66, %65
store i32 %67, i32* %14
%68 = load i32, i32* %15
%69 = load i8*, i8** %10
%70 = getelementptr inbounds i8, i8* %69, i64 0
%71 = load i8, i8* %70
%72 = call i32 @realtek_mst_i2c_spi_write_register(i32 %68, i32 97, i8 zeroext %71)
%73 = load i32, i32* %14
%74 = or i32 %73, %72
store i32 %74, i32* %14
store i32 0, i32* %12
br label %75
75: ; preds = %92, %61
%76 = load i32, i32* %12
%77 = load i32, i32* %8
%78 = icmp ult i32 %76, %77
br i1 %78, label %79, label %95
79: ; preds = %75
%80 = load i32, i32* %15
%81 = load i32, i32* %12
%82 = add i32 100, %81
%83 = load i8*, i8** %10
%84 = load i32, i32* %12
%85 = add i32 %84, 1
%86 = zext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %83, i64 %86
%88 = load i8, i8* %87
%89 = call i32 @realtek_mst_i2c_spi_write_register(i32 %80, i32 %82, i8 zeroext %88)
%90 = load i32, i32* %14
%91 = or i32 %90, %89
store i32 %91, i32* %14
br label %92
92: ; preds = %79
%93 = load i32, i32* %12
%94 = add i32 %93, 1
store i32 %94, i32* %12
br label %75
95: ; preds = %75
%96 = load i32, i32* %15
%97 = load i32, i32* %16
%98 = or i32 %97, 1
%99 = trunc i32 %98 to i8
%100 = call i32 @realtek_mst_i2c_spi_write_register(i32 %96, i32 96, i8 zeroext %99)
%101 = load i32, i32* %14
%102 = or i32 %101, %100
store i32 %102, i32* %14
%103 = load i32, i32* %14
%104 = icmp ne i32 %103, 0
br i1 %104, label %105, label %107
105: ; preds = %95
%106 = load i32, i32* %14
store i32 %106, i32* %6
br label %136
107: ; preds = %95
%108 = load i32, i32* %15
%109 = load i32, i32* %13
%110 = call i32 @realtek_mst_i2c_spi_wait_command_done(i32 %108, i32 96, i32 1, i32 0, i32 %109)
store i32 %110, i32* %14
%111 = load i32, i32* %14
%112 = icmp ne i32 %111, 0
br i1 %112, label %113, label %115
113: ; preds = %107
%114 = load i32, i32* %14
store i32 %114, i32* %6
br label %136
115: ; preds = %107
store i32 0, i32* %12
br label %116
116: ; preds = %131, %115
%117 = load i32, i32* %12
%118 = load i32, i32* %9
%119 = icmp ult i32 %117, %118
br i1 %119, label %120, label %134
120: ; preds = %116
%121 = load i32, i32* %15
%122 = load i32, i32* %12
%123 = add i32 103, %122
%124 = load i8*, i8** %11
%125 = load i32, i32* %12
%126 = zext i32 %125 to i64
%127 = getelementptr inbounds i8, i8* %124, i64 %126
%128 = call i32 @realtek_mst_i2c_spi_read_register(i32 %121, i32 %123, i8* %127)
%129 = load i32, i32* %14
%130 = or i32 %129, %128
store i32 %130, i32* %14
br label %131
131: ; preds = %120
%132 = load i32, i32* %12
%133 = add i32 %132, 1
store i32 %133, i32* %12
br label %116
134: ; preds = %116
%135 = load i32, i32* %14
store i32 %135, i32* %6
br label %136
136: ; preds = %134, %113, %105, %44, %31, %25
%137 = load i32, i32* %6
ret i32 %137
}

LLVM IR (-O2):
%struct.flashrom_flashctx = type { i32 }
define i32 @realtek_mst_i2c_spi_send_command(%struct.flashrom_flashctx* %0, i32 %1, i32 %2, i8* nocapture %3, i8* %4) {
%6 = icmp ugt i32 %2, 3
%7 = add i32 %1, -5
%8 = icmp ult i32 %7, -4
%9 = or i1 %8, %6
br i1 %9, label %69, label %10
10: ; preds = %5
%11 = tail call i32 @get_fd_from_context(%struct.flashrom_flashctx* %0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %69, label %13
13: ; preds = %10
%14 = add nsw i32 %1, -1
%15 = shl nuw nsw i32 %14, 3
%16 = shl nuw nsw i32 %2, 1
%17 = or i32 %15, %16
%18 = load i8, i8* %3
switch i8 %18, label %22 [
i8 6, label %69
i8 1, label %23
i8 -57, label %19
i8 96, label %20
i8 82, label %20
i8 -40, label %20
i8 -41, label %20
i8 32, label %20
]
19: ; preds = %13
br label %20
20: ; preds = %13, %13, %13, %13, %13, %19
%21 = phi i32 [ 1, %13 ], [ 1, %13 ], [ 1, %13 ], [ 1, %13 ], [ 1, %13 ], [ 20, %19 ]
br label %23
22: ; preds = %13
br label %23
23: ; preds = %13, %22, %20
%24 = phi i32 [ 64, %22 ], [ 160, %20 ], [ 96, %13 ]
%25 = phi i32 [ 1, %22 ], [ %21, %20 ], [ 1, %13 ]
%26 = or i32 %17, %24
%27 = trunc i32 %26 to i8
%28 = tail call i32 @realtek_mst_i2c_spi_write_register(i32 %11, i32 96, i8 zeroext %27)
%29 = load i8, i8* %3
%30 = tail call i32 @realtek_mst_i2c_spi_write_register(i32 %11, i32 97, i8 zeroext %29)
%31 = or i32 %30, %28
%32 = icmp eq i32 %14, 0
br i1 %32, label %46, label %33
33: ; preds = %23
%34 = zext i32 %14 to i64
br label %35
35: ; preds = %33, %35
%36 = phi i64 [ 0, %33 ], [ %40, %35 ]
%37 = phi i32 [ %31, %33 ], [ %44, %35 ]
%38 = trunc i64 %36 to i32
%39 = add i32 %38, 100
%40 = add nuw nsw i64 %36, 1
%41 = getelementptr inbounds i8, i8* %3, i64 %40
%42 = load i8, i8* %41
%43 = tail call i32 @realtek_mst_i2c_spi_write_register(i32 %11, i32 %39, i8 zeroext %42)
%44 = or i32 %43, %37
%45 = icmp eq i64 %40, %34
br i1 %45, label %46, label %35
46: ; preds = %35, %23
%47 = phi i32 [ %31, %23 ], [ %44, %35 ]
%48 = or i8 %27, 1
%49 = tail call i32 @realtek_mst_i2c_spi_write_register(i32 %11, i32 96, i8 zeroext %48)
%50 = or i32 %49, %47
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %69
52: ; preds = %46
%53 = tail call i32 @realtek_mst_i2c_spi_wait_command_done(i32 %11, i32 96, i32 1, i32 0, i32 %25)
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %69
55: ; preds = %52
%56 = icmp eq i32 %2, 0
br i1 %56, label %69, label %57
57: ; preds = %55
%58 = zext i32 %2 to i64
br label %59
59: ; preds = %57, %59
%60 = phi i64 [ 0, %57 ], [ %67, %59 ]
%61 = phi i32 [ 0, %57 ], [ %66, %59 ]
%62 = trunc i64 %60 to i32
%63 = add i32 %62, 103
%64 = getelementptr inbounds i8, i8* %4, i64 %60
%65 = tail call i32 @realtek_mst_i2c_spi_read_register(i32 %11, i32 %63, i8* %64)
%66 = or i32 %65, %61
%67 = add nuw nsw i64 %60, 1
%68 = icmp eq i64 %67, %58
br i1 %68, label %69, label %59
69: ; preds = %59, %55, %10, %52, %46, %13, %5
%70 = phi i32 [ -1, %5 ], [ -1, %10 ], [ 0, %13 ], [ %50, %46 ], [ %53, %52 ], [ 0, %55 ], [ %66, %59 ]
ret i32 %70
}