#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 GPIOPinRead(int, int);
int /*<<< orphan*/ GPIOPinTypeGPIOInput(int, int);
int /*<<< orphan*/ GPIOPinTypeGPIOOutput(int, int);
int /*<<< orphan*/ GPIOPinWrite(int, int, int);
unsigned char iic_read_m() {
  unsigned char i = 0;
  unsigned int temp = 0;
  GPIOPinTypeGPIOInput(0x40007000, 0x00000040);
  for (i = 0; i < 8; i++) {
    temp = temp << 1;
    GPIOPinWrite(0x40007000, 0x00000080, 0x00);
    GPIOPinWrite(0x40007000, 0x00000080, 0xff);
    if ((GPIOPinRead(0x40007000, 0x00000040) & 0x00000040)) {
      temp |= 0x01;
    }
  }
  GPIOPinTypeGPIOOutput(0x40007000, 0x00000040);
  GPIOPinWrite(0x40007000, 0x00000080, 0x00);
  GPIOPinWrite(0x40007000, 0x00000040, 0x00);
  GPIOPinWrite(0x40007000, 0x00000080, 0xff);
  GPIOPinWrite(0x40007000, 0x00000080, 0x00);
  GPIOPinWrite(0x40007000, 0x00000040, 0xff);
  return temp;
}


x86 assembly (clang, -O0):
<iic_read_m>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movb   $0x0,-0x1(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x40007000,%edi
mov    $0x40,%esi
call   1030 <GPIOPinTypeGPIOInput@plt>
movb   $0x0,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
cmp    $0x8,%eax
jge    11d7 <iic_read_m+0x97>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    $0x40007000,%edi
mov    $0x80,%esi
xor    %edx,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x80,%esi
mov    $0xff,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x40,%esi
call   1040 <GPIOPinRead@plt>
and    $0x40,%eax
cmp    $0x0,%eax
je     11c5 <iic_read_m+0x85>
mov    -0x8(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ca <iic_read_m+0x8a>
mov    -0x1(%rbp),%al
add    $0x1,%al
mov    %al,-0x1(%rbp)
jmp    1166 <iic_read_m+0x26>
mov    $0x40007000,%edi
mov    $0x40,%esi
call   1050 <GPIOPinTypeGPIOOutput@plt>
mov    $0x40007000,%edi
mov    $0x80,%esi
xor    %edx,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x40,%esi
xor    %edx,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x80,%esi
mov    $0xff,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x80,%esi
xor    %edx,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x40,%esi
mov    $0xff,%edx
call   1060 <GPIOPinWrite@plt>
mov    -0x8(%rbp),%eax
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iic_read_m>:
push   %rbp
push   %rbx
push   %rax
mov    $0x40007000,%edi
mov    $0x40,%esi
call   1030 <GPIOPinTypeGPIOInput@plt>
mov    $0x40007000,%edi
mov    $0x80,%esi
xor    %edx,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x80,%esi
mov    $0xff,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x40,%esi
call   1040 <GPIOPinRead@plt>
mov    %eax,%ebp
shr    $0x5,%ebp
and    $0x2,%ebp
mov    $0x40007000,%edi
mov    $0x80,%esi
xor    %edx,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x80,%esi
mov    $0xff,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x40,%esi
call   1040 <GPIOPinRead@plt>
mov    %eax,%ebx
shr    $0x6,%ebx
and    $0x1,%ebx
or     %ebp,%ebx
mov    $0x40007000,%edi
mov    $0x80,%esi
xor    %edx,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x80,%esi
mov    $0xff,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x40,%esi
call   1040 <GPIOPinRead@plt>
shr    $0x5,%eax
and    $0x2,%eax
lea    (%rax,%rbx,4),%ebp
mov    $0x40007000,%edi
mov    $0x80,%esi
xor    %edx,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x80,%esi
mov    $0xff,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x40,%esi
call   1040 <GPIOPinRead@plt>
mov    %eax,%ebx
shr    $0x6,%ebx
and    $0x1,%ebx
or     %ebp,%ebx
mov    $0x40007000,%edi
mov    $0x80,%esi
xor    %edx,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x80,%esi
mov    $0xff,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x40,%esi
call   1040 <GPIOPinRead@plt>
shr    $0x5,%eax
and    $0x2,%eax
lea    (%rax,%rbx,4),%ebp
mov    $0x40007000,%edi
mov    $0x80,%esi
xor    %edx,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x80,%esi
mov    $0xff,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x40,%esi
call   1040 <GPIOPinRead@plt>
mov    %eax,%ebx
shr    $0x6,%ebx
and    $0x1,%ebx
or     %ebp,%ebx
mov    $0x40007000,%edi
mov    $0x80,%esi
xor    %edx,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x80,%esi
mov    $0xff,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x40,%esi
call   1040 <GPIOPinRead@plt>
shr    $0x5,%eax
and    $0x2,%eax
lea    (%rax,%rbx,4),%ebp
mov    $0x40007000,%edi
mov    $0x80,%esi
xor    %edx,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x80,%esi
mov    $0xff,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x40,%esi
call   1040 <GPIOPinRead@plt>
mov    %eax,%ebx
shr    $0x6,%ebx
and    $0x1,%ebx
or     %ebp,%ebx
mov    $0x40007000,%edi
mov    $0x40,%esi
call   1050 <GPIOPinTypeGPIOOutput@plt>
mov    $0x40007000,%edi
mov    $0x80,%esi
xor    %edx,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x40,%esi
xor    %edx,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x80,%esi
mov    $0xff,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x80,%esi
xor    %edx,%edx
call   1060 <GPIOPinWrite@plt>
mov    $0x40007000,%edi
mov    $0x40,%esi
mov    $0xff,%edx
call   1060 <GPIOPinWrite@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @iic_read_m() {
%1 = alloca i8
%2 = alloca i32
store i8 0, i8* %1
store i32 0, i32* %2
%3 = call i32 @GPIOPinTypeGPIOInput(i32 1073770496, i32 64)
store i8 0, i8* %1
br label %4
4: ; preds = %20, %0
%5 = load i8, i8* %1
%6 = zext i8 %5 to i32
%7 = icmp slt i32 %6, 8
br i1 %7, label %8, label %23
8: ; preds = %4
%9 = load i32, i32* %2
%10 = shl i32 %9, 1
store i32 %10, i32* %2
%11 = call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 0)
%12 = call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 255)
%13 = call i32 @GPIOPinRead(i32 1073770496, i32 64)
%14 = and i32 %13, 64
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = load i32, i32* %2
%18 = or i32 %17, 1
store i32 %18, i32* %2
br label %19
19: ; preds = %16, %8
br label %20
20: ; preds = %19
%21 = load i8, i8* %1
%22 = add i8 %21, 1
store i8 %22, i8* %1
br label %4
23: ; preds = %4
%24 = call i32 @GPIOPinTypeGPIOOutput(i32 1073770496, i32 64)
%25 = call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 0)
%26 = call i32 @GPIOPinWrite(i32 1073770496, i32 64, i32 0)
%27 = call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 255)
%28 = call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 0)
%29 = call i32 @GPIOPinWrite(i32 1073770496, i32 64, i32 255)
%30 = load i32, i32* %2
%31 = trunc i32 %30 to i8
ret i8 %31
}

