#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 I2CAL_input_data();
int /*<<< orphan*/ I2CAL_output_clock(int);
int /*<<< orphan*/ I2CAL_output_data(int);
int /*<<< orphan*/ I2CAL_set_data_for_input();
int /*<<< orphan*/ I2CAL_set_data_for_output();
unsigned char ReceiveI2CData(void) {
  unsigned char data = 0;
  unsigned char x;
  I2CAL_set_data_for_input();
  I2CAL_output_data(1);
  for (x = 0; x < 8; x++) {
    I2CAL_output_clock(1);
    data <<= 1;
    data |= I2CAL_input_data();
    I2CAL_output_clock(0);
  }
  I2CAL_set_data_for_output();
  I2CAL_output_data(1);
  return data;
}


x86 assembly (clang, -O0):
<ReceiveI2CData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movb   $0x0,-0x1(%rbp)
mov    $0x0,%al
call   1060 <I2CAL_set_data_for_input@plt>
mov    $0x1,%edi
call   1030 <I2CAL_output_data@plt>
movb   $0x0,-0x2(%rbp)
movzbl -0x2(%rbp),%eax
cmp    $0x8,%eax
jge    11b9 <ReceiveI2CData+0x69>
mov    $0x1,%edi
call   1050 <I2CAL_output_clock@plt>
movzbl -0x1(%rbp),%eax
shl    $0x1,%eax
mov    %al,-0x1(%rbp)
mov    $0x0,%al
call   1070 <I2CAL_input_data@plt>
movzbl %al,%ecx
movzbl -0x1(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x1(%rbp)
xor    %edi,%edi
call   1050 <I2CAL_output_clock@plt>
mov    -0x2(%rbp),%al
add    $0x1,%al
mov    %al,-0x2(%rbp)
jmp    1171 <ReceiveI2CData+0x21>
mov    $0x0,%al
call   1040 <I2CAL_set_data_for_output@plt>
mov    $0x1,%edi
call   1030 <I2CAL_output_data@plt>
movzbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReceiveI2CData>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <I2CAL_set_data_for_input@plt>
mov    $0x1,%edi
call   1030 <I2CAL_output_data@plt>
mov    $0x1,%edi
call   1050 <I2CAL_output_clock@plt>
xor    %eax,%eax
call   1070 <I2CAL_input_data@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   1050 <I2CAL_output_clock@plt>
mov    $0x1,%edi
call   1050 <I2CAL_output_clock@plt>
xor    %eax,%eax
call   1070 <I2CAL_input_data@plt>
mov    %eax,%ebx
xor    %edi,%edi
call   1050 <I2CAL_output_clock@plt>
mov    $0x1,%edi
call   1050 <I2CAL_output_clock@plt>
shl    $0x2,%bpl
add    %bl,%bl
or     %bpl,%bl
xor    %eax,%eax
call   1070 <I2CAL_input_data@plt>
mov    %eax,%ebp
or     %bl,%bpl
xor    %edi,%edi
call   1050 <I2CAL_output_clock@plt>
mov    $0x1,%edi
call   1050 <I2CAL_output_clock@plt>
xor    %eax,%eax
call   1070 <I2CAL_input_data@plt>
mov    %eax,%r14d
xor    %edi,%edi
call   1050 <I2CAL_output_clock@plt>
mov    $0x1,%edi
call   1050 <I2CAL_output_clock@plt>
shl    $0x2,%bpl
add    %r14b,%r14b
xor    %eax,%eax
call   1070 <I2CAL_input_data@plt>
mov    %eax,%r15d
or     %r14b,%r15b
or     %bpl,%r15b
xor    %edi,%edi
call   1050 <I2CAL_output_clock@plt>
mov    $0x1,%edi
call   1050 <I2CAL_output_clock@plt>
xor    %eax,%eax
call   1070 <I2CAL_input_data@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   1050 <I2CAL_output_clock@plt>
mov    $0x1,%edi
call   1050 <I2CAL_output_clock@plt>
shl    $0x2,%r15b
add    %bpl,%bpl
xor    %eax,%eax
call   1070 <I2CAL_input_data@plt>
mov    %eax,%ebx
or     %bpl,%bl
or     %r15b,%bl
xor    %edi,%edi
call   1050 <I2CAL_output_clock@plt>
mov    $0x1,%edi
call   1050 <I2CAL_output_clock@plt>
add    %bl,%bl
xor    %eax,%eax
call   1070 <I2CAL_input_data@plt>
mov    %eax,%ebp
or     %bl,%bpl
xor    %edi,%edi
call   1050 <I2CAL_output_clock@plt>
xor    %eax,%eax
call   1040 <I2CAL_set_data_for_output@plt>
mov    $0x1,%edi
call   1030 <I2CAL_output_data@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @ReceiveI2CData() {
%1 = alloca i8
%2 = alloca i8
store i8 0, i8* %1
%3 = call i32 (...) @I2CAL_set_data_for_input()
%4 = call i32 @I2CAL_output_data(i32 1)
store i8 0, i8* %2
br label %5
5: ; preds = %22, %0
%6 = load i8, i8* %2
%7 = zext i8 %6 to i32
%8 = icmp slt i32 %7, 8
br i1 %8, label %9, label %25
9: ; preds = %5
%10 = call i32 @I2CAL_output_clock(i32 1)
%11 = load i8, i8* %1
%12 = zext i8 %11 to i32
%13 = shl i32 %12, 1
%14 = trunc i32 %13 to i8
store i8 %14, i8* %1
%15 = call zeroext i8 (...) @I2CAL_input_data()
%16 = zext i8 %15 to i32
%17 = load i8, i8* %1
%18 = zext i8 %17 to i32
%19 = or i32 %18, %16
%20 = trunc i32 %19 to i8
store i8 %20, i8* %1
%21 = call i32 @I2CAL_output_clock(i32 0)
br label %22
22: ; preds = %9
%23 = load i8, i8* %2
%24 = add i8 %23, 1
store i8 %24, i8* %2
br label %5
25: ; preds = %5
%26 = call i32 (...) @I2CAL_set_data_for_output()
%27 = call i32 @I2CAL_output_data(i32 1)
%28 = load i8, i8* %1
ret i8 %28
}

LLVM IR (-O2):
define zeroext i8 @ReceiveI2CData() {
%1 = tail call i32 (...) @I2CAL_set_data_for_input()
%2 = tail call i32 @I2CAL_output_data(i32 1)
%3 = tail call i32 @I2CAL_output_clock(i32 1)
%4 = tail call zeroext i8 (...) @I2CAL_input_data()
%5 = tail call i32 @I2CAL_output_clock(i32 0)
%6 = tail call i32 @I2CAL_output_clock(i32 1)
%7 = tail call zeroext i8 (...) @I2CAL_input_data()
%8 = tail call i32 @I2CAL_output_clock(i32 0)
%9 = tail call i32 @I2CAL_output_clock(i32 1)
%10 = shl i8 %4, 2
%11 = shl i8 %7, 1
%12 = or i8 %10, %11
%13 = tail call zeroext i8 (...) @I2CAL_input_data()
%14 = or i8 %13, %12
%15 = tail call i32 @I2CAL_output_clock(i32 0)
%16 = tail call i32 @I2CAL_output_clock(i32 1)
%17 = tail call zeroext i8 (...) @I2CAL_input_data()
%18 = tail call i32 @I2CAL_output_clock(i32 0)
%19 = tail call i32 @I2CAL_output_clock(i32 1)
%20 = shl i8 %14, 2
%21 = shl i8 %17, 1
%22 = or i8 %20, %21
%23 = tail call zeroext i8 (...) @I2CAL_input_data()
%24 = or i8 %23, %22
%25 = tail call i32 @I2CAL_output_clock(i32 0)
%26 = tail call i32 @I2CAL_output_clock(i32 1)
%27 = tail call zeroext i8 (...) @I2CAL_input_data()
%28 = tail call i32 @I2CAL_output_clock(i32 0)
%29 = tail call i32 @I2CAL_output_clock(i32 1)
%30 = shl i8 %24, 2
%31 = shl i8 %27, 1
%32 = or i8 %30, %31
%33 = tail call zeroext i8 (...) @I2CAL_input_data()
%34 = or i8 %33, %32
%35 = tail call i32 @I2CAL_output_clock(i32 0)
%36 = tail call i32 @I2CAL_output_clock(i32 1)
%37 = shl i8 %34, 1
%38 = tail call zeroext i8 (...) @I2CAL_input_data()
%39 = or i8 %38, %37
%40 = tail call i32 @I2CAL_output_clock(i32 0)
%41 = tail call i32 (...) @I2CAL_set_data_for_output()
%42 = tail call i32 @I2CAL_output_data(i32 1)
ret i8 %39
}