#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned short *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int read_calibration(int buf[4][2]) {
  int i, j, k = 0;
  unsigned short cal[4 * 2];
  FILE *f = fopen("/etc/ADC-calibration.dat", "r");
  if (!f)
    goto empty_calibration;
  printf("Non-virgin board detected, evaluating stored "
         "calibration values\n");
  printf("Stored Calibration values [");
  if (fread(cal, 4 * 4, 1, f) == 1) {
    for (j = 0; j < 2; j++)
      for (i = 0; i < 4; i++) {
        printf("0x%x", cal[k]);
        buf[i][j] = cal[k];
        k++;
        if (k < 4 * 2)
          printf(", ");
      }
    printf("]\n");
    return 1;
  }
empty_calibration:
  printf("/etc/ADC-calibration.dat not found or it's not readable\n");
  return 0;
}


x86 assembly (clang, -O0):
<read_calibration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xeb6(%rip),%rdi
lea    0xec8(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    116a <read_calibration+0x3a>
jmp    1264 <read_calibration+0x134>
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rcx
mov    $0x10,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    125f <read_calibration+0x12f>
movl   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x18(%rbp)
jge    1245 <read_calibration+0x115>
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    1232 <read_calibration+0x102>
movslq -0x1c(%rbp),%rax
movzwl -0x30(%rbp,%rax,2),%esi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x1c(%rbp),%rax
movzwl -0x30(%rbp,%rax,2),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    121f <read_calibration+0xef>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1224 <read_calibration+0xf4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11be <read_calibration+0x8e>
jmp    1237 <read_calibration+0x107>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ad <read_calibration+0x7d>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1279 <read_calibration+0x149>
jmp    1264 <read_calibration+0x134>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_calibration>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r12
lea    0xeaa(%rip),%rdi
lea    0xebc(%rip),%rsi
call   1060 <fopen@plt>
lea    0xed6(%rip),%r14
test   %rax,%rax
je     12bf <read_calibration+0x17f>
mov    %rax,%rbx
lea    0xefb(%rip),%rdi
call   1030 <puts@plt>
lea    0xe93(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rdi
mov    $0x10,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    12c1 <read_calibration+0x181>
movzwl (%rsp),%ebx
lea    0xe7d(%rip),%r14
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,(%r12)
lea    0xe6b(%rip),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzwl 0x2(%rsp),%ebx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,0x8(%r12)
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzwl 0x4(%rsp),%ebx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,0x10(%r12)
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzwl 0x6(%rsp),%ebx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,0x18(%r12)
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzwl 0x8(%rsp),%ebx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,0x4(%r12)
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzwl 0xa(%rsp),%ebx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,0xc(%r12)
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzwl 0xc(%rsp),%ebx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,0x14(%r12)
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzwl 0xe(%rsp),%ebx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,0x1c(%r12)
lea    0xdff(%rip),%r14
mov    $0x1,%ebp
jmp    12c1 <read_calibration+0x181>
xor    %ebp,%ebp
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"/etc/ADC-calibration.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [65 x i8] c"Non-virgin board detected, evaluating stored calibration values\0A\00"
@.str.3 = [28 x i8] c"Stored Calibration values [\00"
@.str.4 = [5 x i8] c"0x%x\00"
@.str.5 = [3 x i8] c", \00"
@.str.6 = [3 x i8] c"]\0A\00"
@.str.7 = [57 x i8] c"/etc/ADC-calibration.dat not found or it's not readable\0A\00"
define i32 @read_calibration([2 x i32]* %0) {
%2 = alloca i32
%3 = alloca [2 x i32]*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [8 x i16]
%8 = alloca i32*
store [2 x i32]* %0, [2 x i32]** %3
store i32 0, i32* %6
%9 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %8
%10 = load i32*, i32** %8
%11 = icmp ne i32* %10, null
br i1 %11, label %13, label %12
12: ; preds = %1
br label %64
13: ; preds = %1
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%16 = getelementptr inbounds [8 x i16], [8 x i16]* %7, i64 0, i64 0
%17 = load i32*, i32** %8
%18 = call i32 @fread(i16* %16, i32 16, i32 1, i32* %17)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %63
20: ; preds = %13
store i32 0, i32* %5
br label %21
21: ; preds = %58, %20
%22 = load i32, i32* %5
%23 = icmp slt i32 %22, 2
br i1 %23, label %24, label %61
24: ; preds = %21
store i32 0, i32* %4
br label %25
25: ; preds = %54, %24
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 4
br i1 %27, label %28, label %57
28: ; preds = %25
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [8 x i16], [8 x i16]* %7, i64 0, i64 %30
%32 = load i16, i16* %31
%33 = zext i16 %32 to i32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [8 x i16], [8 x i16]* %7, i64 0, i64 %36
%38 = load i16, i16* %37
%39 = zext i16 %38 to i32
%40 = load [2 x i32]*, [2 x i32]** %3
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %40, i64 %42
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %43, i64 0, i64 %45
store i32 %39, i32* %46
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
%49 = load i32, i32* %6
%50 = icmp slt i32 %49, 8
br i1 %50, label %51, label %53
51: ; preds = %28
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %53
53: ; preds = %51, %28
br label %54
54: ; preds = %53
%55 = load i32, i32* %4
%56 = add nsw i32 %55, 1
store i32 %56, i32* %4
br label %25
57: ; preds = %25
br label %58
58: ; preds = %57
%59 = load i32, i32* %5
%60 = add nsw i32 %59, 1
store i32 %60, i32* %5
br label %21
61: ; preds = %21
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %2
br label %66
63: ; preds = %13
br label %64
64: ; preds = %63, %12
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %2
br label %66
66: ; preds = %64, %61
%67 = load i32, i32* %2
ret i32 %67
}

LLVM IR (-O2):
@.str = [25 x i8] c"/etc/ADC-calibration.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [28 x i8] c"Stored Calibration values [\00"
@.str.4 = [5 x i8] c"0x%x\00"
@.str.5 = [3 x i8] c", \00"
@str = [56 x i8] c"/etc/ADC-calibration.dat not found or it's not readable\00"
@str.8 = [64 x i8] c"Non-virgin board detected, evaluating stored calibration values\00"
@str.9 = [2 x i8] c"]\00"
define i32 @read_calibration([2 x i32]* nocapture writeonly %0) {
%2 = alloca [8 x i16]
%3 = bitcast [8 x i16]* %2 to i8*
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %59, label %6
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str.8, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%9 = getelementptr inbounds [8 x i16], [8 x i16]* %2, i64 0, i64 0
%10 = call i32 @fread(i16* %9, i32 16, i32 1, i32* %4)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %59
12: ; preds = %6
%13 = load i16, i16* %9
%14 = zext i16 %13 to i32
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 0, i64 0
store i32 %14, i32* %16
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%18 = getelementptr inbounds [8 x i16], [8 x i16]* %2, i64 0, i64 1
%19 = load i16, i16* %18
%20 = zext i16 %19 to i32
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 1, i64 0
store i32 %20, i32* %22
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%24 = getelementptr inbounds [8 x i16], [8 x i16]* %2, i64 0, i64 2
%25 = load i16, i16* %24
%26 = zext i16 %25 to i32
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 2, i64 0
store i32 %26, i32* %28
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%30 = getelementptr inbounds [8 x i16], [8 x i16]* %2, i64 0, i64 3
%31 = load i16, i16* %30
%32 = zext i16 %31 to i32
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 3, i64 0
store i32 %32, i32* %34
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%36 = getelementptr inbounds [8 x i16], [8 x i16]* %2, i64 0, i64 4
%37 = load i16, i16* %36
%38 = zext i16 %37 to i32
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 0, i64 1
store i32 %38, i32* %40
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%42 = getelementptr inbounds [8 x i16], [8 x i16]* %2, i64 0, i64 5
%43 = load i16, i16* %42
%44 = zext i16 %43 to i32
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %44)
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 1, i64 1
store i32 %44, i32* %46
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%48 = getelementptr inbounds [8 x i16], [8 x i16]* %2, i64 0, i64 6
%49 = load i16, i16* %48
%50 = zext i16 %49 to i32
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %50)
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 2, i64 1
store i32 %50, i32* %52
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%54 = getelementptr inbounds [8 x i16], [8 x i16]* %2, i64 0, i64 7
%55 = load i16, i16* %54
%56 = zext i16 %55 to i32
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %56)
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 3, i64 1
store i32 %56, i32* %58
br label %59
59: ; preds = %1, %6, %12
%60 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.9, i64 0, i64 0), %12 ], [ getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0), %6 ], [ getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0), %1 ]
%61 = phi i32 [ 1, %12 ], [ 0, %6 ], [ 0, %1 ]
%62 = tail call i32 @puts(i8* dereferenceable(1) %60)
ret i32 %61
}