LLVM IR (-O2):
define zeroext i8 @iic_read_m() {
%1 = tail call i32 @GPIOPinTypeGPIOInput(i32 1073770496, i32 64)
%2 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 0)
%3 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 255)
%4 = tail call i32 @GPIOPinRead(i32 1073770496, i32 64)
%5 = lshr i32 %4, 5
%6 = and i32 %5, 2
%7 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 0)
%8 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 255)
%9 = tail call i32 @GPIOPinRead(i32 1073770496, i32 64)
%10 = lshr i32 %9, 6
%11 = and i32 %10, 1
%12 = or i32 %11, %6
%13 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 0)
%14 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 255)
%15 = tail call i32 @GPIOPinRead(i32 1073770496, i32 64)
%16 = shl nuw nsw i32 %12, 2
%17 = lshr i32 %15, 5
%18 = and i32 %17, 2
%19 = or i32 %16, %18
%20 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 0)
%21 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 255)
%22 = tail call i32 @GPIOPinRead(i32 1073770496, i32 64)
%23 = lshr i32 %22, 6
%24 = and i32 %23, 1
%25 = or i32 %24, %19
%26 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 0)
%27 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 255)
%28 = tail call i32 @GPIOPinRead(i32 1073770496, i32 64)
%29 = shl nuw nsw i32 %25, 2
%30 = lshr i32 %28, 5
%31 = and i32 %30, 2
%32 = or i32 %29, %31
%33 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 0)
%34 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 255)
%35 = tail call i32 @GPIOPinRead(i32 1073770496, i32 64)
%36 = lshr i32 %35, 6
%37 = and i32 %36, 1
%38 = or i32 %37, %32
%39 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 0)
%40 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 255)
%41 = tail call i32 @GPIOPinRead(i32 1073770496, i32 64)
%42 = shl i32 %38, 2
%43 = lshr i32 %41, 5
%44 = and i32 %43, 2
%45 = or i32 %42, %44
%46 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 0)
%47 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 255)
%48 = tail call i32 @GPIOPinRead(i32 1073770496, i32 64)
%49 = lshr i32 %48, 6
%50 = and i32 %49, 1
%51 = or i32 %50, %45
%52 = tail call i32 @GPIOPinTypeGPIOOutput(i32 1073770496, i32 64)
%53 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 0)
%54 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 64, i32 0)
%55 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 255)
%56 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 0)
%57 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 64, i32 255)
%58 = trunc i32 %51 to i8
ret i8 %58
}