#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*/ ad9520_read_byte(int, unsigned char *, int);
int /*<<< orphan*/ ad9520_write_byte(int, unsigned char *, int);
int /*<<< orphan*/ decode_ad9520_id(unsigned char, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usleep(int);
int self_config_ad9520(int speed) {
  unsigned char cache[4096];
  int i;
  unsigned char data;
  unsigned char idbuf[64];
  ad9520_read_byte(0x003, &data, 1);
  printf("AD9520 part ID: %02x = ", data);
  decode_ad9520_id(data, (char *)idbuf);
  printf("%s", idbuf);
  for (i = 0; i < 4096; i++) {
    cache[i] = 0;
  }
  cache[0x010] = 0x3c;
  cache[0x011] = 0x01;
  cache[0x012] = 0x00;
  cache[0x013] = 16;
  cache[0x014] = 23;
  cache[0x015] = 0x00;
  cache[0x016] = 0x04;
  cache[0x017] = 0x04;
  cache[0x018] = 0x86;
  cache[0x019] = 0x00;
  cache[0x01A] = 0x00;
  cache[0x01B] = 0x00;
  cache[0x01C] = 0x02;
  cache[0x01D] = 0x00;
  cache[0x01E] = 0x00;
  cache[0x0F0] = 0x65;
  cache[0x0F1] = 0x65;
  cache[0x0F2] = 0x65;
  cache[0x0F3] = 0x64;
  cache[0x0F4] = 0x65;
  cache[0x0F5] = 0x65;
  cache[0x0F6] = 0x65;
  cache[0x0F7] = 0x65;
  cache[0x0F8] = 0x65;
  cache[0x0F9] = 0x65;
  cache[0x0FA] = 0x65;
  cache[0x0FB] = 0x65;
  cache[0x0FC] = 0x00;
  cache[0x0FD] = 0x00;
  cache[0x190] = 0x11;
  cache[0x191] = 0x00;
  cache[0x192] = 0x04;
  cache[0x193] = 0x00;
  cache[0x194] = 0x80;
  cache[0x195] = 0x01;
  cache[0x196] = 0x11;
  cache[0x197] = 0x00;
  cache[0x198] = 0x04;
  cache[0x199] = 0x00;
  cache[0x19A] = 0x00;
  cache[0x19B] = 0x04;
  if (speed)
    cache[0x1E0] = 0x00;
  else
    cache[0x1E0] = 0x02;
  cache[0x1E1] = 0x22;
  cache[0x230] = 0x00;
  cache[0x232] = 0;
  do {
  } while (0);
  cache[0x000] = 0x22;
  ad9520_write_byte(0x000, &(cache[0x000]), 1);
  cache[0x000] = 0x00;
  usleep(10000);
  do {
  } while (0);
  ad9520_write_byte(0x010, &(cache[0x010]), 0x01F - 0x010);
  do {
  } while (0);
  ad9520_write_byte(0x0F0, &(cache[0x0F0]), 0x0FD - 0x0F0 + 1);
  do {
  } while (0);
  ad9520_write_byte(0x190, &(cache[0x190]), 0x19B - 0x190 + 1);
  do {
  } while (0);
  ad9520_write_byte(0x1E0, &(cache[0x1E0]), 0x1E1 - 0x1E0 + 1);
  do {
  } while (0);
  ad9520_write_byte(0x230, &(cache[0x230]), 0x230 - 0x230 + 1);
  do {
  } while (0);
  cache[0x232] = 1;
  ad9520_write_byte(0x232, &(cache[0x232]), 1);
  do {
  } while (0);
  cache[0x018] &= 0xFE;
  ad9520_write_byte(0x018, &(cache[0x018]), 1);
  cache[0x232] = 1;
  ad9520_write_byte(0x232, &(cache[0x232]), 1);
  cache[0x018] |= 0x01;
  ad9520_write_byte(0x018, &(cache[0x018]), 1);
  cache[0x232] = 1;
  ad9520_write_byte(0x232, &(cache[0x232]), 1);
  data = 0;
  i = 0;
  do {
    ad9520_read_byte(0x01F, &data, 1);
    i++;
  } while (((data & 0x40) == 0) && (i < 1000));
  if (i >= 1000) {
    printf("Calibration timed out!\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<self_config_ad9520>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1070,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x3,%edi
lea    -0x1015(%rbp),%rsi
mov    $0x1,%edx
call   1050 <ad9520_read_byte@plt>
movzbl -0x1015(%rbp),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1015(%rbp),%al
lea    -0x1060(%rbp),%rsi
movzbl %al,%edi
call   1060 <decode_ad9520_id@plt>
lea    -0x1060(%rbp),%rsi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1014(%rbp)
cmpl   $0x1000,-0x1014(%rbp)
jge    11f0 <self_config_ad9520+0xa0>
movslq -0x1014(%rbp),%rax
movb   $0x0,-0x1010(%rbp,%rax,1)
mov    -0x1014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1014(%rbp)
jmp    11bd <self_config_ad9520+0x6d>
movb   $0x3c,-0x1000(%rbp)
movb   $0x1,-0xfff(%rbp)
movb   $0x0,-0xffe(%rbp)
movb   $0x10,-0xffd(%rbp)
movb   $0x17,-0xffc(%rbp)
movb   $0x0,-0xffb(%rbp)
movb   $0x4,-0xffa(%rbp)
movb   $0x4,-0xff9(%rbp)
movb   $0x86,-0xff8(%rbp)
movb   $0x0,-0xff7(%rbp)
movb   $0x0,-0xff6(%rbp)
movb   $0x0,-0xff5(%rbp)
movb   $0x2,-0xff4(%rbp)
movb   $0x0,-0xff3(%rbp)
movb   $0x0,-0xff2(%rbp)
movb   $0x65,-0xf20(%rbp)
movb   $0x65,-0xf1f(%rbp)
movb   $0x65,-0xf1e(%rbp)
movb   $0x64,-0xf1d(%rbp)
movb   $0x65,-0xf1c(%rbp)
movb   $0x65,-0xf1b(%rbp)
movb   $0x65,-0xf1a(%rbp)
movb   $0x65,-0xf19(%rbp)
movb   $0x65,-0xf18(%rbp)
movb   $0x65,-0xf17(%rbp)
movb   $0x65,-0xf16(%rbp)
movb   $0x65,-0xf15(%rbp)
movb   $0x0,-0xf14(%rbp)
movb   $0x0,-0xf13(%rbp)
movb   $0x11,-0xe80(%rbp)
movb   $0x0,-0xe7f(%rbp)
movb   $0x4,-0xe7e(%rbp)
movb   $0x0,-0xe7d(%rbp)
movb   $0x80,-0xe7c(%rbp)
movb   $0x1,-0xe7b(%rbp)
movb   $0x11,-0xe7a(%rbp)
movb   $0x0,-0xe79(%rbp)
movb   $0x4,-0xe78(%rbp)
movb   $0x0,-0xe77(%rbp)
movb   $0x0,-0xe76(%rbp)
movb   $0x4,-0xe75(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1325 <self_config_ad9520+0x1d5>
movb   $0x0,-0xe30(%rbp)
jmp    132c <self_config_ad9520+0x1dc>
movb   $0x2,-0xe30(%rbp)
movb   $0x22,-0xe2f(%rbp)
movb   $0x0,-0xde0(%rbp)
movb   $0x0,-0xdde(%rbp)
jmp    1346 <self_config_ad9520+0x1f6>
movb   $0x22,-0x1010(%rbp)
lea    -0x1010(%rbp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1040 <ad9520_write_byte@plt>
movb   $0x0,-0x1010(%rbp)
mov    $0x2710,%edi
call   1070 <usleep@plt>
jmp    1376 <self_config_ad9520+0x226>
lea    -0x1010(%rbp),%rsi
add    $0x10,%rsi
mov    $0x10,%edi
mov    $0xf,%edx
call   1040 <ad9520_write_byte@plt>
jmp    1395 <self_config_ad9520+0x245>
lea    -0x1010(%rbp),%rsi
add    $0xf0,%rsi
mov    $0xf0,%edi
mov    $0xe,%edx
call   1040 <ad9520_write_byte@plt>
jmp    13b7 <self_config_ad9520+0x267>
lea    -0x1010(%rbp),%rsi
add    $0x190,%rsi
mov    $0x190,%edi
mov    $0xc,%edx
call   1040 <ad9520_write_byte@plt>
jmp    13d9 <self_config_ad9520+0x289>
lea    -0x1010(%rbp),%rsi
add    $0x1e0,%rsi
mov    $0x1e0,%edi
mov    $0x2,%edx
call   1040 <ad9520_write_byte@plt>
jmp    13fb <self_config_ad9520+0x2ab>
lea    -0x1010(%rbp),%rsi
add    $0x230,%rsi
mov    $0x230,%edi
mov    $0x1,%edx
call   1040 <ad9520_write_byte@plt>
jmp    141d <self_config_ad9520+0x2cd>
movb   $0x1,-0xdde(%rbp)
lea    -0x1010(%rbp),%rsi
add    $0x232,%rsi
mov    $0x232,%edi
mov    $0x1,%edx
call   1040 <ad9520_write_byte@plt>
jmp    1446 <self_config_ad9520+0x2f6>
movzbl -0xff8(%rbp),%eax
and    $0xfe,%eax
mov    %al,-0xff8(%rbp)
lea    -0x1010(%rbp),%rsi
add    $0x18,%rsi
mov    $0x18,%edi
mov    $0x1,%edx
call   1040 <ad9520_write_byte@plt>
movb   $0x1,-0xdde(%rbp)
lea    -0x1010(%rbp),%rsi
add    $0x232,%rsi
mov    $0x232,%edi
mov    $0x1,%edx
call   1040 <ad9520_write_byte@plt>
movzbl -0xff8(%rbp),%eax
or     $0x1,%eax
mov    %al,-0xff8(%rbp)
lea    -0x1010(%rbp),%rsi
add    $0x18,%rsi
mov    $0x18,%edi
mov    $0x1,%edx
call   1040 <ad9520_write_byte@plt>
movb   $0x1,-0xdde(%rbp)
lea    -0x1010(%rbp),%rsi
add    $0x232,%rsi
mov    $0x232,%edi
mov    $0x1,%edx
call   1040 <ad9520_write_byte@plt>
movb   $0x0,-0x1015(%rbp)
movl   $0x0,-0x1014(%rbp)
mov    $0x1f,%edi
lea    -0x1015(%rbp),%rsi
mov    $0x1,%edx
call   1050 <ad9520_read_byte@plt>
mov    -0x1014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1014(%rbp)
movzbl -0x1015(%rbp),%ecx
and    $0x40,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1061(%rbp)
jne    1548 <self_config_ad9520+0x3f8>
cmpl   $0x3e8,-0x1014(%rbp)
setl   %al
mov    %al,-0x1061(%rbp)
mov    -0x1061(%rbp),%al
test   $0x1,%al
jne    14f5 <self_config_ad9520+0x3a5>
cmpl   $0x3e8,-0x1014(%rbp)
jl     1580 <self_config_ad9520+0x430>
lea    0xaae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1587 <self_config_ad9520+0x437>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<self_config_ad9520>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1058,%rsp
mov    %edi,%r15d
lea    0xf(%rsp),%rbx
mov    $0x3,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <ad9520_read_byte@plt>
movzbl 0xf(%rsp),%esi
lea    0xe59(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0xf(%rsp),%edi
lea    0x10(%rsp),%rbp
mov    %rbp,%rsi
call   1080 <decode_ad9520_id@plt>
lea    0xe51(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x50(%rsp),%r12
mov    $0x1000,%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0x60(%rsp),%r13
movw   $0x13c,0x60(%rsp)
movw   $0x1710,0x63(%rsp)
movw   $0x404,0x66(%rsp)
movb   $0x86,0x68(%rsp)
movb   $0x0,0x6a(%rsp)
movb   $0x2,0x6c(%rsp)
movb   $0x0,0x6e(%rsp)
lea    0x140(%rsp),%r14
movl   $0x64656565,0x140(%rsp)
65 65 65 64
movabs $0x6565656565656565,%rax
65 65 65
mov    %rax,0x144(%rsp)
movb   $0x0,0x14d(%rsp)
movb   $0x11,0x1e0(%rsp)
11
movb   $0x4,0x1e2(%rsp)
04
movw   $0x180,0x1e4(%rsp)
movb   $0x11,0x1e6(%rsp)
11
movb   $0x4,0x1e8(%rsp)
04
movw   $0x400,0x1ea(%rsp)
test   %r15d,%r15d
sete   %al
add    %al,%al
lea    0x230(%rsp),%rbp
mov    %al,0x230(%rsp)
movb   $0x22,0x231(%rsp)
22
movb   $0x0,0x280(%rsp)
lea    0x282(%rsp),%r15
movb   $0x0,0x282(%rsp)
movb   $0x22,0x50(%rsp)
xor    %edi,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1060 <ad9520_write_byte@plt>
movb   $0x0,0x50(%rsp)
mov    $0x2710,%edi
call   1090 <usleep@plt>
mov    $0x10,%edi
mov    %r13,%rsi
mov    $0xf,%edx
call   1060 <ad9520_write_byte@plt>
mov    $0xf0,%edi
mov    %r14,%rsi
mov    $0xe,%edx
call   1060 <ad9520_write_byte@plt>
mov    $0x190,%edi
lea    0x1e0(%rsp),%rsi
mov    $0xc,%edx
call   1060 <ad9520_write_byte@plt>
mov    $0x1e0,%edi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1060 <ad9520_write_byte@plt>
mov    $0x230,%edi
lea    0x280(%rsp),%rsi
mov    $0x1,%edx
call   1060 <ad9520_write_byte@plt>
movb   $0x1,0x282(%rsp)
01
mov    $0x232,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1060 <ad9520_write_byte@plt>
andb   $0xfe,0x68(%rsp)
mov    $0x18,%edi
lea    0x68(%rsp),%rsi
mov    $0x1,%edx
call   1060 <ad9520_write_byte@plt>
movb   $0x1,0x282(%rsp)
01
mov    $0x232,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1060 <ad9520_write_byte@plt>
orb    $0x1,0x68(%rsp)
mov    $0x18,%edi
lea    0x68(%rsp),%rsi
mov    $0x1,%edx
call   1060 <ad9520_write_byte@plt>
movb   $0x1,0x282(%rsp)
01
mov    $0x232,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1060 <ad9520_write_byte@plt>
movb   $0x0,0xf(%rsp)
mov    $0xffffffff,%ebp
nopl   0x0(%rax)
add    $0x1,%ebp
mov    $0x1f,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <ad9520_read_byte@plt>
testb  $0x40,0xf(%rsp)
jne    13e4 <self_config_ad9520+0x274>
cmp    $0x3e7,%ebp
jb     13c0 <self_config_ad9520+0x250>
xor    %eax,%eax
cmp    $0x3e7,%ebp
jb     13ff <self_config_ad9520+0x28f>
lea    0xc26(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x1058,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"AD9520 part ID: %02x = \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [24 x i8] c"Calibration timed out!\0A\00"
define i32 @self_config_ad9520(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [4096 x i8]
%5 = alloca i32
%6 = alloca i8
%7 = alloca [64 x i8]
store i32 %0, i32* %3
%8 = call i32 @ad9520_read_byte(i32 3, i8* %6, i32 1)
%9 = load i8, i8* %6
%10 = zext i8 %9 to i32
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i8, i8* %6
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%14 = call i32 @decode_ad9520_id(i8 zeroext %12, i8* %13)
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 0, i32* %5
br label %17
17: ; preds = %24, %1
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 4096
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %20
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %17
27: ; preds = %17
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 16
store i8 60, i8* %28
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 17
store i8 1, i8* %29
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 18
store i8 0, i8* %30
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 19
store i8 16, i8* %31
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 20
store i8 23, i8* %32
%33 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 21
store i8 0, i8* %33
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 22
store i8 4, i8* %34
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 23
store i8 4, i8* %35
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 24
store i8 -122, i8* %36
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 25
store i8 0, i8* %37
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 26
store i8 0, i8* %38
%39 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 27
store i8 0, i8* %39
%40 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 28
store i8 2, i8* %40
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 29
store i8 0, i8* %41
%42 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 30
store i8 0, i8* %42
%43 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 240
store i8 101, i8* %43
%44 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 241
store i8 101, i8* %44
%45 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 242
store i8 101, i8* %45
%46 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 243
store i8 100, i8* %46
%47 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 244
store i8 101, i8* %47
%48 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 245
store i8 101, i8* %48
%49 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 246
store i8 101, i8* %49
%50 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 247
store i8 101, i8* %50
%51 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 248
store i8 101, i8* %51
%52 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 249
store i8 101, i8* %52
%53 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 250
store i8 101, i8* %53
%54 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 251
store i8 101, i8* %54
%55 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 252
store i8 0, i8* %55
%56 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 253
store i8 0, i8* %56
%57 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 400
store i8 17, i8* %57
%58 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 401
store i8 0, i8* %58
%59 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 402
store i8 4, i8* %59
%60 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 403
store i8 0, i8* %60
%61 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 404
store i8 -128, i8* %61
%62 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 405
store i8 1, i8* %62
%63 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 406
store i8 17, i8* %63
%64 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 407
store i8 0, i8* %64
%65 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 408
store i8 4, i8* %65
%66 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 409
store i8 0, i8* %66
%67 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 410
store i8 0, i8* %67
%68 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 411
store i8 4, i8* %68
%69 = load i32, i32* %3
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %27
%72 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 480
store i8 0, i8* %72
br label %75
73: ; preds = %27
%74 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 480
store i8 2, i8* %74
br label %75
75: ; preds = %73, %71
%76 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 481
store i8 34, i8* %76
%77 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 560
store i8 0, i8* %77
%78 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 562
store i8 0, i8* %78
br label %79
79: ; preds = %75
br label %80
80: ; preds = %79
%81 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
store i8 34, i8* %81
%82 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%83 = call i32 @ad9520_write_byte(i32 0, i8* %82, i32 1)
%84 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
store i8 0, i8* %84
%85 = call i32 @usleep(i32 10000)
br label %86
86: ; preds = %80
br label %87
87: ; preds = %86
%88 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 16
%89 = call i32 @ad9520_write_byte(i32 16, i8* %88, i32 15)
br label %90
90: ; preds = %87
br label %91
91: ; preds = %90
%92 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 240
%93 = call i32 @ad9520_write_byte(i32 240, i8* %92, i32 14)
br label %94
94: ; preds = %91
br label %95
95: ; preds = %94
%96 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 400
%97 = call i32 @ad9520_write_byte(i32 400, i8* %96, i32 12)
br label %98
98: ; preds = %95
br label %99
99: ; preds = %98
%100 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 480
%101 = call i32 @ad9520_write_byte(i32 480, i8* %100, i32 2)
br label %102
102: ; preds = %99
br label %103
103: ; preds = %102
%104 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 560
%105 = call i32 @ad9520_write_byte(i32 560, i8* %104, i32 1)
br label %106
106: ; preds = %103
br label %107
107: ; preds = %106
%108 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 562
store i8 1, i8* %108
%109 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 562
%110 = call i32 @ad9520_write_byte(i32 562, i8* %109, i32 1)
br label %111
111: ; preds = %107
br label %112
112: ; preds = %111
%113 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 24
%114 = load i8, i8* %113
%115 = zext i8 %114 to i32
%116 = and i32 %115, 254
%117 = trunc i32 %116 to i8
store i8 %117, i8* %113
%118 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 24
%119 = call i32 @ad9520_write_byte(i32 24, i8* %118, i32 1)
%120 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 562
store i8 1, i8* %120
%121 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 562
%122 = call i32 @ad9520_write_byte(i32 562, i8* %121, i32 1)
%123 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 24
%124 = load i8, i8* %123
%125 = zext i8 %124 to i32
%126 = or i32 %125, 1
%127 = trunc i32 %126 to i8
store i8 %127, i8* %123
%128 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 24
%129 = call i32 @ad9520_write_byte(i32 24, i8* %128, i32 1)
%130 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 562
store i8 1, i8* %130
%131 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 562
%132 = call i32 @ad9520_write_byte(i32 562, i8* %131, i32 1)
store i8 0, i8* %6
store i32 0, i32* %5
br label %133
133: ; preds = %145, %112
%134 = call i32 @ad9520_read_byte(i32 31, i8* %6, i32 1)
%135 = load i32, i32* %5
%136 = add nsw i32 %135, 1
store i32 %136, i32* %5
br label %137
137: ; preds = %133
%138 = load i8, i8* %6
%139 = zext i8 %138 to i32
%140 = and i32 %139, 64
%141 = icmp eq i32 %140, 0
br i1 %141, label %142, label %145
142: ; preds = %137
%143 = load i32, i32* %5
%144 = icmp slt i32 %143, 1000
br label %145
145: ; preds = %142, %137
%146 = phi i1 [ false, %137 ], [ %144, %142 ]
br i1 %146, label %133, label %147
147: ; preds = %145
%148 = load i32, i32* %5
%149 = icmp sge i32 %148, 1000
br i1 %149, label %150, label %152
150: ; preds = %147
%151 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %153
152: ; preds = %147
store i32 0, i32* %2
br label %153
153: ; preds = %152, %150
%154 = load i32, i32* %2
ret i32 %154
}

LLVM IR (-O2):
@.str = [24 x i8] c"AD9520 part ID: %02x = \00"
@.str.1 = [3 x i8] c"%s\00"
@str = [23 x i8] c"Calibration timed out!\00"
define i32 @self_config_ad9520(i32 %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = alloca i8
%5 = alloca [64 x i8]
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%8 = call i32 @ad9520_read_byte(i32 3, i8* %4, i32 1)
%9 = load i8, i8* %4
%10 = zext i8 %9 to i32
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i8, i8* %4
%13 = call i32 @decode_ad9520_id(i8 zeroext %12, i8* %7)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 16
store i8 60, i8* %15
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 17
store i8 1, i8* %16
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 19
store i8 16, i8* %17
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 20
store i8 23, i8* %18
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 22
store i8 4, i8* %19
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 23
store i8 4, i8* %20
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 24
store i8 -122, i8* %21
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 26
store i8 0, i8* %22
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 28
store i8 2, i8* %23
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 30
store i8 0, i8* %24
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 240
store i8 101, i8* %25
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 241
store i8 101, i8* %26
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 242
store i8 101, i8* %27
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 243
store i8 100, i8* %28
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 244
%30 = bitcast i8* %29 to i64*
store i64 7306357456645743973, i64* %30
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 253
store i8 0, i8* %31
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 400
store i8 17, i8* %32
%33 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 402
store i8 4, i8* %33
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 404
store i8 -128, i8* %34
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 405
store i8 1, i8* %35
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 406
store i8 17, i8* %36
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 408
store i8 4, i8* %37
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 410
store i8 0, i8* %38
%39 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 411
store i8 4, i8* %39
%40 = icmp eq i32 %0, 0
%41 = select i1 %40, i8 2, i8 0
%42 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 480
store i8 %41, i8* %42
%43 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 481
store i8 34, i8* %43
%44 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 560
store i8 0, i8* %44
%45 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 562
store i8 0, i8* %45
store i8 34, i8* %6
%46 = call i32 @ad9520_write_byte(i32 0, i8* %6, i32 1)
store i8 0, i8* %6
%47 = call i32 @usleep(i32 10000)
%48 = call i32 @ad9520_write_byte(i32 16, i8* %15, i32 15)
%49 = call i32 @ad9520_write_byte(i32 240, i8* %25, i32 14)
%50 = call i32 @ad9520_write_byte(i32 400, i8* %32, i32 12)
%51 = call i32 @ad9520_write_byte(i32 480, i8* %42, i32 2)
%52 = call i32 @ad9520_write_byte(i32 560, i8* %44, i32 1)
store i8 1, i8* %45
%53 = call i32 @ad9520_write_byte(i32 562, i8* %45, i32 1)
%54 = load i8, i8* %21
%55 = and i8 %54, -2
store i8 %55, i8* %21
%56 = call i32 @ad9520_write_byte(i32 24, i8* %21, i32 1)
store i8 1, i8* %45
%57 = call i32 @ad9520_write_byte(i32 562, i8* %45, i32 1)
%58 = load i8, i8* %21
%59 = or i8 %58, 1
store i8 %59, i8* %21
%60 = call i32 @ad9520_write_byte(i32 24, i8* %21, i32 1)
store i8 1, i8* %45
%61 = call i32 @ad9520_write_byte(i32 562, i8* %45, i32 1)
store i8 0, i8* %4
br label %62
62: ; preds = %62, %1
%63 = phi i32 [ 0, %1 ], [ %65, %62 ]
%64 = call i32 @ad9520_read_byte(i32 31, i8* %4, i32 1)
%65 = add nuw nsw i32 %63, 1
%66 = load i8, i8* %4
%67 = and i8 %66, 64
%68 = icmp eq i8 %67, 0
%69 = icmp ult i32 %63, 999
%70 = select i1 %68, i1 %69, i1 false
br i1 %70, label %62, label %71
71: ; preds = %62
%72 = icmp ugt i32 %63, 998
br i1 %72, label %73, label %75
73: ; preds = %71
%74 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %75
75: ; preds = %71, %73
%76 = phi i32 [ 1, %73 ], [ 0, %71 ]
ret i32 %76
}