#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 /*<<< orphan*/ i2c_delay();
int /*<<< orphan*/ scl_high();
int /*<<< orphan*/ scl_low();
int /*<<< orphan*/ sda_input();
int /*<<< orphan*/ sda_output();
scalar_t__ sda_read();
unsigned int i2c_read_byte(unsigned int *b) {
  unsigned int ra;
  unsigned int rb;
  i2c_delay();
  sda_input();
  rb = 0;
  for (ra = 0; ra < 9; ra++) {
    i2c_delay();
    scl_high();
    i2c_delay();
    rb <<= 1;
    if (sda_read())
      rb |= 1;
    i2c_delay();
    scl_low();
    i2c_delay();
  }
  sda_output();
  i2c_delay();
  ra = rb & 1;
  *b = rb >> 1;
  return (ra);
}


x86 assembly (clang, -O0):
<i2c_read_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <i2c_delay@plt>
mov    $0x0,%al
call   1080 <sda_input@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x9,-0xc(%rbp)
jae    11ed <i2c_read_byte+0x8d>
mov    $0x0,%al
call   1050 <i2c_delay@plt>
mov    $0x0,%al
call   1030 <scl_high@plt>
mov    $0x0,%al
call   1050 <i2c_delay@plt>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <sda_read@plt>
cmp    $0x0,%rax
je     11ca <i2c_read_byte+0x6a>
mov    -0x10(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <i2c_delay@plt>
mov    $0x0,%al
call   1070 <scl_low@plt>
mov    $0x0,%al
call   1050 <i2c_delay@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1188 <i2c_read_byte+0x28>
mov    $0x0,%al
call   1060 <sda_output@plt>
mov    $0x0,%al
call   1050 <i2c_delay@plt>
mov    -0x10(%rbp),%eax
and    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%ecx
shr    $0x1,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2c_read_byte>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1080 <sda_input@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1030 <scl_high@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1040 <sda_read@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1070 <scl_low@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1030 <scl_high@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1040 <sda_read@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rcx,%rbx,2),%ebx
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1070 <scl_low@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1030 <scl_high@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1040 <sda_read@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1070 <scl_low@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1030 <scl_high@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
add    %ebp,%ebp
lea    0x0(%rbp,%rbx,4),%ebp
xor    %eax,%eax
call   1040 <sda_read@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
or     %ebp,%ebx
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1070 <scl_low@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1030 <scl_high@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1040 <sda_read@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1070 <scl_low@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1030 <scl_high@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
add    %ebp,%ebp
lea    0x0(%rbp,%rbx,4),%ebp
xor    %eax,%eax
call   1040 <sda_read@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
or     %ebp,%ebx
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1070 <scl_low@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1030 <scl_high@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1040 <sda_read@plt>
xor    %r15d,%r15d
test   %rax,%rax
setne  %r15b
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1070 <scl_low@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1030 <scl_high@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
add    %r15d,%r15d
xor    %eax,%eax
call   1040 <sda_read@plt>
xor    %r12d,%r12d
test   %rax,%rax
setne  %r12b
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1070 <scl_low@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1030 <scl_high@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1040 <sda_read@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1070 <scl_low@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
xor    %eax,%eax
call   1060 <sda_output@plt>
xor    %eax,%eax
call   1050 <i2c_delay@plt>
and    $0x1fffffff,%ebx
lea    (%r15,%rbx,4),%eax
or     %r12d,%eax
mov    %eax,(%r14)
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @i2c_read_byte(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
%5 = call i32 (...) @i2c_delay()
%6 = call i32 (...) @sda_input()
store i32 0, i32* %4
store i32 0, i32* %3
br label %7
7: ; preds = %25, %1
%8 = load i32, i32* %3
%9 = icmp ult i32 %8, 9
br i1 %9, label %10, label %28
10: ; preds = %7
%11 = call i32 (...) @i2c_delay()
%12 = call i32 (...) @scl_high()
%13 = call i32 (...) @i2c_delay()
%14 = load i32, i32* %4
%15 = shl i32 %14, 1
store i32 %15, i32* %4
%16 = call i64 (...) @sda_read()
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = load i32, i32* %4
%20 = or i32 %19, 1
store i32 %20, i32* %4
br label %21
21: ; preds = %18, %10
%22 = call i32 (...) @i2c_delay()
%23 = call i32 (...) @scl_low()
%24 = call i32 (...) @i2c_delay()
br label %25
25: ; preds = %21
%26 = load i32, i32* %3
%27 = add i32 %26, 1
store i32 %27, i32* %3
br label %7
28: ; preds = %7
%29 = call i32 (...) @sda_output()
%30 = call i32 (...) @i2c_delay()
%31 = load i32, i32* %4
%32 = and i32 %31, 1
store i32 %32, i32* %3
%33 = load i32, i32* %4
%34 = lshr i32 %33, 1
%35 = load i32*, i32** %2
store i32 %34, i32* %35
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
define i32 @i2c_read_byte(i32* nocapture writeonly %0) {
%2 = tail call i32 (...) @i2c_delay()
%3 = tail call i32 (...) @sda_input()
%4 = tail call i32 (...) @i2c_delay()
%5 = tail call i32 (...) @scl_high()
%6 = tail call i32 (...) @i2c_delay()
%7 = tail call i64 (...) @sda_read()
%8 = icmp eq i64 %7, 0
%9 = tail call i32 (...) @i2c_delay()
%10 = tail call i32 (...) @scl_low()
%11 = tail call i32 (...) @i2c_delay()
%12 = tail call i32 (...) @i2c_delay()
%13 = tail call i32 (...) @scl_high()
%14 = tail call i32 (...) @i2c_delay()
%15 = select i1 %8, i32 0, i32 2
%16 = tail call i64 (...) @sda_read()
%17 = icmp ne i64 %16, 0
%18 = zext i1 %17 to i32
%19 = or i32 %15, %18
%20 = tail call i32 (...) @i2c_delay()
%21 = tail call i32 (...) @scl_low()
%22 = tail call i32 (...) @i2c_delay()
%23 = tail call i32 (...) @i2c_delay()
%24 = tail call i32 (...) @scl_high()
%25 = tail call i32 (...) @i2c_delay()
%26 = tail call i64 (...) @sda_read()
%27 = icmp eq i64 %26, 0
%28 = tail call i32 (...) @i2c_delay()
%29 = tail call i32 (...) @scl_low()
%30 = tail call i32 (...) @i2c_delay()
%31 = tail call i32 (...) @i2c_delay()
%32 = tail call i32 (...) @scl_high()
%33 = tail call i32 (...) @i2c_delay()
%34 = shl nuw nsw i32 %19, 2
%35 = select i1 %27, i32 0, i32 2
%36 = or i32 %34, %35
%37 = tail call i64 (...) @sda_read()
%38 = icmp ne i64 %37, 0
%39 = zext i1 %38 to i32
%40 = or i32 %36, %39
%41 = tail call i32 (...) @i2c_delay()
%42 = tail call i32 (...) @scl_low()
%43 = tail call i32 (...) @i2c_delay()
%44 = tail call i32 (...) @i2c_delay()
%45 = tail call i32 (...) @scl_high()
%46 = tail call i32 (...) @i2c_delay()
%47 = tail call i64 (...) @sda_read()
%48 = icmp eq i64 %47, 0
%49 = tail call i32 (...) @i2c_delay()
%50 = tail call i32 (...) @scl_low()
%51 = tail call i32 (...) @i2c_delay()
%52 = tail call i32 (...) @i2c_delay()
%53 = tail call i32 (...) @scl_high()
%54 = tail call i32 (...) @i2c_delay()
%55 = shl nuw nsw i32 %40, 2
%56 = select i1 %48, i32 0, i32 2
%57 = or i32 %55, %56
%58 = tail call i64 (...) @sda_read()
%59 = icmp ne i64 %58, 0
%60 = zext i1 %59 to i32
%61 = or i32 %57, %60
%62 = tail call i32 (...) @i2c_delay()
%63 = tail call i32 (...) @scl_low()
%64 = tail call i32 (...) @i2c_delay()
%65 = tail call i32 (...) @i2c_delay()
%66 = tail call i32 (...) @scl_high()
%67 = tail call i32 (...) @i2c_delay()
%68 = tail call i64 (...) @sda_read()
%69 = icmp eq i64 %68, 0
%70 = tail call i32 (...) @i2c_delay()
%71 = tail call i32 (...) @scl_low()
%72 = tail call i32 (...) @i2c_delay()
%73 = tail call i32 (...) @i2c_delay()
%74 = tail call i32 (...) @scl_high()
%75 = tail call i32 (...) @i2c_delay()
%76 = shl i32 %61, 2
%77 = select i1 %69, i32 0, i32 2
%78 = tail call i64 (...) @sda_read()
%79 = icmp ne i64 %78, 0
%80 = zext i1 %79 to i32
%81 = tail call i32 (...) @i2c_delay()
%82 = tail call i32 (...) @scl_low()
%83 = tail call i32 (...) @i2c_delay()
%84 = tail call i32 (...) @i2c_delay()
%85 = tail call i32 (...) @scl_high()
%86 = tail call i32 (...) @i2c_delay()
%87 = tail call i64 (...) @sda_read()
%88 = icmp ne i64 %87, 0
%89 = zext i1 %88 to i32
%90 = tail call i32 (...) @i2c_delay()
%91 = tail call i32 (...) @scl_low()
%92 = tail call i32 (...) @i2c_delay()
%93 = tail call i32 (...) @sda_output()
%94 = tail call i32 (...) @i2c_delay()
%95 = and i32 %76, 2147483644
%96 = or i32 %95, %77
%97 = or i32 %96, %80
store i32 %97, i32* %0
ret i32 %89
}