#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 int ads_read_count(unsigned int count) {
  unsigned char i = 0;
  unsigned int temp = 0;
  GPIOPinTypeGPIOInput(0x40007000, 0x00000040);
  for (i = 0; i < count; 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):
<ads_read_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x0,-0x5(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x40007000,%edi
mov    $0x40,%esi
call   1030 <GPIOPinTypeGPIOInput@plt>
movb   $0x0,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    11da <ads_read_count+0x9a>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0xc(%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     11c8 <ads_read_count+0x88>
mov    -0xc(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11cd <ads_read_count+0x8d>
mov    -0x5(%rbp),%al
add    $0x1,%al
mov    %al,-0x5(%rbp)
jmp    1169 <ads_read_count+0x29>
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    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ads_read_count>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    $0x40007000,%edi
mov    $0x40,%esi
call   1030 <GPIOPinTypeGPIOInput@plt>
xor    %ebx,%ebx
test   %r14d,%r14d
je     11a9 <ads_read_count+0x69>
mov    $0x1,%bpl
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    $0x6,%eax
and    $0x1,%eax
lea    (%rax,%rbx,2),%ebx
movzbl %bpl,%eax
lea    0x1(%rax),%ebp
cmp    %r14d,%eax
jb     1160 <ads_read_count+0x20>
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
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @ads_read_count(i32 %0) {
%2 = tail call i32 @GPIOPinTypeGPIOInput(i32 1073770496, i32 64)
%3 = icmp eq i32 %0, 0
br i1 %3, label %17, label %4
4: ; preds = %1, %4
%5 = phi i32 [ %13, %4 ], [ 0, %1 ]
%6 = phi i8 [ %14, %4 ], [ 0, %1 ]
%7 = shl i32 %5, 1
%8 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 0)
%9 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 255)
%10 = tail call i32 @GPIOPinRead(i32 1073770496, i32 64)
%11 = lshr i32 %10, 6
%12 = and i32 %11, 1
%13 = or i32 %12, %7
%14 = add i8 %6, 1
%15 = zext i8 %14 to i32
%16 = icmp ult i32 %15, %0
br i1 %16, label %4, label %17
17: ; preds = %4, %1
%18 = phi i32 [ 0, %1 ], [ %13, %4 ]
%19 = tail call i32 @GPIOPinTypeGPIOOutput(i32 1073770496, i32 64)
%20 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 0)
%21 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 64, i32 0)
%22 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 255)
%23 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 128, i32 0)
%24 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 64, i32 255)
ret i32 %18
}