#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 EOF;
int /*<<< orphan*/ exit(int);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *, int *, int *, float *);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, ...);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int verbose();
void read_table(const char *fname, float **vals, int *n) {
  const int max_size = 4096;
  char errmsg[1024];
  char buf[1024];
  FILE *f = fopen(fname, "r");
  if (f == 0) {
    snprintf(errmsg, 1024, "Opening dimension table %s", fname);
    perror(errmsg);
    exit(1);
  }
  *n = 0;
  *vals = (float *)malloc(sizeof(float) * max_size);
  while (1) {
    int c = fgetc(f);
    if (c == EOF) {
      return;
    } else if (c == '#') {
      fgets(buf, 1024, f);
      if (verbose() > 1)
        printf("#%s", buf);
    } else {
      int ret;
      int i, dummy1, dummy2;
      float val;
      ungetc(c, f);
      ret = fscanf(f, " %d %d %d %f", &i, &dummy1, &dummy2, &val);
      if (ret == 4) {
        (*vals)[(*n)++] = val;
        if (i != *n) {
          snprintf(errmsg, 1024,
                   "Reading from dimension table %s: "
                   "line beginning with '%d' is not in order",
                   fname, i);
          perror(errmsg);
          exit(1);
        }
      } else {
        break;
      }
    }
  }
  if (verbose()) {
    printf("read %d values, first %f ... last %f\n", *n, (*vals)[0],
           (*vals)[*n - 1]);
  }
}


