#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 /*<<< orphan*/ Dorado9211ClearCS();
int /*<<< orphan*/ Dorado9211ClearDataOut();
unsigned char Dorado9211ReadDataIn();
int /*<<< orphan*/ Dorado9211SetCS();
int /*<<< orphan*/ Dorado9211SetDataOut();
int /*<<< orphan*/ Dorado9211ToggleClock();
unsigned long Dorado9211ReadReg(unsigned short index) {
  unsigned char i, readbit;
  unsigned long data;
  Dorado9211ClearDataOut();
  Dorado9211SetCS();
  Dorado9211ToggleClock();
  Dorado9211SetDataOut();
  Dorado9211ToggleClock();
  for (i = 0; i < 12; i++) {
    if (index & 0x1) {
      Dorado9211SetDataOut();
    } else {
      Dorado9211ClearDataOut();
    }
    Dorado9211ToggleClock();
    index >>= 1;
  }
  Dorado9211ClearDataOut();
  Dorado9211ToggleClock();
  Dorado9211ToggleClock();
  Dorado9211ToggleClock();
  Dorado9211ToggleClock();
  Dorado9211ToggleClock();
  Dorado9211ToggleClock();
  Dorado9211ToggleClock();
  Dorado9211ToggleClock();
  data = 0;
  for (i = 0; i < 32; i++) {
    Dorado9211ToggleClock();
    readbit = Dorado9211ReadDataIn();
    data |= (((unsigned long)readbit) << i);
  }
  Dorado9211ClearCS();
  Dorado9211ToggleClock();
  return (data);
}


