#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*/ _delay_us(int);
int check_bit();
int /*<<< orphan*/ clear_SDA();
int /*<<< orphan*/ set_SDA_input();
int /*<<< orphan*/ write_to_port(int);
int read_byte(void) {
  int byte = 0b00000000;
  int bit;
  set_SDA_input();
  clear_SDA();
  _delay_us(1);
  int i;
  for (i = 0; i < 7; i++) {
    bit = check_bit();
    byte |= bit;
    byte <<= 1;
    _delay_us(1);
  }
  bit = check_bit();
  byte |= bit;
  write_to_port(byte);
  _delay_us(1);
  return (byte);
}


x86 assembly (clang, -O0):
<read_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <set_SDA_input@plt>
mov    $0x0,%al
call   1060 <clear_SDA@plt>
mov    $0x1,%edi
call   1050 <_delay_us@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x7,-0xc(%rbp)
jge    11bc <read_byte+0x6c>
mov    $0x0,%al
call   1040 <check_bit@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    $0x1,%edi
call   1050 <_delay_us@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117e <read_byte+0x2e>
mov    $0x0,%al
call   1040 <check_bit@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1070 <write_to_port@plt>
mov    $0x1,%edi
call   1050 <_delay_us@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_byte>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1030 <set_SDA_input@plt>
xor    %eax,%eax
call   1060 <clear_SDA@plt>
mov    $0x1,%edi
call   1050 <_delay_us@plt>
xor    %eax,%eax
call   1040 <check_bit@plt>
mov    %eax,%ebx
mov    $0x1,%edi
call   1050 <_delay_us@plt>
xor    %eax,%eax
call   1040 <check_bit@plt>
mov    %eax,%ebp
shl    $0x2,%ebx
add    %eax,%ebp
or     %ebx,%ebp
mov    $0x1,%edi
call   1050 <_delay_us@plt>
xor    %eax,%eax
call   1040 <check_bit@plt>
mov    %eax,%ebx
or     %ebp,%ebx
mov    $0x1,%edi
call   1050 <_delay_us@plt>
xor    %eax,%eax
call   1040 <check_bit@plt>
mov    %eax,%r14d
shl    $0x2,%ebx
add    %eax,%r14d
mov    $0x1,%edi
call   1050 <_delay_us@plt>
xor    %eax,%eax
call   1040 <check_bit@plt>
mov    %eax,%ebp
or     %r14d,%ebp
or     %ebx,%ebp
mov    $0x1,%edi
call   1050 <_delay_us@plt>
xor    %eax,%eax
call   1040 <check_bit@plt>
mov    %eax,%r14d
shl    $0x2,%ebp
add    %eax,%r14d
mov    $0x1,%edi
call   1050 <_delay_us@plt>
xor    %eax,%eax
call   1040 <check_bit@plt>
mov    %eax,%ebx
or     %r14d,%ebx
or     %ebp,%ebx
add    %ebx,%ebx
mov    $0x1,%edi
call   1050 <_delay_us@plt>
xor    %eax,%eax
call   1040 <check_bit@plt>
mov    %eax,%ebp
or     %ebx,%ebp
mov    %ebp,%edi
call   1070 <write_to_port@plt>
mov    $0x1,%edi
call   1050 <_delay_us@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_byte() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @set_SDA_input()
%5 = call i32 (...) @clear_SDA()
%6 = call i32 @_delay_us(i32 1)
store i32 0, i32* %3
br label %7
7: ; preds = %18, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 7
br i1 %9, label %10, label %21
10: ; preds = %7
%11 = call i32 (...) @check_bit()
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = load i32, i32* %1
%14 = or i32 %13, %12
store i32 %14, i32* %1
%15 = load i32, i32* %1
%16 = shl i32 %15, 1
store i32 %16, i32* %1
%17 = call i32 @_delay_us(i32 1)
br label %18
18: ; preds = %10
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %7
21: ; preds = %7
%22 = call i32 (...) @check_bit()
store i32 %22, i32* %2
%23 = load i32, i32* %2
%24 = load i32, i32* %1
%25 = or i32 %24, %23
store i32 %25, i32* %1
%26 = load i32, i32* %1
%27 = call i32 @write_to_port(i32 %26)
%28 = call i32 @_delay_us(i32 1)
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
define i32 @read_byte() {
%1 = tail call i32 (...) @set_SDA_input()
%2 = tail call i32 (...) @clear_SDA()
%3 = tail call i32 @_delay_us(i32 1)
%4 = tail call i32 (...) @check_bit()
%5 = tail call i32 @_delay_us(i32 1)
%6 = tail call i32 (...) @check_bit()
%7 = shl i32 %4, 2
%8 = shl i32 %6, 1
%9 = or i32 %7, %8
%10 = tail call i32 @_delay_us(i32 1)
%11 = tail call i32 (...) @check_bit()
%12 = or i32 %11, %9
%13 = tail call i32 @_delay_us(i32 1)
%14 = tail call i32 (...) @check_bit()
%15 = shl i32 %12, 2
%16 = shl i32 %14, 1
%17 = or i32 %15, %16
%18 = tail call i32 @_delay_us(i32 1)
%19 = tail call i32 (...) @check_bit()
%20 = or i32 %19, %17
%21 = tail call i32 @_delay_us(i32 1)
%22 = tail call i32 (...) @check_bit()
%23 = shl i32 %20, 2
%24 = shl i32 %22, 1
%25 = or i32 %23, %24
%26 = tail call i32 @_delay_us(i32 1)
%27 = tail call i32 (...) @check_bit()
%28 = or i32 %27, %25
%29 = shl i32 %28, 1
%30 = tail call i32 @_delay_us(i32 1)
%31 = tail call i32 (...) @check_bit()
%32 = or i32 %31, %29
%33 = tail call i32 @write_to_port(i32 %32)
%34 = tail call i32 @_delay_us(i32 1)
ret i32 %32
}