#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 i2c_read_rx_data();
int i2c_read_status();
int /*<<< orphan*/ i2c_write_command(int);
int i2c_write_data_command(int, int);
int /*<<< orphan*/ writeHex(int);
int /*<<< orphan*/ writeString(char *);
int hdmi_read_reg(int i2c_addr) {
  int t, sr;
  sr = i2c_write_data_command(0x98, 0x90);
  sr = i2c_write_data_command(i2c_addr, 0x10);
  sr = i2c_write_data_command(0x98 | 0x01, 0x90);
  i2c_write_command(0x20 | 0x08 | 0x40);
  for (t = 100 * 1250, sr = 2; (t > 0) && ((sr & 0x02) != 0); t--)
    sr = i2c_read_status();
  if (t == 0) {
    writeString("READ TIME OUT - sr=");
    writeHex(sr);
    writeString("\n");
  }
  return i2c_read_rx_data();
}


x86 assembly (clang, -O0):
<hdmi_read_reg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x98,%edi
mov    $0x90,%esi
call   1030 <i2c_write_data_command@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x10,%esi
call   1030 <i2c_write_data_command@plt>
mov    %eax,-0xc(%rbp)
mov    $0x99,%edi
mov    $0x90,%esi
call   1030 <i2c_write_data_command@plt>
mov    %eax,-0xc(%rbp)
mov    $0x68,%edi
call   1050 <i2c_write_command@plt>
movl   $0x1e848,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0xd(%rbp)
jle    11d5 <hdmi_read_reg+0x75>
mov    -0xc(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    11e5 <hdmi_read_reg+0x85>
jmp    11fd <hdmi_read_reg+0x9d>
mov    $0x0,%al
call   1080 <i2c_read_status@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    11b7 <hdmi_read_reg+0x57>
cmpl   $0x0,-0x8(%rbp)
jne    1227 <hdmi_read_reg+0xc7>
lea    0xdf2(%rip),%rdi
call   1060 <writeString@plt>
mov    -0xc(%rbp),%edi
call   1070 <writeHex@plt>
lea    0xdf2(%rip),%rdi
call   1060 <writeString@plt>
mov    $0x0,%al
call   1040 <i2c_read_rx_data@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hdmi_read_reg>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x98,%edi
mov    $0x90,%esi
call   1030 <i2c_write_data_command@plt>
mov    %ebx,%edi
mov    $0x10,%esi
call   1030 <i2c_write_data_command@plt>
mov    $0x99,%edi
mov    $0x90,%esi
call   1030 <i2c_write_data_command@plt>
mov    $0x68,%edi
call   1050 <i2c_write_command@plt>
mov    $0x1e848,%eax
xchg   %ax,%ax
mov    %eax,%ebx
xor    %eax,%eax
call   1080 <i2c_read_status@plt>
mov    %eax,%ebp
lea    -0x1(%rbx),%eax
cmp    $0x1,%ebx
je     11ba <hdmi_read_reg+0x5a>
mov    %ebp,%ecx
and    $0x2,%ecx
jne    11a0 <hdmi_read_reg+0x40>
test   %eax,%eax
jne    11dd <hdmi_read_reg+0x7d>
lea    0xe3b(%rip),%rdi
call   1060 <writeString@plt>
mov    %ebp,%edi
call   1070 <writeHex@plt>
lea    0xe3c(%rip),%rdi
call   1060 <writeString@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <i2c_read_rx_data@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"READ TIME OUT - sr=\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @hdmi_read_reg(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32 @i2c_write_data_command(i32 152, i32 144)
store i32 %5, i32* %4
%6 = load i32, i32* %2
%7 = call i32 @i2c_write_data_command(i32 %6, i32 16)
store i32 %7, i32* %4
%8 = call i32 @i2c_write_data_command(i32 153, i32 144)
store i32 %8, i32* %4
%9 = call i32 @i2c_write_command(i32 104)
store i32 125000, i32* %3
store i32 2, i32* %4
br label %10
10: ; preds = %21, %1
%11 = load i32, i32* %3
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* %4
%15 = and i32 %14, 2
%16 = icmp ne i32 %15, 0
br label %17
17: ; preds = %13, %10
%18 = phi i1 [ false, %10 ], [ %16, %13 ]
br i1 %18, label %19, label %24
19: ; preds = %17
%20 = call i32 (...) @i2c_read_status()
store i32 %20, i32* %4
br label %21
21: ; preds = %19
%22 = load i32, i32* %3
%23 = add nsw i32 %22, -1
store i32 %23, i32* %3
br label %10
24: ; preds = %17
%25 = load i32, i32* %3
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = call i32 @writeString(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* %4
%30 = call i32 @writeHex(i32 %29)
%31 = call i32 @writeString(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %27, %24
%33 = call i32 (...) @i2c_read_rx_data()
ret i32 %33
}

LLVM IR (-O2):
@.str = [20 x i8] c"READ TIME OUT - sr=\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @hdmi_read_reg(i32 %0) {
%2 = tail call i32 @i2c_write_data_command(i32 152, i32 144)
%3 = tail call i32 @i2c_write_data_command(i32 %0, i32 16)
%4 = tail call i32 @i2c_write_data_command(i32 153, i32 144)
%5 = tail call i32 @i2c_write_command(i32 104)
br label %6
6: ; preds = %1, %6
%7 = phi i32 [ 125000, %1 ], [ %9, %6 ]
%8 = tail call i32 (...) @i2c_read_status()
%9 = add nsw i32 %7, -1
%10 = icmp ne i32 %9, 0
%11 = and i32 %8, 2
%12 = icmp ne i32 %11, 0
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %6, label %14
14: ; preds = %6
%15 = icmp eq i32 %9, 0
br i1 %15, label %16, label %20
16: ; preds = %14
%17 = tail call i32 @writeString(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%18 = tail call i32 @writeHex(i32 %8)
%19 = tail call i32 @writeString(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %16, %14
%21 = tail call i32 (...) @i2c_read_rx_data()
ret i32 %21
}