#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*/ GPIOPinWrite(int, int, int);
int /*<<< orphan*/ cs5463_write(unsigned char *, int);
void cs5463_read(unsigned char *dat, unsigned char reg) {
  unsigned char i, j;
  cs5463_write(&reg, 1);
  GPIOPinWrite(0x40005000, 0x00000008, 0xff);
  for (j = 0; j < 3; j++) {
    for (i = 0; i < 8; i++) {
      *dat <<= 1;
      GPIOPinWrite(0x40005000, 0x00000002, 0x00);
      GPIOPinWrite(0x40005000, 0x00000002, 0xff);
      if ((GPIOPinRead(0x40005000, 0x00000004) & 0x00000004)) {
        *dat |= 0x01;
      }
    }
    GPIOPinWrite(0x40005000, 0x00000002, 0x00);
    GPIOPinWrite(0x40005000, 0x00000002, 0xff);
    dat++;
  }
}


x86 assembly (clang, -O0):
<cs5463_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
lea    -0x9(%rbp),%rdi
mov    $0x1,%esi
call   1050 <cs5463_write@plt>
mov    $0x40005000,%edi
mov    $0x8,%esi
mov    $0xff,%edx
call   1040 <GPIOPinWrite@plt>
movb   $0x0,-0xb(%rbp)
movzbl -0xb(%rbp),%eax
cmp    $0x3,%eax
jge    122e <cs5463_read+0xfe>
movb   $0x0,-0xa(%rbp)
movzbl -0xa(%rbp),%eax
cmp    $0x8,%eax
jge    11f0 <cs5463_read+0xc0>
mov    -0x8(%rbp),%rax
movzbl (%rax),%ecx
shl    $0x1,%ecx
mov    %cl,(%rax)
mov    $0x40005000,%edi
mov    $0x2,%esi
xor    %edx,%edx
call   1040 <GPIOPinWrite@plt>
mov    $0x40005000,%edi
mov    $0x2,%esi
mov    $0xff,%edx
call   1040 <GPIOPinWrite@plt>
mov    $0x40005000,%edi
mov    $0x4,%esi
call   1030 <GPIOPinRead@plt>
and    $0x4,%eax
cmp    $0x0,%eax
je     11de <cs5463_read+0xae>
mov    -0x8(%rbp),%rax
movzbl (%rax),%ecx
or     $0x1,%ecx
mov    %cl,(%rax)
jmp    11e3 <cs5463_read+0xb3>
mov    -0xa(%rbp),%al
add    $0x1,%al
mov    %al,-0xa(%rbp)
jmp    1179 <cs5463_read+0x49>
mov    $0x40005000,%edi
mov    $0x2,%esi
xor    %edx,%edx
call   1040 <GPIOPinWrite@plt>
mov    $0x40005000,%edi
mov    $0x2,%esi
mov    $0xff,%edx
call   1040 <GPIOPinWrite@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0xb(%rbp),%al
add    $0x1,%al
mov    %al,-0xb(%rbp)
jmp    1168 <cs5463_read+0x38>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cs5463_read>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %sil,0x7(%rsp)
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
call   1050 <cs5463_write@plt>
mov    $0x40005000,%edi
mov    $0x8,%esi
mov    $0xff,%edx
call   1040 <GPIOPinWrite@plt>
mov    $0x8,%bl
jmp    1175 <cs5463_read+0x45>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xff,%bl
je     11b6 <cs5463_read+0x86>
shlb   (%r14)
mov    $0x40005000,%edi
mov    $0x2,%esi
xor    %edx,%edx
call   1040 <GPIOPinWrite@plt>
mov    $0x40005000,%edi
mov    $0x2,%esi
mov    $0xff,%edx
call   1040 <GPIOPinWrite@plt>
mov    $0x40005000,%edi
mov    $0x4,%esi
call   1030 <GPIOPinRead@plt>
test   $0x4,%al
je     1170 <cs5463_read+0x40>
orb    $0x1,(%r14)
jmp    1170 <cs5463_read+0x40>
mov    $0x40005000,%edi
mov    $0x2,%esi
xor    %edx,%edx
call   1040 <GPIOPinWrite@plt>
mov    $0x40005000,%edi
mov    $0x2,%esi
mov    $0xff,%edx
call   1040 <GPIOPinWrite@plt>
mov    $0x8,%bl
jmp    11e5 <cs5463_read+0xb5>
nop
add    $0xff,%bl
je     1228 <cs5463_read+0xf8>
shlb   0x1(%r14)
mov    $0x40005000,%edi
mov    $0x2,%esi
xor    %edx,%edx
call   1040 <GPIOPinWrite@plt>
mov    $0x40005000,%edi
mov    $0x2,%esi
mov    $0xff,%edx
call   1040 <GPIOPinWrite@plt>
mov    $0x40005000,%edi
mov    $0x4,%esi
call   1030 <GPIOPinRead@plt>
test   $0x4,%al
je     11e0 <cs5463_read+0xb0>
orb    $0x1,0x1(%r14)
jmp    11e0 <cs5463_read+0xb0>
mov    $0x40005000,%edi
mov    $0x2,%esi
xor    %edx,%edx
call   1040 <GPIOPinWrite@plt>
mov    $0x40005000,%edi
mov    $0x2,%esi
mov    $0xff,%edx
call   1040 <GPIOPinWrite@plt>
mov    $0x8,%bl
jmp    1265 <cs5463_read+0x135>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xff,%bl
je     12a8 <cs5463_read+0x178>
shlb   0x2(%r14)
mov    $0x40005000,%edi
mov    $0x2,%esi
xor    %edx,%edx
call   1040 <GPIOPinWrite@plt>
mov    $0x40005000,%edi
mov    $0x2,%esi
mov    $0xff,%edx
call   1040 <GPIOPinWrite@plt>
mov    $0x40005000,%edi
mov    $0x4,%esi
call   1030 <GPIOPinRead@plt>
test   $0x4,%al
je     1260 <cs5463_read+0x130>
orb    $0x1,0x2(%r14)
jmp    1260 <cs5463_read+0x130>
mov    $0x40005000,%edi
mov    $0x2,%esi
xor    %edx,%edx
call   1040 <GPIOPinWrite@plt>
mov    $0x40005000,%edi
mov    $0x2,%esi
mov    $0xff,%edx
call   1040 <GPIOPinWrite@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @cs5463_read(i8* %0, i8 zeroext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
store i8* %0, i8** %3
store i8 %1, i8* %4
%7 = call i32 @cs5463_write(i8* %4, i32 1)
%8 = call i32 @GPIOPinWrite(i32 1073762304, i32 8, i32 255)
store i8 0, i8* %6
br label %9
9: ; preds = %44, %2
%10 = load i8, i8* %6
%11 = zext i8 %10 to i32
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %47
13: ; preds = %9
store i8 0, i8* %5
br label %14
14: ; preds = %36, %13
%15 = load i8, i8* %5
%16 = zext i8 %15 to i32
%17 = icmp slt i32 %16, 8
br i1 %17, label %18, label %39
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = shl i32 %21, 1
%23 = trunc i32 %22 to i8
store i8 %23, i8* %19
%24 = call i32 @GPIOPinWrite(i32 1073762304, i32 2, i32 0)
%25 = call i32 @GPIOPinWrite(i32 1073762304, i32 2, i32 255)
%26 = call i32 @GPIOPinRead(i32 1073762304, i32 4)
%27 = and i32 %26, 4
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %18
%30 = load i8*, i8** %3
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = or i32 %32, 1
%34 = trunc i32 %33 to i8
store i8 %34, i8* %30
br label %35
35: ; preds = %29, %18
br label %36
36: ; preds = %35
%37 = load i8, i8* %5
%38 = add i8 %37, 1
store i8 %38, i8* %5
br label %14
39: ; preds = %14
%40 = call i32 @GPIOPinWrite(i32 1073762304, i32 2, i32 0)
%41 = call i32 @GPIOPinWrite(i32 1073762304, i32 2, i32 255)
%42 = load i8*, i8** %3
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %3
br label %44
44: ; preds = %39
%45 = load i8, i8* %6
%46 = add i8 %45, 1
store i8 %46, i8* %6
br label %9
47: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @cs5463_read(i8* nocapture %0, i8 zeroext %1) {
%3 = alloca i8
store i8 %1, i8* %3
%4 = call i32 @cs5463_write(i8* %3, i32 1)
%5 = call i32 @GPIOPinWrite(i32 1073762304, i32 8, i32 255)
br label %6
6: ; preds = %2, %18
%7 = phi i8 [ 0, %2 ], [ %19, %18 ]
%8 = load i8, i8* %0
%9 = shl i8 %8, 1
store i8 %9, i8* %0
%10 = call i32 @GPIOPinWrite(i32 1073762304, i32 2, i32 0)
%11 = call i32 @GPIOPinWrite(i32 1073762304, i32 2, i32 255)
%12 = call i32 @GPIOPinRead(i32 1073762304, i32 4)
%13 = and i32 %12, 4
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %6
%16 = load i8, i8* %0
%17 = or i8 %16, 1
store i8 %17, i8* %0
br label %18
18: ; preds = %6, %15
%19 = add nuw nsw i8 %7, 1
%20 = icmp eq i8 %19, 8
br i1 %20, label %21, label %6
21: ; preds = %18
%22 = call i32 @GPIOPinWrite(i32 1073762304, i32 2, i32 0)
%23 = call i32 @GPIOPinWrite(i32 1073762304, i32 2, i32 255)
%24 = getelementptr inbounds i8, i8* %0, i64 1
br label %25
25: ; preds = %37, %21
%26 = phi i8 [ 0, %21 ], [ %38, %37 ]
%27 = load i8, i8* %24
%28 = shl i8 %27, 1
store i8 %28, i8* %24
%29 = call i32 @GPIOPinWrite(i32 1073762304, i32 2, i32 0)
%30 = call i32 @GPIOPinWrite(i32 1073762304, i32 2, i32 255)
%31 = call i32 @GPIOPinRead(i32 1073762304, i32 4)
%32 = and i32 %31, 4
%33 = icmp eq i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %25
%35 = load i8, i8* %24
%36 = or i8 %35, 1
store i8 %36, i8* %24
br label %37
37: ; preds = %34, %25
%38 = add nuw nsw i8 %26, 1
%39 = icmp eq i8 %38, 8
br i1 %39, label %40, label %25
40: ; preds = %37
%41 = call i32 @GPIOPinWrite(i32 1073762304, i32 2, i32 0)
%42 = call i32 @GPIOPinWrite(i32 1073762304, i32 2, i32 255)
%43 = getelementptr inbounds i8, i8* %0, i64 2
br label %44
44: ; preds = %56, %40
%45 = phi i8 [ 0, %40 ], [ %57, %56 ]
%46 = load i8, i8* %43
%47 = shl i8 %46, 1
store i8 %47, i8* %43
%48 = call i32 @GPIOPinWrite(i32 1073762304, i32 2, i32 0)
%49 = call i32 @GPIOPinWrite(i32 1073762304, i32 2, i32 255)
%50 = call i32 @GPIOPinRead(i32 1073762304, i32 4)
%51 = and i32 %50, 4
%52 = icmp eq i32 %51, 0
br i1 %52, label %56, label %53
53: ; preds = %44
%54 = load i8, i8* %43
%55 = or i8 %54, 1
store i8 %55, i8* %43
br label %56
56: ; preds = %53, %44
%57 = add nuw nsw i8 %45, 1
%58 = icmp eq i8 %57, 8
br i1 %58, label %59, label %44
59: ; preds = %56
%60 = call i32 @GPIOPinWrite(i32 1073762304, i32 2, i32 0)
%61 = call i32 @GPIOPinWrite(i32 1073762304, i32 2, i32 255)
ret void
}