#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 DateStamp[]) {
  int i, j;
  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], &DateStamp[i]) != 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    $0x70,%rsp
mov    0x30(%rbp),%rax
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    -0x60(%rbp),%rdx
lea    0xebc(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
cmp    $0x0,%eax
jne    1188 <read_header+0x58>
jmp    1318 <read_header+0x1e8>
lea    -0x60(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11ae <read_header+0x7e>
lea    0xe61(%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    0xe4b(%rip),%rsi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <fscanf@plt>
cmp    $0x5,%eax
je     11e6 <read_header+0xb6>
jmp    1318 <read_header+0x1e8>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    124d <read_header+0x11d>
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    0xe02(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
cmp    $0x2,%eax
je     123a <read_header+0x10a>
jmp    1318 <read_header+0x1e8>
jmp    123f <read_header+0x10f>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11ed <read_header+0xbd>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jge    12a5 <read_header+0x175>
mov    -0x10(%rbp),%rdi
mov    0x20(%rbp),%rdx
movslq -0x3c(%rbp),%rax
imul   $0xa,%rax,%rax
add    %rax,%rdx
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     1292 <read_header+0x162>
jmp    1318 <read_header+0x1e8>
jmp    1297 <read_header+0x167>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1254 <read_header+0x124>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x28(%rbp),%rcx
cmp    (%rcx),%eax
jge    130c <read_header+0x1dc>
mov    -0x10(%rbp),%rdi
mov    0x28(%rbp),%rdx
movslq -0x3c(%rbp),%rax
imul   $0x14,%rax,%rax
add    %rax,%rdx
mov    0x30(%rbp),%rcx
movslq -0x3c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rcx
lea    0xd43(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
cmp    $0x2,%eax
je     12f9 <read_header+0x1c9>
jmp    1318 <read_header+0x1e8>
jmp    12fe <read_header+0x1ce>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12ac <read_header+0x17c>
movl   $0x0,-0x4(%rbp)
jmp    132b <read_header+0x1fb>
lea    0xd13(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%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,0x10(%rsp)
mov    %rdx,0x18(%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     12b5 <read_header+0x185>
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    0x18(%rsp),%rcx
mov    0x10(%rsp),%r8
mov    %rbp,%r9
xor    %eax,%eax
call   1040 <fscanf@plt>
cmp    $0x5,%eax
jne    12b5 <read_header+0x185>
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    12b5 <read_header+0x185>
add    $0x1,%r15
movslq 0x0(%r13),%rax
add    $0x4,%rbx
add    $0xa,%rbp
cmp    %rax,%r15
jl     11e0 <read_header+0xb0>
mov    0x18(%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    12b5 <read_header+0x185>
add    $0x1,%rbp
mov    0x18(%rsp),%rax
movslq (%rax),%rax
add    $0xa,%rbx
cmp    %rax,%rbp
jl     1230 <read_header+0x100>
mov    0x10(%rsp),%rax
cmpl   $0x0,(%rax)
jle    12b1 <read_header+0x181>
mov    0xa0(%rsp),%r15
mov    0x98(%rsp),%rbp
lea    0xd9e(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1040 <fscanf@plt>
cmp    $0x2,%eax
jne    12b5 <read_header+0x185>
add    $0x1,%rbx
mov    0x10(%rsp),%rax
movslq (%rax),%rax
add    $0x4,%r15
add    $0x14,%rbp
cmp    %rax,%rbx
jl     1280 <read_header+0x150>
xor    %eax,%eax
jmp    12c6 <read_header+0x196>
lea    0xd68(%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, i32* %10) {
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i32*
%19 = alloca i32*
%20 = alloca [10 x i8]*
%21 = alloca [10 x i8]*
%22 = alloca [20 x i8]*
%23 = alloca i32*
%24 = alloca i32
%25 = alloca i32
%26 = alloca [30 x i8]
store i32* %0, i32** %13
store i32* %1, i32** %14
store i32* %2, i32** %15
store i32* %3, i32** %16
store i32* %4, i32** %17
store i32* %5, i32** %18
store i32* %6, i32** %19
store [10 x i8]* %7, [10 x i8]** %20
store [10 x i8]* %8, [10 x i8]** %21
store [20 x i8]* %9, [20 x i8]** %22
store i32* %10, i32** %23
%27 = load i32*, i32** %13
%28 = getelementptr inbounds [30 x i8], [30 x i8]* %26, i64 0, i64 0
%29 = call i32 (i32*, i8*, ...) @fscanf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %11
br label %117
32: ; preds = %11
%33 = getelementptr inbounds [30 x i8], [30 x i8]* %26, i64 0, i64 0
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %32
%39 = load i32*, i32** %13
%40 = load i32*, i32** %14
%41 = load i32*, i32** %15
%42 = load i32*, i32** %16
%43 = load i32*, i32** %18
%44 = load i32*, i32** %19
%45 = call i32 (i32*, i8*, ...) @fscanf(i32* %39, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32* %40, i32* %41, i32* %42, i32* %43, i32* %44)
%46 = icmp ne i32 %45, 5
br i1 %46, label %47, label %48
47: ; preds = %38
br label %117
48: ; preds = %38
store i32 0, i32* %24
br label %49
49: ; preds = %69, %48
%50 = load i32, i32* %24
%51 = load i32*, i32** %14
%52 = load i32, i32* %51
%53 = icmp slt i32 %50, %52
br i1 %53, label %54, label %72
54: ; preds = %49
%55 = load i32*, i32** %13
%56 = load [10 x i8]*, [10 x i8]** %20
%57 = load i32, i32* %24
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [10 x i8], [10 x i8]* %56, i64 %58
%60 = getelementptr inbounds [10 x i8], [10 x i8]* %59, i64 0, i64 0
%61 = load i32*, i32** %17
%62 = load i32, i32* %24
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %61, i64 %63
%65 = call i32 (i32*, i8*, ...) @fscanf(i32* %55, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %60, i32* %64)
%66 = icmp ne i32 %65, 2
br i1 %66, label %67, label %68
67: ; preds = %54
br label %117
68: ; preds = %54
br label %69
69: ; preds = %68
%70 = load i32, i32* %24
%71 = add nsw i32 %70, 1
store i32 %71, i32* %24
br label %49
72: ; preds = %49
store i32 0, i32* %24
br label %73
73: ; preds = %89, %72
%74 = load i32, i32* %24
%75 = load i32*, i32** %15
%76 = load i32, i32* %75
%77 = icmp slt i32 %74, %76
br i1 %77, label %78, label %92
78: ; preds = %73
%79 = load i32*, i32** %13
%80 = load [10 x i8]*, [10 x i8]** %21
%81 = load i32, i32* %24
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [10 x i8], [10 x i8]* %80, i64 %82
%84 = getelementptr inbounds [10 x i8], [10 x i8]* %83, i64 0, i64 0
%85 = call i32 (i32*, i8*, ...) @fscanf(i32* %79, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %84)
%86 = icmp ne i32 %85, 1
br i1 %86, label %87, label %88
87: ; preds = %78
br label %117
88: ; preds = %78
br label %89
89: ; preds = %88
%90 = load i32, i32* %24
%91 = add nsw i32 %90, 1
store i32 %91, i32* %24
br label %73
92: ; preds = %73
store i32 0, i32* %24
br label %93
93: ; preds = %113, %92
%94 = load i32, i32* %24
%95 = load i32*, i32** %16
%96 = load i32, i32* %95
%97 = icmp slt i32 %94, %96
br i1 %97, label %98, label %116
98: ; preds = %93
%99 = load i32*, i32** %13
%100 = load [20 x i8]*, [20 x i8]** %22
%101 = load i32, i32* %24
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds [20 x i8], [20 x i8]* %100, i64 %102
%104 = getelementptr inbounds [20 x i8], [20 x i8]* %103, i64 0, i64 0
%105 = load i32*, i32** %23
%106 = load i32, i32* %24
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds i32, i32* %105, i64 %107
%109 = call i32 (i32*, i8*, ...) @fscanf(i32* %99, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %104, i32* %108)
%110 = icmp ne i32 %109, 2
br i1 %110, label %111, label %112
111: ; preds = %98
br label %117
112: ; preds = %98
br label %113
113: ; preds = %112
%114 = load i32, i32* %24
%115 = add nsw i32 %114, 1
store i32 %115, i32* %24
br label %93
116: ; preds = %93
store i32 0, i32* %12
br label %119
117: ; preds = %111, %87, %67, %47, %31
%118 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %12
br label %119
119: ; preds = %117, %116
%120 = load i32, i32* %12
ret i32 %120
}

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