#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*/ O_RDONLY;
int /*<<< orphan*/ ad9520_write_byte(int, unsigned char *, int);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
int load_ad9520_from_file(char *fname) {
  int fd;
  unsigned char cache[4096];
  int readcount;
  fd = open(fname, O_RDONLY);
  if (fd < 0) {
    perror("Can't open file ");
    printf("%s\n", fname);
    return -1;
  }
  readcount = read(fd, cache, 2820);
  if (readcount != 2820) {
    printf("Error: read only %d out of 2820 expected bytes in AD9520 PLL "
           "config file\n",
           readcount);
    close(fd);
    return -1;
  }
  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]), 0x19A - 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);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<load_ad9520_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11b8 <load_ad9520_from_file+0x58>
lea    0xe6b(%rip),%rdi
call   1080 <perror@plt>
mov    -0x10(%rbp),%rsi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1391 <load_ad9520_from_file+0x231>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0xb04,%edx
call   1050 <read@plt>
mov    %eax,-0x1024(%rbp)
cmpl   $0xb04,-0x1024(%rbp)
je     120a <load_ad9520_from_file+0xaa>
mov    -0x1024(%rbp),%esi
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1391 <load_ad9520_from_file+0x231>
jmp    120f <load_ad9520_from_file+0xaf>
jmp    1214 <load_ad9520_from_file+0xb4>
lea    -0x1020(%rbp),%rsi
add    $0x10,%rsi
mov    $0x10,%edi
mov    $0xf,%edx
call   1060 <ad9520_write_byte@plt>
jmp    1233 <load_ad9520_from_file+0xd3>
lea    -0x1020(%rbp),%rsi
add    $0xf0,%rsi
mov    $0xf0,%edi
mov    $0xe,%edx
call   1060 <ad9520_write_byte@plt>
jmp    1255 <load_ad9520_from_file+0xf5>
lea    -0x1020(%rbp),%rsi
add    $0x190,%rsi
mov    $0x190,%edi
mov    $0xb,%edx
call   1060 <ad9520_write_byte@plt>
jmp    1277 <load_ad9520_from_file+0x117>
lea    -0x1020(%rbp),%rsi
add    $0x1e0,%rsi
mov    $0x1e0,%edi
mov    $0x2,%edx
call   1060 <ad9520_write_byte@plt>
jmp    1299 <load_ad9520_from_file+0x139>
lea    -0x1020(%rbp),%rsi
add    $0x230,%rsi
mov    $0x230,%edi
mov    $0x1,%edx
call   1060 <ad9520_write_byte@plt>
jmp    12bb <load_ad9520_from_file+0x15b>
movb   $0x1,-0xdee(%rbp)
lea    -0x1020(%rbp),%rsi
add    $0x232,%rsi
mov    $0x232,%edi
mov    $0x1,%edx
call   1060 <ad9520_write_byte@plt>
jmp    12e4 <load_ad9520_from_file+0x184>
movzbl -0x1008(%rbp),%eax
and    $0xfe,%eax
mov    %al,-0x1008(%rbp)
lea    -0x1020(%rbp),%rsi
add    $0x18,%rsi
mov    $0x18,%edi
mov    $0x1,%edx
call   1060 <ad9520_write_byte@plt>
movb   $0x1,-0xdee(%rbp)
lea    -0x1020(%rbp),%rsi
add    $0x232,%rsi
mov    $0x232,%edi
mov    $0x1,%edx
call   1060 <ad9520_write_byte@plt>
movzbl -0x1008(%rbp),%eax
or     $0x1,%eax
mov    %al,-0x1008(%rbp)
lea    -0x1020(%rbp),%rsi
add    $0x18,%rsi
mov    $0x18,%edi
mov    $0x1,%edx
call   1060 <ad9520_write_byte@plt>
movb   $0x1,-0xdee(%rbp)
lea    -0x1020(%rbp),%rsi
add    $0x232,%rsi
mov    $0x232,%edi
mov    $0x1,%edx
call   1060 <ad9520_write_byte@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_ad9520_from_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rdi,%rbx
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     12dc <load_ad9520_from_file+0x16c>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0xb04,%edx
call   1060 <read@plt>
cmp    $0xb04,%eax
jne    12b4 <load_ad9520_from_file+0x144>
lea    0x10(%rsp),%rsi
mov    $0x10,%edi
mov    $0xf,%edx
call   1070 <ad9520_write_byte@plt>
lea    0xf0(%rsp),%rsi
mov    $0xf0,%edi
mov    $0xe,%edx
call   1070 <ad9520_write_byte@plt>
lea    0x190(%rsp),%rsi
mov    $0x190,%edi
mov    $0xb,%edx
call   1070 <ad9520_write_byte@plt>
lea    0x1e0(%rsp),%rsi
mov    $0x1e0,%edi
mov    $0x2,%edx
call   1070 <ad9520_write_byte@plt>
lea    0x230(%rsp),%rsi
mov    $0x230,%edi
mov    $0x1,%edx
call   1070 <ad9520_write_byte@plt>
lea    0x232(%rsp),%r14
movb   $0x1,0x232(%rsp)
01
mov    $0x232,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1070 <ad9520_write_byte@plt>
lea    0x18(%rsp),%rbx
andb   $0xfe,0x18(%rsp)
mov    $0x18,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <ad9520_write_byte@plt>
movb   $0x1,0x232(%rsp)
01
mov    $0x232,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1070 <ad9520_write_byte@plt>
orb    $0x1,0x18(%rsp)
mov    $0x18,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <ad9520_write_byte@plt>
movb   $0x1,0x232(%rsp)
01
mov    $0x232,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1070 <ad9520_write_byte@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    12d0 <load_ad9520_from_file+0x160>
lea    0xd56(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    $0xffffffff,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd1d(%rip),%rdi
call   1090 <perror@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
jmp    12cb <load_ad9520_from_file+0x15b>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [17 x i8] c"Can't open file \00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [74 x i8] c"Error: read only %d out of 2820 expected bytes in AD9520 PLL config file\0A\00"
define i32 @load_ad9520_from_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [4096 x i8]
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%14 = load i8*, i8** %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i32 -1, i32* %2
br label %77
16: ; preds = %1
%17 = load i32, i32* %4
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%19 = call i32 @read(i32 %17, i8* %18, i32 2820)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 2820
br i1 %21, label %22, label %27
22: ; preds = %16
%23 = load i32, i32* %6
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %4
%26 = call i32 @close(i32 %25)
store i32 -1, i32* %2
br label %77
27: ; preds = %16
br label %28
28: ; preds = %27
br label %29
29: ; preds = %28
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 16
%31 = call i32 @ad9520_write_byte(i32 16, i8* %30, i32 15)
br label %32
32: ; preds = %29
br label %33
33: ; preds = %32
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 240
%35 = call i32 @ad9520_write_byte(i32 240, i8* %34, i32 14)
br label %36
36: ; preds = %33
br label %37
37: ; preds = %36
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 400
%39 = call i32 @ad9520_write_byte(i32 400, i8* %38, i32 11)
br label %40
40: ; preds = %37
br label %41
41: ; preds = %40
%42 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 480
%43 = call i32 @ad9520_write_byte(i32 480, i8* %42, i32 2)
br label %44
44: ; preds = %41
br label %45
45: ; preds = %44
%46 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 560
%47 = call i32 @ad9520_write_byte(i32 560, i8* %46, i32 1)
br label %48
48: ; preds = %45
br label %49
49: ; preds = %48
%50 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 562
store i8 1, i8* %50
%51 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 562
%52 = call i32 @ad9520_write_byte(i32 562, i8* %51, i32 1)
br label %53
53: ; preds = %49
br label %54
54: ; preds = %53
%55 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 24
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = and i32 %57, 254
%59 = trunc i32 %58 to i8
store i8 %59, i8* %55
%60 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 24
%61 = call i32 @ad9520_write_byte(i32 24, i8* %60, i32 1)
%62 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 562
store i8 1, i8* %62
%63 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 562
%64 = call i32 @ad9520_write_byte(i32 562, i8* %63, i32 1)
%65 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 24
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = or i32 %67, 1
%69 = trunc i32 %68 to i8
store i8 %69, i8* %65
%70 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 24
%71 = call i32 @ad9520_write_byte(i32 24, i8* %70, i32 1)
%72 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 562
store i8 1, i8* %72
%73 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 562
%74 = call i32 @ad9520_write_byte(i32 562, i8* %73, i32 1)
%75 = load i32, i32* %4
%76 = call i32 @close(i32 %75)
store i32 0, i32* %2
br label %77
77: ; preds = %54, %22, %12
%78 = load i32, i32* %2
ret i32 %78
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [17 x i8] c"Can't open file \00"
@.str.2 = [74 x i8] c"Error: read only %d out of 2820 expected bytes in AD9520 PLL config file\0A\00"
define i32 @load_ad9520_from_file(i8* nocapture %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) %0)
br label %39
10: ; preds = %1
%11 = call i32 @read(i32 %5, i8* %3, i32 2820)
%12 = icmp eq i32 %11, 2820
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%15 = tail call i32 @close(i32 %5)
br label %39
16: ; preds = %10
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 16
%18 = call i32 @ad9520_write_byte(i32 16, i8* %17, i32 15)
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 240
%20 = call i32 @ad9520_write_byte(i32 240, i8* %19, i32 14)
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 400
%22 = call i32 @ad9520_write_byte(i32 400, i8* %21, i32 11)
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 480
%24 = call i32 @ad9520_write_byte(i32 480, i8* %23, i32 2)
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 560
%26 = call i32 @ad9520_write_byte(i32 560, i8* %25, i32 1)
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 562
store i8 1, i8* %27
%28 = call i32 @ad9520_write_byte(i32 562, i8* %27, i32 1)
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 24
%30 = load i8, i8* %29
%31 = and i8 %30, -2
store i8 %31, i8* %29
%32 = call i32 @ad9520_write_byte(i32 24, i8* %29, i32 1)
store i8 1, i8* %27
%33 = call i32 @ad9520_write_byte(i32 562, i8* %27, i32 1)
%34 = load i8, i8* %29
%35 = or i8 %34, 1
store i8 %35, i8* %29
%36 = call i32 @ad9520_write_byte(i32 24, i8* %29, i32 1)
store i8 1, i8* %27
%37 = call i32 @ad9520_write_byte(i32 562, i8* %27, i32 1)
%38 = call i32 @close(i32 %5)
br label %39
39: ; preds = %16, %13, %7
%40 = phi i32 [ -1, %7 ], [ -1, %13 ], [ 0, %16 ]
ret i32 %40
}