#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 realtek_mst_i2c_spi_wait_command_done(int, int, int, int, int);
int realtek_mst_i2c_spi_write_register(int, int, int);
int realtek_mst_i2c_spi_enter_isp_mode(int fd) {
  int ret = realtek_mst_i2c_spi_write_register(fd, 0x6F, 0x80);
  ret |= realtek_mst_i2c_spi_wait_command_done(fd, 0x6F, 0x80, 0x80, 1);
  if (ret)
    return ret;
  ret |= realtek_mst_i2c_spi_write_register(fd, 0xF4, 0x9F);
  ret |= realtek_mst_i2c_spi_write_register(fd, 0xF5, 0x06);
  ret |= realtek_mst_i2c_spi_write_register(fd, 0xF4, 0xA0);
  ret |= realtek_mst_i2c_spi_write_register(fd, 0xF5, 0x74);
  return ret;
}


x86 assembly (clang, -O0):
<realtek_mst_i2c_spi_enter_isp_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x6f,%esi
mov    $0x80,%edx
call   1040 <realtek_mst_i2c_spi_write_register@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x6f,%esi
mov    $0x80,%ecx
mov    $0x1,%r8d
mov    %ecx,%edx
call   1030 <realtek_mst_i2c_spi_wait_command_done@plt>
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1175 <realtek_mst_i2c_spi_enter_isp_mode+0x55>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11db <realtek_mst_i2c_spi_enter_isp_mode+0xbb>
mov    -0x8(%rbp),%edi
mov    $0xf4,%esi
mov    $0x9f,%edx
call   1040 <realtek_mst_i2c_spi_write_register@plt>
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    $0xf5,%esi
mov    $0x6,%edx
call   1040 <realtek_mst_i2c_spi_write_register@plt>
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    $0xf4,%esi
mov    $0xa0,%edx
call   1040 <realtek_mst_i2c_spi_write_register@plt>
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    $0xf5,%esi
mov    $0x74,%edx
call   1040 <realtek_mst_i2c_spi_write_register@plt>
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<realtek_mst_i2c_spi_enter_isp_mode>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
mov    $0x6f,%esi
mov    $0x80,%edx
call   1040 <realtek_mst_i2c_spi_write_register@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    $0x6f,%esi
mov    $0x80,%edx
mov    $0x80,%ecx
mov    $0x1,%r8d
call   1030 <realtek_mst_i2c_spi_wait_command_done@plt>
or     %ebp,%eax
jne    11ab <realtek_mst_i2c_spi_enter_isp_mode+0x8b>
mov    %ebx,%edi
mov    $0xf4,%esi
mov    $0x9f,%edx
call   1040 <realtek_mst_i2c_spi_write_register@plt>
mov    %eax,%r14d
mov    %ebx,%edi
mov    $0xf5,%esi
mov    $0x6,%edx
call   1040 <realtek_mst_i2c_spi_write_register@plt>
mov    %eax,%ebp
or     %r14d,%ebp
mov    %ebx,%edi
mov    $0xf4,%esi
mov    $0xa0,%edx
call   1040 <realtek_mst_i2c_spi_write_register@plt>
mov    %eax,%r14d
mov    %ebx,%edi
mov    $0xf5,%esi
mov    $0x74,%edx
call   1040 <realtek_mst_i2c_spi_write_register@plt>
or     %r14d,%eax
or     %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @realtek_mst_i2c_spi_enter_isp_mode(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i32 @realtek_mst_i2c_spi_write_register(i32 %5, i32 111, i32 128)
store i32 %6, i32* %4
%7 = load i32, i32* %3
%8 = call i32 @realtek_mst_i2c_spi_wait_command_done(i32 %7, i32 111, i32 128, i32 128, i32 1)
%9 = load i32, i32* %4
%10 = or i32 %9, %8
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = load i32, i32* %4
store i32 %14, i32* %2
br label %33
15: ; preds = %1
%16 = load i32, i32* %3
%17 = call i32 @realtek_mst_i2c_spi_write_register(i32 %16, i32 244, i32 159)
%18 = load i32, i32* %4
%19 = or i32 %18, %17
store i32 %19, i32* %4
%20 = load i32, i32* %3
%21 = call i32 @realtek_mst_i2c_spi_write_register(i32 %20, i32 245, i32 6)
%22 = load i32, i32* %4
%23 = or i32 %22, %21
store i32 %23, i32* %4
%24 = load i32, i32* %3
%25 = call i32 @realtek_mst_i2c_spi_write_register(i32 %24, i32 244, i32 160)
%26 = load i32, i32* %4
%27 = or i32 %26, %25
store i32 %27, i32* %4
%28 = load i32, i32* %3
%29 = call i32 @realtek_mst_i2c_spi_write_register(i32 %28, i32 245, i32 116)
%30 = load i32, i32* %4
%31 = or i32 %30, %29
store i32 %31, i32* %4
%32 = load i32, i32* %4
store i32 %32, i32* %2
br label %33
33: ; preds = %15, %13
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
define i32 @realtek_mst_i2c_spi_enter_isp_mode(i32 %0) {
%2 = tail call i32 @realtek_mst_i2c_spi_write_register(i32 %0, i32 111, i32 128)
%3 = tail call i32 @realtek_mst_i2c_spi_wait_command_done(i32 %0, i32 111, i32 128, i32 128, i32 1)
%4 = or i32 %3, %2
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = tail call i32 @realtek_mst_i2c_spi_write_register(i32 %0, i32 244, i32 159)
%8 = tail call i32 @realtek_mst_i2c_spi_write_register(i32 %0, i32 245, i32 6)
%9 = or i32 %8, %7
%10 = tail call i32 @realtek_mst_i2c_spi_write_register(i32 %0, i32 244, i32 160)
%11 = or i32 %9, %10
%12 = tail call i32 @realtek_mst_i2c_spi_write_register(i32 %0, i32 245, i32 116)
%13 = or i32 %11, %12
br label %14
14: ; preds = %1, %6
%15 = phi i32 [ %13, %6 ], [ %4, %1 ]
ret i32 %15
}