#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 fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
int read_header(FILE *fpin, int *NumVars, int *NumLev, int *NumTimes, int Nl[],
                int *Nr, int *Nc, char VarName[][10], char LevName[][10],
                char TStepName[][20]) {
  int i, j;
  int skip;
  char head_txt[30];
  if (fscanf(fpin, "%s", head_txt) == 0)
    goto err;
  if (strcmp(head_txt, "#to_vis5d") != 0)
    printf("header error\n");
  if (fscanf(fpin, "%i %i %i %i %i", NumVars, NumLev, NumTimes, Nr, Nc) != 5)
    goto err;
  for (i = 0; i < *NumVars; i++) {
    if (fscanf(fpin, " %s %i", VarName[i], &Nl[i]) != 2)
      goto err;
  }
  for (i = 0; i < *NumLev; i++) {
    if (fscanf(fpin, " %s", LevName[i]) != 1)
      goto err;
  }
  for (i = 0; i < *NumTimes; i++) {
    if (fscanf(fpin, " %s %i", TStepName[i], &skip) != 2)
      goto err;
  }
  return 0;
err:
  printf("error reading header file\n");
  return -1;
}


x86 assembly (clang, -O0):
<read_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rdx
lea    0xebd(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
cmp    $0x0,%eax
jne    1187 <read_header+0x57>
jmp    130c <read_header+0x1dc>
lea    -0x70(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11ad <read_header+0x7d>
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x38(%rbp),%r9
mov    0x10(%rbp),%rax
lea    0xe4c(%rip),%rsi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <fscanf@plt>
cmp    $0x5,%eax
je     11e5 <read_header+0xb5>
jmp    130c <read_header+0x1dc>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    124c <read_header+0x11c>
mov    -0x10(%rbp),%rdi
mov    0x18(%rbp),%rdx
movslq -0x3c(%rbp),%rax
imul   $0xa,%rax,%rax
add    %rax,%rdx
mov    -0x30(%rbp),%rcx
movslq -0x3c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rcx
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
cmp    $0x2,%eax
je     1239 <read_header+0x109>
jmp    130c <read_header+0x1dc>
jmp    123e <read_header+0x10e>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11ec <read_header+0xbc>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jge    12a4 <read_header+0x174>
mov    -0x10(%rbp),%rdi
mov    0x20(%rbp),%rdx
movslq -0x3c(%rbp),%rax
imul   $0xa,%rax,%rax
add    %rax,%rdx
lea    0xdb2(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     1291 <read_header+0x161>
jmp    130c <read_header+0x1dc>
jmp    1296 <read_header+0x166>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1253 <read_header+0x123>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x28(%rbp),%rcx
cmp    (%rcx),%eax
jge    1300 <read_header+0x1d0>
mov    -0x10(%rbp),%rdi
mov    0x28(%rbp),%rdx
movslq -0x3c(%rbp),%rax
imul   $0x14,%rax,%rax
add    %rax,%rdx
lea    0xd53(%rip),%rsi
lea    -0x44(%rbp),%rcx
mov    $0x0,%al
call   1040 <fscanf@plt>
cmp    $0x2,%eax
je     12ed <read_header+0x1bd>
jmp    130c <read_header+0x1dc>
jmp    12f2 <read_header+0x1c2>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12ab <read_header+0x17b>
movl   $0x0,-0x4(%rbp)
jmp    131f <read_header+0x1ef>
lea    0xd1f(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_header>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9,%rbp
mov    %r8,%rbx
mov    %rcx,0x8(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rsi,%r13
mov    %rdi,%r12
lea    0xec6(%rip),%rsi
lea    0x20(%rsp),%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
test   %eax,%eax
je     12b1 <read_header+0x181>
mov    0x80(%rsp),%r14
lea    0xe82(%rip),%rsi
lea    0x20(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1199 <read_header+0x69>
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,(%rsp)
lea    0xe66(%rip),%rsi
mov    %r12,%rdi
mov    %r13,%rdx
mov    0x10(%rsp),%rcx
mov    0x8(%rsp),%r8
mov    %rbp,%r9
xor    %eax,%eax
call   1040 <fscanf@plt>
cmp    $0x5,%eax
jne    12b1 <read_header+0x181>
cmpl   $0x0,0x0(%r13)
jle    1211 <read_header+0xe1>
mov    0x88(%rsp),%rbp
lea    0xe3c(%rip),%r14
xor    %r15d,%r15d
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <fscanf@plt>
cmp    $0x2,%eax
jne    12b1 <read_header+0x181>
add    $0x1,%r15
movslq 0x0(%r13),%rax
add    $0x4,%rbx
add    $0xa,%rbp
cmp    %rax,%r15
jl     11e0 <read_header+0xb0>
mov    0x10(%rsp),%rax
cmpl   $0x0,(%rax)
jle    125a <read_header+0x12a>
mov    0x90(%rsp),%rbx
lea    0xdf6(%rip),%r14
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    12b1 <read_header+0x181>
add    $0x1,%rbp
mov    0x10(%rsp),%rax
movslq (%rax),%rax
add    $0xa,%rbx
cmp    %rax,%rbp
jl     1230 <read_header+0x100>
mov    0x8(%rsp),%rax
cmpl   $0x0,(%rax)
jle    12ad <read_header+0x17d>
mov    0x98(%rsp),%rbx
lea    0xda6(%rip),%r14
lea    0x1c(%rsp),%r15
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1040 <fscanf@plt>
cmp    $0x2,%eax
jne    12b1 <read_header+0x181>
add    $0x1,%rbp
mov    0x8(%rsp),%rax
movslq (%rax),%rax
add    $0x14,%rbx
cmp    %rax,%rbp
jl     1280 <read_header+0x150>
xor    %eax,%eax
jmp    12c2 <read_header+0x192>
lea    0xd6c(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [10 x i8] c"#to_vis5d\00"
@.str.2 = [14 x i8] c"header error\0A\00"
@.str.3 = [15 x i8] c"%i %i %i %i %i\00"
@.str.4 = [7 x i8] c" %s %i\00"
@.str.5 = [4 x i8] c" %s\00"
@.str.6 = [27 x i8] c"error reading header file\0A\00"
define i32 @read_header(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, [10 x i8]* %7, [10 x i8]* %8, [20 x i8]* %9) {
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i32*
%19 = alloca [10 x i8]*
%20 = alloca [10 x i8]*
%21 = alloca [20 x i8]*
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca [30 x i8]
store i32* %0, i32** %12
store i32* %1, i32** %13
store i32* %2, i32** %14
store i32* %3, i32** %15
store i32* %4, i32** %16
store i32* %5, i32** %17
store i32* %6, i32** %18
store [10 x i8]* %7, [10 x i8]** %19
store [10 x i8]* %8, [10 x i8]** %20
store [20 x i8]* %9, [20 x i8]** %21
%26 = load i32*, i32** %12
%27 = getelementptr inbounds [30 x i8], [30 x i8]* %25, i64 0, i64 0
%28 = call i32 (i32*, i8*, ...) @fscanf(i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %10
br label %112
31: ; preds = %10
%32 = getelementptr inbounds [30 x i8], [30 x i8]* %25, i64 0, i64 0
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %31
%38 = load i32*, i32** %12
%39 = load i32*, i32** %13
%40 = load i32*, i32** %14
%41 = load i32*, i32** %15
%42 = load i32*, i32** %17
%43 = load i32*, i32** %18
%44 = call i32 (i32*, i8*, ...) @fscanf(i32* %38, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32* %39, i32* %40, i32* %41, i32* %42, i32* %43)
%45 = icmp ne i32 %44, 5
br i1 %45, label %46, label %47
46: ; preds = %37
br label %112
47: ; preds = %37
store i32 0, i32* %22
br label %48
48: ; preds = %68, %47
%49 = load i32, i32* %22
%50 = load i32*, i32** %13
%51 = load i32, i32* %50
%52 = icmp slt i32 %49, %51
br i1 %52, label %53, label %71
53: ; preds = %48
%54 = load i32*, i32** %12
%55 = load [10 x i8]*, [10 x i8]** %19
%56 = load i32, i32* %22
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [10 x i8], [10 x i8]* %55, i64 %57
%59 = getelementptr inbounds [10 x i8], [10 x i8]* %58, i64 0, i64 0
%60 = load i32*, i32** %16
%61 = load i32, i32* %22
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %60, i64 %62
%64 = call i32 (i32*, i8*, ...) @fscanf(i32* %54, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %59, i32* %63)
%65 = icmp ne i32 %64, 2
br i1 %65, label %66, label %67
66: ; preds = %53
br label %112
67: ; preds = %53
br label %68
68: ; preds = %67
%69 = load i32, i32* %22
%70 = add nsw i32 %69, 1
store i32 %70, i32* %22
br label %48
71: ; preds = %48
store i32 0, i32* %22
br label %72
72: ; preds = %88, %71
%73 = load i32, i32* %22
%74 = load i32*, i32** %14
%75 = load i32, i32* %74
%76 = icmp slt i32 %73, %75
br i1 %76, label %77, label %91
77: ; preds = %72
%78 = load i32*, i32** %12
%79 = load [10 x i8]*, [10 x i8]** %20
%80 = load i32, i32* %22
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [10 x i8], [10 x i8]* %79, i64 %81
%83 = getelementptr inbounds [10 x i8], [10 x i8]* %82, i64 0, i64 0
%84 = call i32 (i32*, i8*, ...) @fscanf(i32* %78, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %83)
%85 = icmp ne i32 %84, 1
br i1 %85, label %86, label %87
86: ; preds = %77
br label %112
87: ; preds = %77
br label %88
88: ; preds = %87
%89 = load i32, i32* %22
%90 = add nsw i32 %89, 1
store i32 %90, i32* %22
br label %72
91: ; preds = %72
store i32 0, i32* %22
br label %92
92: ; preds = %108, %91
%93 = load i32, i32* %22
%94 = load i32*, i32** %15
%95 = load i32, i32* %94
%96 = icmp slt i32 %93, %95
br i1 %96, label %97, label %111
97: ; preds = %92
%98 = load i32*, i32** %12
%99 = load [20 x i8]*, [20 x i8]** %21
%100 = load i32, i32* %22
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds [20 x i8], [20 x i8]* %99, i64 %101
%103 = getelementptr inbounds [20 x i8], [20 x i8]* %102, i64 0, i64 0
%104 = call i32 (i32*, i8*, ...) @fscanf(i32* %98, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %103, i32* %24)
%105 = icmp ne i32 %104, 2
br i1 %105, label %106, label %107
106: ; preds = %97
br label %112
107: ; preds = %97
br label %108
108: ; preds = %107
%109 = load i32, i32* %22
%110 = add nsw i32 %109, 1
store i32 %110, i32* %22
br label %92
111: ; preds = %92
store i32 0, i32* %11
br label %114
112: ; preds = %106, %86, %66, %46, %30
%113 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %11
br label %114
114: ; preds = %112, %111
%115 = load i32, i32* %11
ret i32 %115
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [10 x i8] c"#to_vis5d\00"
@.str.3 = [15 x i8] c"%i %i %i %i %i\00"
@.str.4 = [7 x i8] c" %s %i\00"
@.str.5 = [4 x i8] c" %s\00"
@str = [26 x i8] c"error reading header file\00"
@str.7 = [13 x i8] c"header error\00"
define i32 @read_header(i32* nocapture %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, [10 x i8]* %7, [10 x i8]* %8, [20 x i8]* %9) {
%11 = alloca i32
%12 = alloca [30 x i8]
%13 = bitcast i32* %11 to i8*
%14 = getelementptr inbounds [30 x i8], [30 x i8]* %12, i64 0, i64 0
%15 = call i32 (i32*, i8*, ...) @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %65, label %17
17: ; preds = %10
%18 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = call i32 (i32*, i8*, ...) @fscanf(i32* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32* %1, i32* %2, i32* %3, i32* %5, i32* %6)
%24 = icmp eq i32 %23, 5
br i1 %24, label %25, label %65
25: ; preds = %22
%26 = load i32, i32* %1
%27 = icmp sgt i32 %26, 0
br i1 %27, label %35, label %32
28: ; preds = %35
%29 = load i32, i32* %1
%30 = sext i32 %29 to i64
%31 = icmp slt i64 %41, %30
br i1 %31, label %35, label %32
32: ; preds = %28, %25
%33 = load i32, i32* %2
%34 = icmp sgt i32 %33, 0
br i1 %34, label %49, label %46
35: ; preds = %25, %28
%36 = phi i64 [ %41, %28 ], [ 0, %25 ]
%37 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 %36, i64 0
%38 = getelementptr inbounds i32, i32* %4, i64 %36
%39 = call i32 (i32*, i8*, ...) @fscanf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %37, i32* %38)
%40 = icmp eq i32 %39, 2
%41 = add nuw nsw i64 %36, 1
br i1 %40, label %28, label %65
42: ; preds = %49
%43 = load i32, i32* %2
%44 = sext i32 %43 to i64
%45 = icmp slt i64 %54, %44
br i1 %45, label %49, label %46
46: ; preds = %42, %32
%47 = load i32, i32* %3
%48 = icmp sgt i32 %47, 0
br i1 %48, label %59, label %67
49: ; preds = %32, %42
%50 = phi i64 [ %54, %42 ], [ 0, %32 ]
%51 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 %50, i64 0
%52 = call i32 (i32*, i8*, ...) @fscanf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %51)
%53 = icmp eq i32 %52, 1
%54 = add nuw nsw i64 %50, 1
br i1 %53, label %42, label %65
55: ; preds = %59
%56 = load i32, i32* %3
%57 = sext i32 %56 to i64
%58 = icmp slt i64 %64, %57
br i1 %58, label %59, label %67
59: ; preds = %46, %55
%60 = phi i64 [ %64, %55 ], [ 0, %46 ]
%61 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 %60, i64 0
%62 = call i32 (i32*, i8*, ...) @fscanf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %61, i32* %11)
%63 = icmp eq i32 %62, 2
%64 = add nuw nsw i64 %60, 1
br i1 %63, label %55, label %65
65: ; preds = %35, %49, %59, %22, %10
%66 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %67
67: ; preds = %55, %46, %65
%68 = phi i32 [ -1, %65 ], [ 0, %46 ], [ 0, %55 ]
ret i32 %68
}