x86 assembly (clang, -O0):
<Dorado9211ReadReg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    $0x0,%al
call   1070 <Dorado9211ClearDataOut@plt>
mov    $0x0,%al
call   1060 <Dorado9211SetCS@plt>
mov    $0x0,%al
call   1030 <Dorado9211ToggleClock@plt>
mov    $0x0,%al
call   1080 <Dorado9211SetDataOut@plt>
mov    $0x0,%al
call   1030 <Dorado9211ToggleClock@plt>
movb   $0x0,-0x3(%rbp)
movzbl -0x3(%rbp),%eax
cmp    $0xc,%eax
jge    11e5 <Dorado9211ReadReg+0x85>
movzwl -0x2(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11bf <Dorado9211ReadReg+0x5f>
mov    $0x0,%al
call   1080 <Dorado9211SetDataOut@plt>
jmp    11c6 <Dorado9211ReadReg+0x66>
mov    $0x0,%al
call   1070 <Dorado9211ClearDataOut@plt>
mov    $0x0,%al
call   1030 <Dorado9211ToggleClock@plt>
movzwl -0x2(%rbp),%eax
sar    $0x1,%eax
mov    %ax,-0x2(%rbp)
mov    -0x3(%rbp),%al
add    $0x1,%al
mov    %al,-0x3(%rbp)
jmp    1196 <Dorado9211ReadReg+0x36>
mov    $0x0,%al
call   1070 <Dorado9211ClearDataOut@plt>
mov    $0x0,%al
call   1030 <Dorado9211ToggleClock@plt>
mov    $0x0,%al
call   1030 <Dorado9211ToggleClock@plt>
mov    $0x0,%al
call   1030 <Dorado9211ToggleClock@plt>
mov    $0x0,%al
call   1030 <Dorado9211ToggleClock@plt>
mov    $0x0,%al
call   1030 <Dorado9211ToggleClock@plt>
mov    $0x0,%al
call   1030 <Dorado9211ToggleClock@plt>
mov    $0x0,%al
call   1030 <Dorado9211ToggleClock@plt>
mov    $0x0,%al
call   1030 <Dorado9211ToggleClock@plt>
movq   $0x0,-0x10(%rbp)
movb   $0x0,-0x3(%rbp)
movzbl -0x3(%rbp),%eax
cmp    $0x20,%eax
jge    1270 <Dorado9211ReadReg+0x110>
mov    $0x0,%al
call   1030 <Dorado9211ToggleClock@plt>
mov    $0x0,%al
call   1050 <Dorado9211ReadDataIn@plt>
mov    %al,-0x4(%rbp)
movzbl -0x4(%rbp),%eax
movzbl -0x3(%rbp),%ecx
mov    %ecx,%ecx
shl    %cl,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x3(%rbp),%al
add    $0x1,%al
mov    %al,-0x3(%rbp)
jmp    1230 <Dorado9211ReadReg+0xd0>
mov    $0x0,%al
call   1040 <Dorado9211ClearCS@plt>
mov    $0x0,%al
call   1030 <Dorado9211ToggleClock@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Dorado9211ReadReg>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   1070 <Dorado9211ClearDataOut@plt>
xor    %eax,%eax
call   1060 <Dorado9211SetCS@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
call   1080 <Dorado9211SetDataOut@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
test   $0x1,%bl
jne    1197 <Dorado9211ReadReg+0x37>
call   1070 <Dorado9211ClearDataOut@plt>
jmp    119c <Dorado9211ReadReg+0x3c>
call   1080 <Dorado9211SetDataOut@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
test   $0x2,%bl
jne    11b1 <Dorado9211ReadReg+0x51>
call   1070 <Dorado9211ClearDataOut@plt>
jmp    11b6 <Dorado9211ReadReg+0x56>
call   1080 <Dorado9211SetDataOut@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
test   $0x4,%bl
jne    11cb <Dorado9211ReadReg+0x6b>
call   1070 <Dorado9211ClearDataOut@plt>
jmp    11d0 <Dorado9211ReadReg+0x70>
call   1080 <Dorado9211SetDataOut@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
test   $0x8,%bl
jne    11e5 <Dorado9211ReadReg+0x85>
call   1070 <Dorado9211ClearDataOut@plt>
jmp    11ea <Dorado9211ReadReg+0x8a>
call   1080 <Dorado9211SetDataOut@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
test   $0x10,%bl
jne    11ff <Dorado9211ReadReg+0x9f>
call   1070 <Dorado9211ClearDataOut@plt>
jmp    1204 <Dorado9211ReadReg+0xa4>
call   1080 <Dorado9211SetDataOut@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
test   $0x20,%bl
jne    1219 <Dorado9211ReadReg+0xb9>
call   1070 <Dorado9211ClearDataOut@plt>
jmp    121e <Dorado9211ReadReg+0xbe>
call   1080 <Dorado9211SetDataOut@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
test   $0x40,%bl
jne    1233 <Dorado9211ReadReg+0xd3>
call   1070 <Dorado9211ClearDataOut@plt>
jmp    1238 <Dorado9211ReadReg+0xd8>
call   1080 <Dorado9211SetDataOut@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
test   $0x80,%bl
jne    124d <Dorado9211ReadReg+0xed>
call   1070 <Dorado9211ClearDataOut@plt>
jmp    1252 <Dorado9211ReadReg+0xf2>
call   1080 <Dorado9211SetDataOut@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
test   $0x100,%ebx
jne    126a <Dorado9211ReadReg+0x10a>
call   1070 <Dorado9211ClearDataOut@plt>
jmp    126f <Dorado9211ReadReg+0x10f>
call   1080 <Dorado9211SetDataOut@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
test   $0x200,%ebx
jne    1287 <Dorado9211ReadReg+0x127>
call   1070 <Dorado9211ClearDataOut@plt>
jmp    128c <Dorado9211ReadReg+0x12c>
call   1080 <Dorado9211SetDataOut@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
test   $0x400,%ebx
jne    12a4 <Dorado9211ReadReg+0x144>
call   1070 <Dorado9211ClearDataOut@plt>
jmp    12a9 <Dorado9211ReadReg+0x149>
call   1080 <Dorado9211SetDataOut@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
test   $0x800,%ebx
jne    12c1 <Dorado9211ReadReg+0x161>
call   1070 <Dorado9211ClearDataOut@plt>
jmp    12c6 <Dorado9211ReadReg+0x166>
call   1080 <Dorado9211SetDataOut@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
call   1070 <Dorado9211ClearDataOut@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %ebx,%ebx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
xor    %eax,%eax
call   1050 <Dorado9211ReadDataIn@plt>
movzbl %al,%eax
mov    %ebx,%ecx
shl    %cl,%rax
or     %rax,%r14
add    $0x1,%rbx
cmp    $0x20,%rbx
jne    1320 <Dorado9211ReadReg+0x1c0>
xor    %eax,%eax
call   1040 <Dorado9211ClearCS@plt>
xor    %eax,%eax
call   1030 <Dorado9211ToggleClock@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @Dorado9211ReadReg(i16 zeroext %0) {
%2 = alloca i16
%3 = alloca i8
%4 = alloca i8
%5 = alloca i64
store i16 %0, i16* %2
%6 = call i32 (...) @Dorado9211ClearDataOut()
%7 = call i32 (...) @Dorado9211SetCS()
%8 = call i32 (...) @Dorado9211ToggleClock()
%9 = call i32 (...) @Dorado9211SetDataOut()
%10 = call i32 (...) @Dorado9211ToggleClock()
store i8 0, i8* %3
br label %11
11: ; preds = %30, %1
%12 = load i8, i8* %3
%13 = zext i8 %12 to i32
%14 = icmp slt i32 %13, 12
br i1 %14, label %15, label %33
15: ; preds = %11
%16 = load i16, i16* %2
%17 = zext i16 %16 to i32
%18 = and i32 %17, 1
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 (...) @Dorado9211SetDataOut()
br label %24
22: ; preds = %15
%23 = call i32 (...) @Dorado9211ClearDataOut()
br label %24
24: ; preds = %22, %20
%25 = call i32 (...) @Dorado9211ToggleClock()
%26 = load i16, i16* %2
%27 = zext i16 %26 to i32
%28 = ashr i32 %27, 1
%29 = trunc i32 %28 to i16
store i16 %29, i16* %2
br label %30
30: ; preds = %24
%31 = load i8, i8* %3
%32 = add i8 %31, 1
store i8 %32, i8* %3
br label %11
33: ; preds = %11
%34 = call i32 (...) @Dorado9211ClearDataOut()
%35 = call i32 (...) @Dorado9211ToggleClock()
%36 = call i32 (...) @Dorado9211ToggleClock()
%37 = call i32 (...) @Dorado9211ToggleClock()
%38 = call i32 (...) @Dorado9211ToggleClock()
%39 = call i32 (...) @Dorado9211ToggleClock()
%40 = call i32 (...) @Dorado9211ToggleClock()
%41 = call i32 (...) @Dorado9211ToggleClock()
%42 = call i32 (...) @Dorado9211ToggleClock()
store i64 0, i64* %5
store i8 0, i8* %3
br label %43
43: ; preds = %58, %33
%44 = load i8, i8* %3
%45 = zext i8 %44 to i32
%46 = icmp slt i32 %45, 32
br i1 %46, label %47, label %61
47: ; preds = %43
%48 = call i32 (...) @Dorado9211ToggleClock()
%49 = call zeroext i8 (...) @Dorado9211ReadDataIn()
store i8 %49, i8* %4
%50 = load i8, i8* %4
%51 = zext i8 %50 to i64
%52 = load i8, i8* %3
%53 = zext i8 %52 to i32
%54 = zext i32 %53 to i64
%55 = shl i64 %51, %54
%56 = load i64, i64* %5
%57 = or i64 %56, %55
store i64 %57, i64* %5
br label %58
58: ; preds = %47
%59 = load i8, i8* %3
%60 = add i8 %59, 1
store i8 %60, i8* %3
br label %43
61: ; preds = %43
%62 = call i32 (...) @Dorado9211ClearCS()
%63 = call i32 (...) @Dorado9211ToggleClock()
%64 = load i64, i64* %5
ret i64 %64
}

LLVM IR (-O2):
define i64 @Dorado9211ReadReg(i16 zeroext %0) {
%2 = tail call i32 (...) @Dorado9211ClearDataOut()
%3 = tail call i32 (...) @Dorado9211SetCS()
%4 = tail call i32 (...) @Dorado9211ToggleClock()
%5 = tail call i32 (...) @Dorado9211SetDataOut()
%6 = tail call i32 (...) @Dorado9211ToggleClock()
%7 = and i16 %0, 1
%8 = icmp eq i16 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = tail call i32 (...) @Dorado9211SetDataOut()
br label %13
11: ; preds = %1
%12 = tail call i32 (...) @Dorado9211ClearDataOut()
br label %13
13: ; preds = %11, %9
%14 = tail call i32 (...) @Dorado9211ToggleClock()
%15 = and i16 %0, 2
%16 = icmp eq i16 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = tail call i32 (...) @Dorado9211SetDataOut()
br label %21
19: ; preds = %13
%20 = tail call i32 (...) @Dorado9211ClearDataOut()
br label %21
21: ; preds = %19, %17
%22 = tail call i32 (...) @Dorado9211ToggleClock()
%23 = and i16 %0, 4
%24 = icmp eq i16 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = tail call i32 (...) @Dorado9211SetDataOut()
br label %29
27: ; preds = %21
%28 = tail call i32 (...) @Dorado9211ClearDataOut()
br label %29
29: ; preds = %27, %25
%30 = tail call i32 (...) @Dorado9211ToggleClock()
%31 = and i16 %0, 8
%32 = icmp eq i16 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %29
%34 = tail call i32 (...) @Dorado9211SetDataOut()
br label %37
35: ; preds = %29
%36 = tail call i32 (...) @Dorado9211ClearDataOut()
br label %37
37: ; preds = %35, %33
%38 = tail call i32 (...) @Dorado9211ToggleClock()
%39 = and i16 %0, 16
%40 = icmp eq i16 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %37
%42 = tail call i32 (...) @Dorado9211SetDataOut()
br label %45
43: ; preds = %37
%44 = tail call i32 (...) @Dorado9211ClearDataOut()
br label %45
45: ; preds = %43, %41
%46 = tail call i32 (...) @Dorado9211ToggleClock()
%47 = and i16 %0, 32
%48 = icmp eq i16 %47, 0
br i1 %48, label %51, label %49
49: ; preds = %45
%50 = tail call i32 (...) @Dorado9211SetDataOut()
br label %53
51: ; preds = %45
%52 = tail call i32 (...) @Dorado9211ClearDataOut()
br label %53
53: ; preds = %51, %49
%54 = tail call i32 (...) @Dorado9211ToggleClock()
%55 = and i16 %0, 64
%56 = icmp eq i16 %55, 0
br i1 %56, label %59, label %57
57: ; preds = %53
%58 = tail call i32 (...) @Dorado9211SetDataOut()
br label %61
59: ; preds = %53
%60 = tail call i32 (...) @Dorado9211ClearDataOut()
br label %61
61: ; preds = %59, %57
%62 = tail call i32 (...) @Dorado9211ToggleClock()
%63 = and i16 %0, 128
%64 = icmp eq i16 %63, 0
br i1 %64, label %67, label %65
65: ; preds = %61
%66 = tail call i32 (...) @Dorado9211SetDataOut()
br label %69
67: ; preds = %61
%68 = tail call i32 (...) @Dorado9211ClearDataOut()
br label %69
69: ; preds = %67, %65
%70 = tail call i32 (...) @Dorado9211ToggleClock()
%71 = and i16 %0, 256
%72 = icmp eq i16 %71, 0
br i1 %72, label %75, label %73
73: ; preds = %69
%74 = tail call i32 (...) @Dorado9211SetDataOut()
br label %77
75: ; preds = %69
%76 = tail call i32 (...) @Dorado9211ClearDataOut()
br label %77
77: ; preds = %75, %73
%78 = tail call i32 (...) @Dorado9211ToggleClock()
%79 = and i16 %0, 512
%80 = icmp eq i16 %79, 0
br i1 %80, label %83, label %81
81: ; preds = %77
%82 = tail call i32 (...) @Dorado9211SetDataOut()
br label %85
83: ; preds = %77
%84 = tail call i32 (...) @Dorado9211ClearDataOut()
br label %85
85: ; preds = %83, %81
%86 = tail call i32 (...) @Dorado9211ToggleClock()
%87 = and i16 %0, 1024
%88 = icmp eq i16 %87, 0
br i1 %88, label %91, label %89
89: ; preds = %85
%90 = tail call i32 (...) @Dorado9211SetDataOut()
br label %93
91: ; preds = %85
%92 = tail call i32 (...) @Dorado9211ClearDataOut()
br label %93
93: ; preds = %91, %89
%94 = tail call i32 (...) @Dorado9211ToggleClock()
%95 = and i16 %0, 2048
%96 = icmp eq i16 %95, 0
br i1 %96, label %99, label %97
97: ; preds = %93
%98 = tail call i32 (...) @Dorado9211SetDataOut()
br label %101
99: ; preds = %93
%100 = tail call i32 (...) @Dorado9211ClearDataOut()
br label %101
101: ; preds = %99, %97
%102 = tail call i32 (...) @Dorado9211ToggleClock()
%103 = tail call i32 (...) @Dorado9211ClearDataOut()
%104 = tail call i32 (...) @Dorado9211ToggleClock()
%105 = tail call i32 (...) @Dorado9211ToggleClock()
%106 = tail call i32 (...) @Dorado9211ToggleClock()
%107 = tail call i32 (...) @Dorado9211ToggleClock()
%108 = tail call i32 (...) @Dorado9211ToggleClock()
%109 = tail call i32 (...) @Dorado9211ToggleClock()
%110 = tail call i32 (...) @Dorado9211ToggleClock()
%111 = tail call i32 (...) @Dorado9211ToggleClock()
br label %112
112: ; preds = %101, %112
%113 = phi i64 [ 0, %101 ], [ %120, %112 ]
%114 = phi i64 [ 0, %101 ], [ %119, %112 ]
%115 = tail call i32 (...) @Dorado9211ToggleClock()
%116 = tail call zeroext i8 (...) @Dorado9211ReadDataIn()
%117 = zext i8 %116 to i64
%118 = shl nuw nsw i64 %117, %113
%119 = or i64 %118, %114
%120 = add nuw nsw i64 %113, 1
%121 = icmp eq i64 %120, 32
br i1 %121, label %122, label %112
122: ; preds = %112
%123 = tail call i32 (...) @Dorado9211ClearCS()
%124 = tail call i32 (...) @Dorado9211ToggleClock()
ret i64 %119
}