x86 assembly (clang, -O0):
<read_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1000,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x828(%rbp)
cmpq   $0x0,-0x828(%rbp)
jne    1227 <read_table+0x77>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x400,%esi
lea    0xdf6(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x420(%rbp),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    $0x4000,%edi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x828(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x82c(%rbp)
mov    -0x82c(%rbp),%eax
mov    0x2d84(%rip),%rcx
cmp    (%rcx),%eax
jne    1271 <read_table+0xc1>
jmp    13ed <read_table+0x23d>
cmpl   $0x23,-0x82c(%rbp)
jne    12c0 <read_table+0x110>
lea    -0x820(%rbp),%rdi
mov    -0x828(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
mov    $0x0,%al
call   10c0 <verbose@plt>
cmp    $0x1,%eax
jle    12bb <read_table+0x10b>
lea    -0x820(%rbp),%rsi
lea    0xd67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1394 <read_table+0x1e4>
mov    -0x82c(%rbp),%edi
mov    -0x828(%rbp),%rsi
call   1090 <ungetc@plt>
mov    -0x828(%rbp),%rdi
lea    0xd3f(%rip),%rsi
lea    -0x834(%rbp),%rdx
lea    -0x838(%rbp),%rcx
lea    -0x83c(%rbp),%r8
lea    -0x840(%rbp),%r9
call   1050 <fscanf@plt>
mov    %eax,-0x830(%rbp)
cmpl   $0x4,-0x830(%rbp)
jne    138a <read_table+0x1da>
movss  -0x840(%rbp),%xmm0
ff
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rdx
mov    (%rdx),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,(%rdx)
movslq %ecx,%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x834(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
je     1385 <read_table+0x1d5>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    -0x834(%rbp),%r8d
mov    $0x400,%esi
lea    0xcc4(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x420(%rbp),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    138f <read_table+0x1df>
jmp    139e <read_table+0x1ee>
jmp    1394 <read_table+0x1e4>
jmp    1399 <read_table+0x1e9>
jmp    1245 <read_table+0x95>
mov    $0x0,%al
call   10c0 <verbose@plt>
cmp    $0x0,%eax
je     13ed <read_table+0x23d>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xc90(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_table>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x828,%rsp
mov    %rdx,%r12
mov    %rsi,%r15
lea    0xea6(%rip),%rsi
mov    %rdi,0x10(%rsp)
call   10a0 <fopen@plt>
test   %rax,%rax
je     1344 <read_table+0x194>
mov    %rax,%rbx
movl   $0x0,(%r12)
mov    $0x4000,%edi
call   1080 <malloc@plt>
mov    %rax,(%r15)
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    0x2de0(%rip),%rbp
cmp    0x0(%rbp),%eax
jne    121f <read_table+0x6f>
add    $0x828,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x420(%rsp),%r13
lea    0x8(%rsp),%r14
jmp    123d <read_table+0x8d>
xchg   %ax,%ax
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    0x0(%rbp),%eax
je     120d <read_table+0x5d>
cmp    $0x23,%eax
jne    1280 <read_table+0xd0>
mov    %r13,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
xor    %eax,%eax
call   10c0 <verbose@plt>
cmp    $0x2,%eax
jl     1230 <read_table+0x80>
lea    0xdb6(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1230 <read_table+0x80>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
mov    %rbx,%rsi
call   1090 <ungetc@plt>
mov    %rbx,%rdi
lea    0xd8b(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x1c(%rsp),%rcx
lea    0x18(%rsp),%r8
mov    %r14,%r9
call   1050 <fscanf@plt>
cmp    $0x4,%eax
jne    1309 <read_table+0x159>
movss  0x8(%rsp),%xmm0
mov    (%r15),%rax
movslq (%r12),%rcx
lea    0x1(%rcx),%edx
mov    %edx,(%r12)
movss  %xmm0,(%rax,%rcx,4)
mov    0xc(%rsp),%r8d
cmp    %edx,%r8d
je     1230 <read_table+0x80>
lea    0xd4e(%rip),%rdx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    0x10(%rsp),%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
xor    %eax,%eax
call   10c0 <verbose@plt>
test   %eax,%eax
je     120d <read_table+0x5d>
movslq (%r12),%rsi
mov    (%r15),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x4(%rax,%rsi,4),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xd3e(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
jmp    120d <read_table+0x5d>
lea    0xcb5(%rip),%rdx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    0x10(%rsp),%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    12f7 <read_table+0x147>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [27 x i8] c"Opening dimension table %s\00"
@EOF = global i32 0
@.str.2 = [4 x i8] c"#%s\00"
@.str.3 = [13 x i8] c" %d %d %d %f\00"
@.str.4 = [74 x i8] c"Reading from dimension table %s: line beginning with '%d' is not in order\00"
@.str.5 = [38 x i8] c"read %d values, first %f ... last %f\0A\00"
define void @read_table(i8* %0, float** %1, i32* %2) {
%4 = alloca i8*
%5 = alloca float**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca [1024 x i8]
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca float
store i8* %0, i8** %4
store float** %1, float*** %5
store i32* %2, i32** %6
store i32 4096, i32* %7
%17 = load i8*, i8** %4
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %10
%19 = load i32*, i32** %10
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %28
21: ; preds = %3
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%23 = load i8*, i8** %4
%24 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %22, i32 1024, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%26 = call i32 @perror(i8* %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %3
%29 = load i32*, i32** %6
store i32 0, i32* %29
%30 = call i64 @malloc(i32 16384)
%31 = inttoptr i64 %30 to float*
%32 = load float**, float*** %5
store float* %31, float** %32
br label %33
33: ; preds = %28, %86
%34 = load i32*, i32** %10
%35 = call i32 @fgetc(i32* %34)
store i32 %35, i32* %11
%36 = load i32, i32* %11
%37 = load i32, i32* @EOF
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %40
39: ; preds = %33
br label %108
40: ; preds = %33
%41 = load i32, i32* %11
%42 = icmp eq i32 %41, 35
br i1 %42, label %43, label %53
43: ; preds = %40
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%45 = load i32*, i32** %10
%46 = call i32 @fgets(i8* %44, i32 1024, i32* %45)
%47 = call i32 (...) @verbose()
%48 = icmp sgt i32 %47, 1
br i1 %48, label %49, label %52
49: ; preds = %43
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %49, %43
br label %85
53: ; preds = %40
%54 = load i32, i32* %11
%55 = load i32*, i32** %10
%56 = call i32 @ungetc(i32 %54, i32* %55)
%57 = load i32*, i32** %10
%58 = call i32 @fscanf(i32* %57, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32* %13, i32* %14, i32* %15, float* %16)
store i32 %58, i32* %12
%59 = load i32, i32* %12
%60 = icmp eq i32 %59, 4
br i1 %60, label %61, label %83
61: ; preds = %53
%62 = load float, float* %16
%63 = load float**, float*** %5
%64 = load float*, float** %63
%65 = load i32*, i32** %6
%66 = load i32, i32* %65
%67 = add nsw i32 %66, 1
store i32 %67, i32* %65
%68 = sext i32 %66 to i64
%69 = getelementptr inbounds float, float* %64, i64 %68
store float %62, float* %69
%70 = load i32, i32* %13
%71 = load i32*, i32** %6
%72 = load i32, i32* %71
%73 = icmp ne i32 %70, %72
br i1 %73, label %74, label %82
74: ; preds = %61
%75 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%76 = load i8*, i8** %4
%77 = load i32, i32* %13
%78 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %75, i32 1024, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.4, i64 0, i64 0), i8* %76, i32 %77)
%79 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%80 = call i32 @perror(i8* %79)
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %61
br label %84
83: ; preds = %53
br label %87
84: ; preds = %82
br label %85
85: ; preds = %84, %52
br label %86
86: ; preds = %85
br label %33
87: ; preds = %83
%88 = call i32 (...) @verbose()
%89 = icmp ne i32 %88, 0
br i1 %89, label %90, label %108
90: ; preds = %87
%91 = load i32*, i32** %6
%92 = load i32, i32* %91
%93 = load float**, float*** %5
%94 = load float*, float** %93
%95 = getelementptr inbounds float, float* %94, i64 0
%96 = load float, float* %95
%97 = fpext float %96 to double
%98 = load float**, float*** %5
%99 = load float*, float** %98
%100 = load i32*, i32** %6
%101 = load i32, i32* %100
%102 = sub nsw i32 %101, 1
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds float, float* %99, i64 %103
%105 = load float, float* %104
%106 = fpext float %105 to double
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %92, double %97, double %106)
br label %108
108: ; preds = %39, %90, %87
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [27 x i8] c"Opening dimension table %s\00"
@EOF = global i32 0
@.str.2 = [4 x i8] c"#%s\00"
@.str.3 = [13 x i8] c" %d %d %d %f\00"
@.str.4 = [74 x i8] c"Reading from dimension table %s: line beginning with '%d' is not in order\00"
@.str.5 = [38 x i8] c"read %d values, first %f ... last %f\0A\00"
define void @read_table(i8* %0, float** nocapture %1, i32* nocapture %2) {
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca float
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %10, i32 1024, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%16 = call i32 @perror(i8* %10)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %3
store i32 0, i32* %2
%19 = tail call i64 @malloc(i32 16384)
%20 = inttoptr i64 %19 to float*
store float* %20, float** %1
%21 = call i32 @fgetc(i32* %12)
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %74, label %24
24: ; preds = %18
%25 = bitcast i32* %6 to i8*
%26 = bitcast i32* %7 to i8*
%27 = bitcast i32* %8 to i8*
%28 = bitcast float* %9 to i8*
br label %29
29: ; preds = %24, %56
%30 = phi i32 [ %21, %24 ], [ %57, %56 ]
%31 = icmp eq i32 %30, 35
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = call i32 @fgets(i8* %11, i32 1024, i32* %12)
%34 = call i32 (...) @verbose()
%35 = icmp sgt i32 %34, 1
br i1 %35, label %36, label %56
36: ; preds = %32
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %11)
br label %56
38: ; preds = %29
%39 = call i32 @ungetc(i32 %30, i32* %12)
%40 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32* %6, i32* %7, i32* %8, float* %9)
%41 = icmp eq i32 %40, 4
br i1 %41, label %42, label %60
42: ; preds = %38
%43 = load float, float* %9
%44 = load float*, float** %1
%45 = load i32, i32* %2
%46 = add nsw i32 %45, 1
store i32 %46, i32* %2
%47 = sext i32 %45 to i64
%48 = getelementptr inbounds float, float* %44, i64 %47
store float %43, float* %48
%49 = load i32, i32* %6
%50 = icmp eq i32 %49, %46
br i1 %50, label %51, label %52
51: ; preds = %42
br label %56
52: ; preds = %42
%53 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %10, i32 1024, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.4, i64 0, i64 0), i8* %0, i32 %49)
%54 = call i32 @perror(i8* %10)
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %32, %36, %51
%57 = call i32 @fgetc(i32* %12)
%58 = load i32, i32* @EOF
%59 = icmp eq i32 %57, %58
br i1 %59, label %74, label %29
60: ; preds = %38
%61 = call i32 (...) @verbose()
%62 = icmp eq i32 %61, 0
br i1 %62, label %74, label %63
63: ; preds = %60
%64 = load i32, i32* %2
%65 = load float*, float** %1
%66 = load float, float* %65
%67 = fpext float %66 to double
%68 = add nsw i32 %64, -1
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds float, float* %65, i64 %69
%71 = load float, float* %70
%72 = fpext float %71 to double
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %64, double %67, double %72)
br label %74
74: ; preds = %56, %18, %60, %63
ret void
}