#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_PutByte(unsigned char Byte) {
  signed char Counter;
  for (Counter = 7; Counter >= 0; Counter--) {
    if (Byte & (1 << Counter)) {
      I2C_SDA_HIGH();
    } else {
      I2C_SDA_LOW();
    }
    I2C_SCL_TOGGLE();
  }
  I2C_SDA_HIGH();
  I2C_HAL_delay_10th_usec(47);
  ;
  if (I2C_SCL_HIGH())
    return 0x01;
  I2C_HAL_delay_10th_usec(47);
  ;
  Byte = I2C_HAL_BitRead_I2C_SDA();
  I2C_SCL_LOW();
  I2C_SDA_HIGH();
  if (Byte == 0)
    return 0x00;
  return 0x01;
}


x86 assembly (clang, -O0):
<I2C_PutByte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x2(%rbp)
movb   $0x7,-0x3(%rbp)
movsbl -0x3(%rbp),%eax
cmp    $0x0,%eax
jl     11d2 <I2C_PutByte+0x62>
movzbl -0x2(%rbp),%eax
movsbl -0x3(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11b7 <I2C_PutByte+0x47>
mov    $0x0,%al
call   1070 <I2C_SDA_HIGH@plt>
jmp    11be <I2C_PutByte+0x4e>
mov    $0x0,%al
call   1060 <I2C_SDA_LOW@plt>
mov    $0x0,%al
call   1090 <I2C_SCL_TOGGLE@plt>
mov    -0x3(%rbp),%al
add    $0xff,%al
mov    %al,-0x3(%rbp)
jmp    1182 <I2C_PutByte+0x12>
mov    $0x0,%al
call   1070 <I2C_SDA_HIGH@plt>
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
mov    $0x0,%al
call   1050 <I2C_SCL_HIGH@plt>
cmp    $0x0,%rax
je     11fd <I2C_PutByte+0x8d>
movb   $0x1,-0x1(%rbp)
jmp    1239 <I2C_PutByte+0xc9>
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
mov    $0x0,%al
call   1080 <I2C_HAL_BitRead_I2C_SDA@plt>
mov    %al,-0x2(%rbp)
mov    $0x0,%al
call   1030 <I2C_SCL_LOW@plt>
mov    $0x0,%al
call   1070 <I2C_SDA_HIGH@plt>
movzbl -0x2(%rbp),%eax
cmp    $0x0,%eax
jne    1235 <I2C_PutByte+0xc5>
movb   $0x0,-0x1(%rbp)
jmp    1239 <I2C_PutByte+0xc9>
movb   $0x1,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<I2C_PutByte>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
test   $0x80,%bl
jne    1181 <I2C_PutByte+0x11>
call   1060 <I2C_SDA_LOW@plt>
jmp    1186 <I2C_PutByte+0x16>
call   1070 <I2C_SDA_HIGH@plt>
xor    %eax,%eax
call   1090 <I2C_SCL_TOGGLE@plt>
xor    %eax,%eax
test   $0x40,%bl
jne    119b <I2C_PutByte+0x2b>
call   1060 <I2C_SDA_LOW@plt>
jmp    11a0 <I2C_PutByte+0x30>
call   1070 <I2C_SDA_HIGH@plt>
xor    %eax,%eax
call   1090 <I2C_SCL_TOGGLE@plt>
xor    %eax,%eax
test   $0x20,%bl
jne    11b5 <I2C_PutByte+0x45>
call   1060 <I2C_SDA_LOW@plt>
jmp    11ba <I2C_PutByte+0x4a>
call   1070 <I2C_SDA_HIGH@plt>
xor    %eax,%eax
call   1090 <I2C_SCL_TOGGLE@plt>
xor    %eax,%eax
test   $0x10,%bl
jne    11cf <I2C_PutByte+0x5f>
call   1060 <I2C_SDA_LOW@plt>
jmp    11d4 <I2C_PutByte+0x64>
call   1070 <I2C_SDA_HIGH@plt>
xor    %eax,%eax
call   1090 <I2C_SCL_TOGGLE@plt>
xor    %eax,%eax
test   $0x8,%bl
jne    11e9 <I2C_PutByte+0x79>
call   1060 <I2C_SDA_LOW@plt>
jmp    11ee <I2C_PutByte+0x7e>
call   1070 <I2C_SDA_HIGH@plt>
xor    %eax,%eax
call   1090 <I2C_SCL_TOGGLE@plt>
xor    %eax,%eax
test   $0x4,%bl
jne    1203 <I2C_PutByte+0x93>
call   1060 <I2C_SDA_LOW@plt>
jmp    1208 <I2C_PutByte+0x98>
call   1070 <I2C_SDA_HIGH@plt>
xor    %eax,%eax
call   1090 <I2C_SCL_TOGGLE@plt>
xor    %eax,%eax
test   $0x2,%bl
jne    121d <I2C_PutByte+0xad>
call   1060 <I2C_SDA_LOW@plt>
jmp    1222 <I2C_PutByte+0xb2>
call   1070 <I2C_SDA_HIGH@plt>
xor    %eax,%eax
call   1090 <I2C_SCL_TOGGLE@plt>
xor    %eax,%eax
test   $0x1,%bl
jne    1237 <I2C_PutByte+0xc7>
call   1060 <I2C_SDA_LOW@plt>
jmp    123c <I2C_PutByte+0xcc>
call   1070 <I2C_SDA_HIGH@plt>
xor    %eax,%eax
call   1090 <I2C_SCL_TOGGLE@plt>
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    %rax,%rcx
mov    $0x1,%al
test   %rcx,%rcx
je     1267 <I2C_PutByte+0xf7>
pop    %rbx
ret
mov    $0x2f,%edi
call   1040 <I2C_HAL_delay_10th_usec@plt>
xor    %eax,%eax
call   1080 <I2C_HAL_BitRead_I2C_SDA@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <I2C_SCL_LOW@plt>
xor    %eax,%eax
call   1070 <I2C_SDA_HIGH@plt>
test   %bl,%bl
setne  %al
pop    %rbx
ret

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

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