#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 */
unsigned char I2C_HAL_BitRead_I2C_SDA();
int /*<<< orphan*/ I2C_HAL_delay_10th_usec(int);
scalar_t__ I2C_SCL_HIGH();
int /*<<< orphan*/ I2C_SCL_LOW();
int /*<<< orphan*/ I2C_SCL_TOGGLE();
int /*<<< orphan*/ I2C_SDA_HIGH();
int /*<<< orphan*/ I2C_SDA_LOW();
unsigned char I2C_GetByte(unsigned char Last) {
  signed char Counter;
  unsigned char Val, Byte = 0;
  I2C_SDA_HIGH();
  for (Counter = 7; Counter >= 0; Counter--) {
    I2C_HAL_delay_10th_usec(47);
    ;
    if (I2C_SCL_HIGH())
      return 0x01;
    Val = I2C_HAL_BitRead_I2C_SDA();
    Byte <<= 1;
    if (Val)
      Byte |= 1;
    I2C_HAL_delay_10th_usec(47);
    ;
    I2C_SCL_LOW();
  }
  if (Last)
    I2C_SDA_HIGH();
  else
    I2C_SDA_LOW();
  I2C_SCL_TOGGLE();
  I2C_SDA_HIGH();
  return Byte;
}


x86 assembly (clang, -O0):
<I2C_GetByte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x2(%rbp)
movb   $0x0,-0x5(%rbp)
mov    $0x0,%al
call   1070 <I2C_SDA_HIGH@plt>
movb   $0x7,-0x3(%rbp)
movsbl -0x3(%rbp),%eax
cmp    $0x0,%eax
jl     1204 <I2C_GetByte+0x94>
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
mov    $0x0,%al
call   1050 <I2C_SCL_HIGH@plt>
cmp    $0x0,%rax
je     11be <I2C_GetByte+0x4e>
movb   $0x1,-0x1(%rbp)
jmp    1235 <I2C_GetByte+0xc5>
mov    $0x0,%al
call   1080 <I2C_HAL_BitRead_I2C_SDA@plt>
mov    %al,-0x4(%rbp)
movzbl -0x5(%rbp),%eax
shl    $0x1,%eax
mov    %al,-0x5(%rbp)
cmpb   $0x0,-0x4(%rbp)
je     11e6 <I2C_GetByte+0x76>
movzbl -0x5(%rbp),%eax
or     $0x1,%eax
mov    %al,-0x5(%rbp)
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
mov    $0x0,%al
call   1030 <I2C_SCL_LOW@plt>
mov    -0x3(%rbp),%al
add    $0xff,%al
mov    %al,-0x3(%rbp)
jmp    118d <I2C_GetByte+0x1d>
cmpb   $0x0,-0x2(%rbp)
je     121a <I2C_GetByte+0xaa>
mov    $0x0,%al
call   1070 <I2C_SDA_HIGH@plt>
jmp    1221 <I2C_GetByte+0xb1>
mov    $0x0,%al
call   1060 <I2C_SDA_LOW@plt>
mov    $0x0,%al
call   1090 <I2C_SCL_TOGGLE@plt>
mov    $0x0,%al
call   1070 <I2C_SDA_HIGH@plt>
mov    -0x5(%rbp),%al
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<I2C_GetByte>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %eax,%eax
call   1070 <I2C_SDA_HIGH@plt>
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
xor    %eax,%eax
call   1050 <I2C_SCL_HIGH@plt>
mov    $0x1,%bl
test   %rax,%rax
jne    13b1 <I2C_GetByte+0x241>
xor    %eax,%eax
call   1080 <I2C_HAL_BitRead_I2C_SDA@plt>
mov    %eax,%r14d
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
xor    %eax,%eax
call   1030 <I2C_SCL_LOW@plt>
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
xor    %eax,%eax
call   1050 <I2C_SCL_HIGH@plt>
test   %rax,%rax
jne    13b1 <I2C_GetByte+0x241>
xor    %eax,%eax
call   1080 <I2C_HAL_BitRead_I2C_SDA@plt>
mov    %eax,%r15d
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
xor    %eax,%eax
call   1030 <I2C_SCL_LOW@plt>
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
xor    %eax,%eax
call   1050 <I2C_SCL_HIGH@plt>
test   %rax,%rax
jne    13b1 <I2C_GetByte+0x241>
xor    %eax,%eax
call   1080 <I2C_HAL_BitRead_I2C_SDA@plt>
mov    %eax,%r12d
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
xor    %eax,%eax
call   1030 <I2C_SCL_LOW@plt>
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
xor    %eax,%eax
call   1050 <I2C_SCL_HIGH@plt>
test   %rax,%rax
jne    13b1 <I2C_GetByte+0x241>
xor    %eax,%eax
call   1080 <I2C_HAL_BitRead_I2C_SDA@plt>
mov    %eax,%r13d
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
xor    %eax,%eax
call   1030 <I2C_SCL_LOW@plt>
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
xor    %eax,%eax
call   1050 <I2C_SCL_HIGH@plt>
test   %rax,%rax
jne    13b1 <I2C_GetByte+0x241>
mov    %r13b,0x7(%rsp)
xor    %eax,%eax
call   1080 <I2C_HAL_BitRead_I2C_SDA@plt>
mov    %eax,%r13d
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
xor    %eax,%eax
call   1030 <I2C_SCL_LOW@plt>
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
xor    %eax,%eax
call   1050 <I2C_SCL_HIGH@plt>
test   %rax,%rax
jne    13b1 <I2C_GetByte+0x241>
mov    %r13b,0x6(%rsp)
xor    %eax,%eax
call   1080 <I2C_HAL_BitRead_I2C_SDA@plt>
mov    %eax,%r13d
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
xor    %eax,%eax
call   1030 <I2C_SCL_LOW@plt>
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
xor    %eax,%eax
call   1050 <I2C_SCL_HIGH@plt>
test   %rax,%rax
jne    13b1 <I2C_GetByte+0x241>
xor    %eax,%eax
call   1080 <I2C_HAL_BitRead_I2C_SDA@plt>
mov    %al,0x5(%rsp)
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
xor    %eax,%eax
call   1030 <I2C_SCL_LOW@plt>
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
xor    %eax,%eax
call   1050 <I2C_SCL_HIGH@plt>
test   %rax,%rax
jne    13b1 <I2C_GetByte+0x241>
test   %r14b,%r14b
setne  %al
add    %al,%al
test   %r15b,%r15b
setne  %cl
or     %al,%cl
shl    $0x2,%cl
test   %r12b,%r12b
setne  %al
add    %al,%al
or     %cl,%al
cmpb   $0x0,0x7(%rsp)
setne  %cl
or     %al,%cl
shl    $0x2,%cl
cmpb   $0x0,0x6(%rsp)
setne  %al
add    %al,%al
or     %cl,%al
test   %r13b,%r13b
setne  %r14b
or     %al,%r14b
cmpb   $0x0,0x5(%rsp)
setne  %bl
xor    %eax,%eax
call   1080 <I2C_HAL_BitRead_I2C_SDA@plt>
shl    $0x2,%r14b
add    %bl,%bl
or     %r14b,%bl
test   %al,%al
setne  %r14b
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
xor    %eax,%eax
call   1030 <I2C_SCL_LOW@plt>
xor    %eax,%eax
test   %bpl,%bpl
je     139b <I2C_GetByte+0x22b>
call   1070 <I2C_SDA_HIGH@plt>
jmp    13a0 <I2C_GetByte+0x230>
call   1060 <I2C_SDA_LOW@plt>
or     %r14b,%bl
xor    %eax,%eax
call   1090 <I2C_SCL_TOGGLE@plt>
xor    %eax,%eax
call   1070 <I2C_SDA_HIGH@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @I2C_GetByte(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
store i8 %0, i8* %3
store i8 0, i8* %6
%7 = call i32 (...) @I2C_SDA_HIGH()
store i8 7, i8* %4
br label %8
8: ; preds = %33, %1
%9 = load i8, i8* %4
%10 = sext i8 %9 to i32
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %36
12: ; preds = %8
%13 = call i32 @I2C_HAL_delay_10th_usec(i32 47)
%14 = call i64 (...) @I2C_SCL_HIGH()
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
store i8 1, i8* %2
br label %47
17: ; preds = %12
%18 = call zeroext i8 (...) @I2C_HAL_BitRead_I2C_SDA()
store i8 %18, i8* %5
%19 = load i8, i8* %6
%20 = zext i8 %19 to i32
%21 = shl i32 %20, 1
%22 = trunc i32 %21 to i8
store i8 %22, i8* %6
%23 = load i8, i8* %5
%24 = icmp ne i8 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %17
%26 = load i8, i8* %6
%27 = zext i8 %26 to i32
%28 = or i32 %27, 1
%29 = trunc i32 %28 to i8
store i8 %29, i8* %6
br label %30
30: ; preds = %25, %17
%31 = call i32 @I2C_HAL_delay_10th_usec(i32 47)
%32 = call i32 (...) @I2C_SCL_LOW()
br label %33
33: ; preds = %30
%34 = load i8, i8* %4
%35 = add i8 %34, -1
store i8 %35, i8* %4
br label %8
36: ; preds = %8
%37 = load i8, i8* %3
%38 = icmp ne i8 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 (...) @I2C_SDA_HIGH()
br label %43
41: ; preds = %36
%42 = call i32 (...) @I2C_SDA_LOW()
br label %43
43: ; preds = %41, %39
%44 = call i32 (...) @I2C_SCL_TOGGLE()
%45 = call i32 (...) @I2C_SDA_HIGH()
%46 = load i8, i8* %6
store i8 %46, i8* %2
br label %47
47: ; preds = %43, %16
%48 = load i8, i8* %2
ret i8 %48
}

