#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 */
scalar_t__ get_i2c_bit();
int /*<<< orphan*/ write_i2c_bit(unsigned char);
unsigned char read_i2c_byte(unsigned char ack) {
  unsigned char b;
  unsigned char ret = 0;
  for (b = 128; b != 0; b = b >> 1) {
    if (get_i2c_bit())
      ret |= b;
  }
  write_i2c_bit(ack);
  return ret;
}


x86 assembly (clang, -O0):
<read_i2c_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movb   $0x0,-0x3(%rbp)
movb   $0x80,-0x2(%rbp)
movzbl -0x2(%rbp),%eax
cmp    $0x0,%eax
je     1175 <read_i2c_byte+0x55>
mov    $0x0,%al
call   1040 <get_i2c_bit@plt>
cmp    $0x0,%rax
je     1161 <read_i2c_byte+0x41>
movzbl -0x2(%rbp),%ecx
movzbl -0x3(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x3(%rbp)
jmp    1166 <read_i2c_byte+0x46>
movzbl -0x2(%rbp),%eax
sar    $0x1,%eax
mov    %al,-0x2(%rbp)
jmp    1136 <read_i2c_byte+0x16>
movzbl -0x1(%rbp),%edi
call   1030 <write_i2c_bit@plt>
movzbl -0x3(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_i2c_byte>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <get_i2c_bit@plt>
test   %rax,%rax
setne  %r14b
shl    $0x7,%r14b
xor    %eax,%eax
call   1040 <get_i2c_bit@plt>
test   %rax,%rax
setne  %bl
shl    $0x6,%bl
or     %r14b,%bl
xor    %eax,%eax
call   1040 <get_i2c_bit@plt>
test   %rax,%rax
setne  %r14b
shl    $0x5,%r14b
or     %bl,%r14b
xor    %eax,%eax
call   1040 <get_i2c_bit@plt>
test   %rax,%rax
setne  %bl
shl    $0x4,%bl
or     %r14b,%bl
xor    %eax,%eax
call   1040 <get_i2c_bit@plt>
test   %rax,%rax
setne  %r14b
shl    $0x3,%r14b
or     %bl,%r14b
xor    %eax,%eax
call   1040 <get_i2c_bit@plt>
test   %rax,%rax
setne  %r15b
shl    $0x2,%r15b
or     %r14b,%r15b
xor    %eax,%eax
call   1040 <get_i2c_bit@plt>
test   %rax,%rax
setne  %bl
add    %bl,%bl
or     %r15b,%bl
xor    %eax,%eax
call   1040 <get_i2c_bit@plt>
test   %rax,%rax
setne  %r14b
or     %bl,%r14b
mov    %ebp,%edi
call   1030 <write_i2c_bit@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @read_i2c_byte(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
store i8 %0, i8* %2
store i8 0, i8* %4
store i8 -128, i8* %3
br label %5
5: ; preds = %20, %1
%6 = load i8, i8* %3
%7 = zext i8 %6 to i32
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %25
9: ; preds = %5
%10 = call i64 (...) @get_i2c_bit()
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = load i8, i8* %3
%14 = zext i8 %13 to i32
%15 = load i8, i8* %4
%16 = zext i8 %15 to i32
%17 = or i32 %16, %14
%18 = trunc i32 %17 to i8
store i8 %18, i8* %4
br label %19
19: ; preds = %12, %9
br label %20
20: ; preds = %19
%21 = load i8, i8* %3
%22 = zext i8 %21 to i32
%23 = ashr i32 %22, 1
%24 = trunc i32 %23 to i8
store i8 %24, i8* %3
br label %5
25: ; preds = %5
%26 = load i8, i8* %2
%27 = call i32 @write_i2c_bit(i8 zeroext %26)
%28 = load i8, i8* %4
ret i8 %28
}

LLVM IR (-O2):
define zeroext i8 @read_i2c_byte(i8 zeroext %0) {
%2 = tail call i64 (...) @get_i2c_bit()
%3 = icmp eq i64 %2, 0
%4 = select i1 %3, i8 0, i8 -128
%5 = tail call i64 (...) @get_i2c_bit()
%6 = icmp eq i64 %5, 0
%7 = select i1 %6, i8 0, i8 64
%8 = or i8 %7, %4
%9 = tail call i64 (...) @get_i2c_bit()
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i8 0, i8 32
%12 = or i8 %11, %8
%13 = tail call i64 (...) @get_i2c_bit()
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i8 0, i8 16
%16 = or i8 %15, %12
%17 = tail call i64 (...) @get_i2c_bit()
%18 = icmp eq i64 %17, 0
%19 = select i1 %18, i8 0, i8 8
%20 = or i8 %19, %16
%21 = tail call i64 (...) @get_i2c_bit()
%22 = icmp eq i64 %21, 0
%23 = select i1 %22, i8 0, i8 4
%24 = or i8 %23, %20
%25 = tail call i64 (...) @get_i2c_bit()
%26 = icmp eq i64 %25, 0
%27 = select i1 %26, i8 0, i8 2
%28 = or i8 %27, %24
%29 = tail call i64 (...) @get_i2c_bit()
%30 = icmp ne i64 %29, 0
%31 = zext i1 %30 to i8
%32 = or i8 %28, %31
%33 = tail call i32 @write_i2c_bit(i8 zeroext %0)
ret i8 %32
}