#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*/ I2CBitDly();
int /*<<< orphan*/ I2CSCLHigh();
int /*<<< orphan*/ SCL_Down();
int /*<<< orphan*/ SDA_Down();
scalar_t__ SDA_Read();
int /*<<< orphan*/ SDA_Up();
unsigned char I2CGetByte(unsigned char lastone) {
  register unsigned char i, res;
  res = 0;
  for (i = 0; i < 8; i++) {
    I2CSCLHigh();
    I2CBitDly();
    res <<= 1;
    if (SDA_Read())
      res |= 1;
    SCL_Down();
    I2CBitDly();
  }
  if (lastone)
    SDA_Up();
  else
    SDA_Down();
  I2CSCLHigh();
  I2CBitDly();
  SCL_Down();
  I2CBitDly();
  SDA_Up();
  I2CBitDly();
  return (res);
}


x86 assembly (clang, -O0):
<I2CGetByte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movb   $0x0,-0x3(%rbp)
movb   $0x0,-0x2(%rbp)
movzbl -0x2(%rbp),%eax
cmp    $0x8,%eax
jge    11d1 <I2CGetByte+0x71>
mov    $0x0,%al
call   1040 <I2CSCLHigh@plt>
mov    $0x0,%al
call   1030 <I2CBitDly@plt>
movzbl -0x3(%rbp),%eax
shl    $0x1,%eax
mov    %al,-0x3(%rbp)
mov    $0x0,%al
call   1050 <SDA_Read@plt>
cmp    $0x0,%rax
je     11b6 <I2CGetByte+0x56>
movzbl -0x3(%rbp),%eax
or     $0x1,%eax
mov    %al,-0x3(%rbp)
mov    $0x0,%al
call   1060 <SCL_Down@plt>
mov    $0x0,%al
call   1030 <I2CBitDly@plt>
mov    -0x2(%rbp),%al
add    $0x1,%al
mov    %al,-0x2(%rbp)
jmp    1176 <I2CGetByte+0x16>
cmpb   $0x0,-0x1(%rbp)
je     11e7 <I2CGetByte+0x87>
mov    $0x0,%al
call   1070 <SDA_Up@plt>
jmp    11ee <I2CGetByte+0x8e>
mov    $0x0,%al
call   1080 <SDA_Down@plt>
mov    $0x0,%al
call   1040 <I2CSCLHigh@plt>
mov    $0x0,%al
call   1030 <I2CBitDly@plt>
mov    $0x0,%al
call   1060 <SCL_Down@plt>
mov    $0x0,%al
call   1030 <I2CBitDly@plt>
mov    $0x0,%al
call   1070 <SDA_Up@plt>
mov    $0x0,%al
call   1030 <I2CBitDly@plt>
movzbl -0x3(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<I2CGetByte>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,0x4(%rsp)
xor    %eax,%eax
call   1040 <I2CSCLHigh@plt>
xor    %eax,%eax
call   1030 <I2CBitDly@plt>
xor    %eax,%eax
call   1050 <SDA_Read@plt>
mov    %rax,0x10(%rsp)
xor    %eax,%eax
call   1060 <SCL_Down@plt>
xor    %eax,%eax
call   1030 <I2CBitDly@plt>
xor    %eax,%eax
call   1040 <I2CSCLHigh@plt>
xor    %eax,%eax
call   1030 <I2CBitDly@plt>
xor    %eax,%eax
call   1050 <SDA_Read@plt>
mov    %rax,0x8(%rsp)
xor    %eax,%eax
call   1060 <SCL_Down@plt>
xor    %eax,%eax
call   1030 <I2CBitDly@plt>
xor    %eax,%eax
call   1040 <I2CSCLHigh@plt>
xor    %eax,%eax
call   1030 <I2CBitDly@plt>
xor    %eax,%eax
call   1050 <SDA_Read@plt>
mov    %rax,%r13
xor    %eax,%eax
call   1060 <SCL_Down@plt>
xor    %eax,%eax
call   1030 <I2CBitDly@plt>
xor    %eax,%eax
call   1040 <I2CSCLHigh@plt>
xor    %eax,%eax
call   1030 <I2CBitDly@plt>
xor    %eax,%eax
call   1050 <SDA_Read@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <SCL_Down@plt>
xor    %eax,%eax
call   1030 <I2CBitDly@plt>
xor    %eax,%eax
call   1040 <I2CSCLHigh@plt>
xor    %eax,%eax
call   1030 <I2CBitDly@plt>
xor    %eax,%eax
call   1050 <SDA_Read@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1060 <SCL_Down@plt>
xor    %eax,%eax
call   1030 <I2CBitDly@plt>
xor    %eax,%eax
call   1040 <I2CSCLHigh@plt>
xor    %eax,%eax
call   1030 <I2CBitDly@plt>
xor    %eax,%eax
call   1050 <SDA_Read@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1060 <SCL_Down@plt>
xor    %eax,%eax
call   1030 <I2CBitDly@plt>
xor    %eax,%eax
call   1040 <I2CSCLHigh@plt>
xor    %eax,%eax
call   1030 <I2CBitDly@plt>
xor    %eax,%eax
call   1050 <SDA_Read@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1060 <SCL_Down@plt>
xor    %eax,%eax
call   1030 <I2CBitDly@plt>
xor    %eax,%eax
call   1040 <I2CSCLHigh@plt>
xor    %eax,%eax
call   1030 <I2CBitDly@plt>
xor    %eax,%eax
call   1050 <SDA_Read@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1060 <SCL_Down@plt>
xor    %eax,%eax
call   1030 <I2CBitDly@plt>
cmpl   $0x0,0x4(%rsp)
je     12b6 <I2CGetByte+0x156>
xor    %eax,%eax
call   1070 <SDA_Up@plt>
jmp    12bd <I2CGetByte+0x15d>
xor    %eax,%eax
call   1080 <SDA_Down@plt>
cmpq   $0x0,0x10(%rsp)
setne  %al
add    %al,%al
cmpq   $0x0,0x8(%rsp)
setne  %cl
or     %al,%cl
shl    $0x2,%cl
test   %r13,%r13
setne  %al
add    %al,%al
or     %cl,%al
test   %rbx,%rbx
setne  %cl
or     %al,%cl
shl    $0x2,%cl
test   %rbp,%rbp
setne  %al
add    %al,%al
or     %cl,%al
test   %r14,%r14
setne  %cl
or     %al,%cl
shl    $0x2,%cl
test   %r15,%r15
setne  %al
add    %al,%al
or     %cl,%al
test   %r12,%r12
setne  %bl
or     %al,%bl
xor    %eax,%eax
call   1040 <I2CSCLHigh@plt>
xor    %eax,%eax
call   1030 <I2CBitDly@plt>
xor    %eax,%eax
call   1060 <SCL_Down@plt>
xor    %eax,%eax
call   1030 <I2CBitDly@plt>
xor    %eax,%eax
call   1070 <SDA_Up@plt>
xor    %eax,%eax
call   1030 <I2CBitDly@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @I2CGetByte(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
store i8 %0, i8* %2
store i8 0, i8* %4
store i8 0, i8* %3
br label %5
5: ; preds = %26, %1
%6 = load i8, i8* %3
%7 = zext i8 %6 to i32
%8 = icmp slt i32 %7, 8
br i1 %8, label %9, label %29
9: ; preds = %5
%10 = call i32 (...) @I2CSCLHigh()
%11 = call i32 (...) @I2CBitDly()
%12 = load i8, i8* %4
%13 = zext i8 %12 to i32
%14 = shl i32 %13, 1
%15 = trunc i32 %14 to i8
store i8 %15, i8* %4
%16 = call i64 (...) @SDA_Read()
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %9
%19 = load i8, i8* %4
%20 = zext i8 %19 to i32
%21 = or i32 %20, 1
%22 = trunc i32 %21 to i8
store i8 %22, i8* %4
br label %23
23: ; preds = %18, %9
%24 = call i32 (...) @SCL_Down()
%25 = call i32 (...) @I2CBitDly()
br label %26
26: ; preds = %23
%27 = load i8, i8* %3
%28 = add i8 %27, 1
store i8 %28, i8* %3
br label %5
29: ; preds = %5
%30 = load i8, i8* %2
%31 = icmp ne i8 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 (...) @SDA_Up()
br label %36
34: ; preds = %29
%35 = call i32 (...) @SDA_Down()
br label %36
36: ; preds = %34, %32
%37 = call i32 (...) @I2CSCLHigh()
%38 = call i32 (...) @I2CBitDly()
%39 = call i32 (...) @SCL_Down()
%40 = call i32 (...) @I2CBitDly()
%41 = call i32 (...) @SDA_Up()
%42 = call i32 (...) @I2CBitDly()
%43 = load i8, i8* %4
ret i8 %43
}

LLVM IR (-O2):
define zeroext i8 @I2CGetByte(i8 zeroext %0) {
%2 = tail call i32 (...) @I2CSCLHigh()
%3 = tail call i32 (...) @I2CBitDly()
%4 = tail call i64 (...) @SDA_Read()
%5 = tail call i32 (...) @SCL_Down()
%6 = tail call i32 (...) @I2CBitDly()
%7 = tail call i32 (...) @I2CSCLHigh()
%8 = tail call i32 (...) @I2CBitDly()
%9 = tail call i64 (...) @SDA_Read()
%10 = tail call i32 (...) @SCL_Down()
%11 = tail call i32 (...) @I2CBitDly()
%12 = tail call i32 (...) @I2CSCLHigh()
%13 = tail call i32 (...) @I2CBitDly()
%14 = tail call i64 (...) @SDA_Read()
%15 = tail call i32 (...) @SCL_Down()
%16 = tail call i32 (...) @I2CBitDly()
%17 = tail call i32 (...) @I2CSCLHigh()
%18 = tail call i32 (...) @I2CBitDly()
%19 = tail call i64 (...) @SDA_Read()
%20 = tail call i32 (...) @SCL_Down()
%21 = tail call i32 (...) @I2CBitDly()
%22 = tail call i32 (...) @I2CSCLHigh()
%23 = tail call i32 (...) @I2CBitDly()
%24 = tail call i64 (...) @SDA_Read()
%25 = tail call i32 (...) @SCL_Down()
%26 = tail call i32 (...) @I2CBitDly()
%27 = tail call i32 (...) @I2CSCLHigh()
%28 = tail call i32 (...) @I2CBitDly()
%29 = tail call i64 (...) @SDA_Read()
%30 = tail call i32 (...) @SCL_Down()
%31 = tail call i32 (...) @I2CBitDly()
%32 = tail call i32 (...) @I2CSCLHigh()
%33 = tail call i32 (...) @I2CBitDly()
%34 = tail call i64 (...) @SDA_Read()
%35 = tail call i32 (...) @SCL_Down()
%36 = tail call i32 (...) @I2CBitDly()
%37 = tail call i32 (...) @I2CSCLHigh()
%38 = tail call i32 (...) @I2CBitDly()
%39 = tail call i64 (...) @SDA_Read()
%40 = tail call i32 (...) @SCL_Down()
%41 = tail call i32 (...) @I2CBitDly()
%42 = icmp eq i8 %0, 0
br i1 %42, label %45, label %43
43: ; preds = %1
%44 = tail call i32 (...) @SDA_Up()
br label %47
45: ; preds = %1
%46 = tail call i32 (...) @SDA_Down()
br label %47
47: ; preds = %45, %43
%48 = icmp eq i64 %4, 0
%49 = select i1 %48, i8 0, i8 2
%50 = icmp ne i64 %9, 0
%51 = zext i1 %50 to i8
%52 = or i8 %49, %51
%53 = shl nuw nsw i8 %52, 2
%54 = icmp eq i64 %14, 0
%55 = select i1 %54, i8 0, i8 2
%56 = or i8 %53, %55
%57 = icmp ne i64 %19, 0
%58 = zext i1 %57 to i8
%59 = or i8 %56, %58
%60 = shl nuw nsw i8 %59, 2
%61 = icmp eq i64 %24, 0
%62 = select i1 %61, i8 0, i8 2
%63 = or i8 %60, %62
%64 = icmp ne i64 %29, 0
%65 = zext i1 %64 to i8
%66 = or i8 %63, %65
%67 = shl i8 %66, 2
%68 = icmp eq i64 %34, 0
%69 = select i1 %68, i8 0, i8 2
%70 = or i8 %67, %69
%71 = icmp ne i64 %39, 0
%72 = zext i1 %71 to i8
%73 = or i8 %70, %72
%74 = tail call i32 (...) @I2CSCLHigh()
%75 = tail call i32 (...) @I2CBitDly()
%76 = tail call i32 (...) @SCL_Down()
%77 = tail call i32 (...) @I2CBitDly()
%78 = tail call i32 (...) @SDA_Up()
%79 = tail call i32 (...) @I2CBitDly()
ret i8 %73
}