LLVM IR (-O2):
define zeroext i8 @I2C_GetByte(i8 zeroext %0) {
%2 = tail call i32 (...) @I2C_SDA_HIGH()
%3 = tail call i32 @I2C_HAL_delay_10th_usec(i32 47)
%4 = tail call i64 (...) @I2C_SCL_HIGH()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %93
6: ; preds = %1
%7 = tail call zeroext i8 (...) @I2C_HAL_BitRead_I2C_SDA()
%8 = tail call i32 @I2C_HAL_delay_10th_usec(i32 47)
%9 = tail call i32 (...) @I2C_SCL_LOW()
%10 = tail call i32 @I2C_HAL_delay_10th_usec(i32 47)
%11 = tail call i64 (...) @I2C_SCL_HIGH()
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %93
13: ; preds = %6
%14 = tail call zeroext i8 (...) @I2C_HAL_BitRead_I2C_SDA()
%15 = tail call i32 @I2C_HAL_delay_10th_usec(i32 47)
%16 = tail call i32 (...) @I2C_SCL_LOW()
%17 = tail call i32 @I2C_HAL_delay_10th_usec(i32 47)
%18 = tail call i64 (...) @I2C_SCL_HIGH()
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %93
20: ; preds = %13
%21 = tail call zeroext i8 (...) @I2C_HAL_BitRead_I2C_SDA()
%22 = tail call i32 @I2C_HAL_delay_10th_usec(i32 47)
%23 = tail call i32 (...) @I2C_SCL_LOW()
%24 = tail call i32 @I2C_HAL_delay_10th_usec(i32 47)
%25 = tail call i64 (...) @I2C_SCL_HIGH()
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %93
27: ; preds = %20
%28 = tail call zeroext i8 (...) @I2C_HAL_BitRead_I2C_SDA()
%29 = tail call i32 @I2C_HAL_delay_10th_usec(i32 47)
%30 = tail call i32 (...) @I2C_SCL_LOW()
%31 = tail call i32 @I2C_HAL_delay_10th_usec(i32 47)
%32 = tail call i64 (...) @I2C_SCL_HIGH()
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %93
34: ; preds = %27
%35 = tail call zeroext i8 (...) @I2C_HAL_BitRead_I2C_SDA()
%36 = tail call i32 @I2C_HAL_delay_10th_usec(i32 47)
%37 = tail call i32 (...) @I2C_SCL_LOW()
%38 = tail call i32 @I2C_HAL_delay_10th_usec(i32 47)
%39 = tail call i64 (...) @I2C_SCL_HIGH()
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %93
41: ; preds = %34
%42 = tail call zeroext i8 (...) @I2C_HAL_BitRead_I2C_SDA()
%43 = tail call i32 @I2C_HAL_delay_10th_usec(i32 47)
%44 = tail call i32 (...) @I2C_SCL_LOW()
%45 = tail call i32 @I2C_HAL_delay_10th_usec(i32 47)
%46 = tail call i64 (...) @I2C_SCL_HIGH()
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %93
48: ; preds = %41
%49 = tail call zeroext i8 (...) @I2C_HAL_BitRead_I2C_SDA()
%50 = tail call i32 @I2C_HAL_delay_10th_usec(i32 47)
%51 = tail call i32 (...) @I2C_SCL_LOW()
%52 = tail call i32 @I2C_HAL_delay_10th_usec(i32 47)
%53 = tail call i64 (...) @I2C_SCL_HIGH()
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %93
55: ; preds = %48
%56 = icmp eq i8 %7, 0
%57 = select i1 %56, i8 0, i8 2
%58 = icmp ne i8 %14, 0
%59 = zext i1 %58 to i8
%60 = or i8 %57, %59
%61 = shl nuw nsw i8 %60, 2
%62 = icmp eq i8 %21, 0
%63 = select i1 %62, i8 0, i8 2
%64 = or i8 %61, %63
%65 = icmp ne i8 %28, 0
%66 = zext i1 %65 to i8
%67 = or i8 %64, %66
%68 = shl nuw nsw i8 %67, 2
%69 = icmp eq i8 %35, 0
%70 = select i1 %69, i8 0, i8 2
%71 = or i8 %68, %70
%72 = icmp ne i8 %42, 0
%73 = zext i1 %72 to i8
%74 = or i8 %71, %73
%75 = icmp eq i8 %49, 0
%76 = tail call zeroext i8 (...) @I2C_HAL_BitRead_I2C_SDA()
%77 = shl i8 %74, 2
%78 = select i1 %75, i8 0, i8 2
%79 = or i8 %77, %78
%80 = icmp ne i8 %76, 0
%81 = zext i1 %80 to i8
%82 = or i8 %79, %81
%83 = tail call i32 @I2C_HAL_delay_10th_usec(i32 47)
%84 = tail call i32 (...) @I2C_SCL_LOW()
%85 = icmp eq i8 %0, 0
br i1 %85, label %88, label %86
86: ; preds = %55
%87 = tail call i32 (...) @I2C_SDA_HIGH()
br label %90
88: ; preds = %55
%89 = tail call i32 (...) @I2C_SDA_LOW()
br label %90
90: ; preds = %88, %86
%91 = tail call i32 (...) @I2C_SCL_TOGGLE()
%92 = tail call i32 (...) @I2C_SDA_HIGH()
br label %93
93: ; preds = %1, %6, %13, %20, %27, %34, %41, %48, %90
%94 = phi i8 [ %82, %90 ], [ 1, %48 ], [ 1, %41 ], [ 1, %34 ], [ 1, %27 ], [ 1, %20 ], [ 1, %13 ], [ 1, %6 ], [ 1, %1 ]
ret i8 %94
}