#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *, ...);
int getshc(char *fname, int *nmax, double *erad, double *gh) {
  char dummy[256];
  int nn, mm, n, m;
  double g, h;
  double yr;
  FILE *fp;
  int stat;
  int i = 0;
  fp = fopen(fname, "r");
  if (fp == NULL)
    return -1;
  stat = (fgets(dummy, 256, fp) == NULL);
  if (stat != 0) {
    fclose(fp);
    return -1;
  }
  stat = (fscanf(fp, "%d %lg %lg", nmax, erad, &yr) != 3);
  if (stat != 0) {
    fclose(fp);
    return -1;
  }
  for (nn = 1; nn <= *nmax; nn++) {
    for (mm = 0; mm <= nn; mm++) {
      stat = (fscanf(fp, "%d %d  %lg %lg ", &n, &m, &g, &h) != 4);
      if (stat != 0) {
        fclose(fp);
        return -1;
      }
      gh[i] = g;
      i++;
      if (m != 0) {
        gh[i] = h;
        i++;
      }
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<getshc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x168(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe90(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x160(%rbp)
cmpq   $0x0,-0x160(%rbp)
jne    1196 <getshc+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    137e <getshc+0x23e>
lea    -0x130(%rbp),%rdi
mov    -0x160(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x164(%rbp)
cmpl   $0x0,-0x164(%rbp)
je     11e5 <getshc+0xa5>
mov    -0x160(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    137e <getshc+0x23e>
mov    -0x160(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe07(%rip),%rsi
lea    -0x158(%rbp),%r8
mov    $0x0,%al
call   1040 <fscanf@plt>
cmp    $0x3,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x164(%rbp)
cmpl   $0x0,-0x164(%rbp)
je     123f <getshc+0xff>
mov    -0x160(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    137e <getshc+0x23e>
movl   $0x1,-0x134(%rbp)
mov    -0x134(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jg     136b <getshc+0x22b>
movl   $0x0,-0x138(%rbp)
mov    -0x138(%rbp),%eax
cmp    -0x134(%rbp),%eax
jg     1352 <getshc+0x212>
mov    -0x160(%rbp),%rdi
lea    0xd88(%rip),%rsi
lea    -0x13c(%rbp),%rdx
lea    -0x140(%rbp),%rcx
lea    -0x148(%rbp),%r8
lea    -0x150(%rbp),%r9
mov    $0x0,%al
call   1040 <fscanf@plt>
cmp    $0x4,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x164(%rbp)
cmpl   $0x0,-0x164(%rbp)
je     12de <getshc+0x19e>
mov    -0x160(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    137e <getshc+0x23e>
movsd  -0x148(%rbp),%xmm0
ff
mov    -0x28(%rbp),%rax
movslq -0x168(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x168(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x168(%rbp)
cmpl   $0x0,-0x140(%rbp)
je     1339 <getshc+0x1f9>
movsd  -0x150(%rbp),%xmm0
ff
mov    -0x28(%rbp),%rax
movslq -0x168(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x168(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x168(%rbp)
jmp    133e <getshc+0x1fe>
mov    -0x138(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x138(%rbp)
jmp    1265 <getshc+0x125>
jmp    1357 <getshc+0x217>
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
jmp    1249 <getshc+0x109>
mov    -0x160(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getshc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
mov    %rcx,%r14
mov    %rdx,%rbp
mov    %rsi,%rbx
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1274 <getshc+0x134>
mov    %rax,%r15
lea    0x40(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1264 <getshc+0x124>
lea    0xe6e(%rip),%rsi
xor    %r13d,%r13d
lea    0x38(%rsp),%r8
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1040 <fscanf@plt>
cmp    $0x3,%eax
jne    1264 <getshc+0x124>
cmpl   $0x0,(%rbx)
jle    126a <getshc+0x12a>
mov    $0x1,%eax
mov    %rax,0x10(%rsp)
mov    $0x2,%ecx
lea    0x20(%rsp),%r12
xor    %ebp,%ebp
mov    %rbx,0x18(%rsp)
mov    %ecx,%ebx
mov    %ecx,%r13d
jmp    11e7 <getshc+0xa7>
mov    %eax,%ebp
add    $0xffffffff,%ebx
je     123e <getshc+0xfe>
mov    %r15,%rdi
lea    0xe1c(%rip),%rsi
lea    0x34(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x28(%rsp),%r8
mov    %r12,%r9
xor    %eax,%eax
call   1040 <fscanf@plt>
cmp    $0x4,%eax
jne    1264 <getshc+0x124>
movsd  0x28(%rsp),%xmm0
movslq %ebp,%rax
movsd  %xmm0,(%r14,%rax,8)
add    $0x1,%eax
cmpl   $0x0,0xc(%rsp)
je     11e0 <getshc+0xa0>
movsd  0x20(%rsp),%xmm0
cltq
movsd  %xmm0,(%r14,%rax,8)
add    $0x2,%ebp
add    $0xffffffff,%ebx
jne    11e7 <getshc+0xa7>
mov    0x10(%rsp),%rdx
lea    0x1(%rdx),%eax
add    $0x1,%r13d
mov    %r13d,%ecx
xor    %r13d,%r13d
mov    0x18(%rsp),%rbx
cmp    (%rbx),%edx
mov    %rax,0x10(%rsp)
jl     11d9 <getshc+0x99>
jmp    126a <getshc+0x12a>
mov    $0xffffffff,%r13d
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    127a <getshc+0x13a>
mov    $0xffffffff,%r13d
mov    %r13d,%eax
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [11 x i8] c"%d %lg %lg\00"
@.str.2 = [16 x i8] c"%d %d %lg %lg \00"
define i32 @getshc(i8* %0, i32* %1, double* %2, double* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca double*
%9 = alloca double*
%10 = alloca [256 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca i32*
%19 = alloca i32
%20 = alloca i32
store i8* %0, i8** %6
store i32* %1, i32** %7
store double* %2, double** %8
store double* %3, double** %9
store i32 0, i32* %20
%21 = load i8*, i8** %6
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %18
%23 = load i32*, i32** %18
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %26
25: ; preds = %4
store i32 -1, i32* %5
br label %99
26: ; preds = %4
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%28 = load i32*, i32** %18
%29 = call i32* @fgets(i8* %27, i32 256, i32* %28)
%30 = icmp eq i32* %29, null
%31 = zext i1 %30 to i32
store i32 %31, i32* %19
%32 = load i32, i32* %19
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %26
%35 = load i32*, i32** %18
%36 = call i32 @fclose(i32* %35)
store i32 -1, i32* %5
br label %99
37: ; preds = %26
%38 = load i32*, i32** %18
%39 = load i32*, i32** %7
%40 = load double*, double** %8
%41 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %38, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32* %39, double* %40, double* %17)
%42 = icmp ne i32 %41, 3
%43 = zext i1 %42 to i32
store i32 %43, i32* %19
%44 = load i32, i32* %19
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %37
%47 = load i32*, i32** %18
%48 = call i32 @fclose(i32* %47)
store i32 -1, i32* %5
br label %99
49: ; preds = %37
store i32 1, i32* %11
br label %50
50: ; preds = %93, %49
%51 = load i32, i32* %11
%52 = load i32*, i32** %7
%53 = load i32, i32* %52
%54 = icmp sle i32 %51, %53
br i1 %54, label %55, label %96
55: ; preds = %50
store i32 0, i32* %12
br label %56
56: ; preds = %89, %55
%57 = load i32, i32* %12
%58 = load i32, i32* %11
%59 = icmp sle i32 %57, %58
br i1 %59, label %60, label %92
60: ; preds = %56
%61 = load i32*, i32** %18
%62 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %61, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32* %13, i32* %14, double* %15, double* %16)
%63 = icmp ne i32 %62, 4
%64 = zext i1 %63 to i32
store i32 %64, i32* %19
%65 = load i32, i32* %19
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %60
%68 = load i32*, i32** %18
%69 = call i32 @fclose(i32* %68)
store i32 -1, i32* %5
br label %99
70: ; preds = %60
%71 = load double, double* %15
%72 = load double*, double** %9
%73 = load i32, i32* %20
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds double, double* %72, i64 %74
store double %71, double* %75
%76 = load i32, i32* %20
%77 = add nsw i32 %76, 1
store i32 %77, i32* %20
%78 = load i32, i32* %14
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %88
80: ; preds = %70
%81 = load double, double* %16
%82 = load double*, double** %9
%83 = load i32, i32* %20
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds double, double* %82, i64 %84
store double %81, double* %85
%86 = load i32, i32* %20
%87 = add nsw i32 %86, 1
store i32 %87, i32* %20
br label %88
88: ; preds = %80, %70
br label %89
89: ; preds = %88
%90 = load i32, i32* %12
%91 = add nsw i32 %90, 1
store i32 %91, i32* %12
br label %56
92: ; preds = %56
br label %93
93: ; preds = %92
%94 = load i32, i32* %11
%95 = add nsw i32 %94, 1
store i32 %95, i32* %11
br label %50
96: ; preds = %50
%97 = load i32*, i32** %18
%98 = call i32 @fclose(i32* %97)
store i32 0, i32* %5
br label %99
99: ; preds = %96, %67, %46, %34, %25
%100 = load i32, i32* %5
ret i32 %100
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [11 x i8] c"%d %lg %lg\00"
@.str.2 = [16 x i8] c"%d %d %lg %lg \00"
define i32 @getshc(i8* nocapture %0, i32* %1, double* %2, double* nocapture writeonly %3) {
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%12 = bitcast i32* %6 to i8*
%13 = bitcast i32* %7 to i8*
%14 = bitcast double* %8 to i8*
%15 = bitcast double* %9 to i8*
%16 = bitcast double* %10 to i8*
%17 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %61, label %19
19: ; preds = %4
%20 = call i32* @fgets(i8* %11, i32 256, i32* %17)
%21 = icmp eq i32* %20, null
br i1 %21, label %58, label %22
22: ; preds = %19
%23 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %17, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32* %1, double* %2, double* %10)
%24 = icmp eq i32 %23, 3
br i1 %24, label %25, label %58
25: ; preds = %22
%26 = load i32, i32* %1
%27 = icmp slt i32 %26, 1
br i1 %27, label %58, label %28
28: ; preds = %25, %53
%29 = phi i32 [ %57, %53 ], [ 2, %25 ]
%30 = phi i32 [ %50, %53 ], [ 0, %25 ]
%31 = phi i32 [ %54, %53 ], [ 1, %25 ]
br label %32
32: ; preds = %28, %49
%33 = phi i32 [ %30, %28 ], [ %50, %49 ]
%34 = phi i32 [ 0, %28 ], [ %51, %49 ]
%35 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32* %6, i32* %7, double* %8, double* %9)
%36 = icmp eq i32 %35, 4
br i1 %36, label %37, label %58
37: ; preds = %32
%38 = load double, double* %8
%39 = sext i32 %33 to i64
%40 = getelementptr inbounds double, double* %3, i64 %39
store double %38, double* %40
%41 = add nsw i32 %33, 1
%42 = load i32, i32* %7
%43 = icmp eq i32 %42, 0
br i1 %43, label %49, label %44
44: ; preds = %37
%45 = load double, double* %9
%46 = sext i32 %41 to i64
%47 = getelementptr inbounds double, double* %3, i64 %46
store double %45, double* %47
%48 = add nsw i32 %33, 2
br label %49
49: ; preds = %37, %44
%50 = phi i32 [ %48, %44 ], [ %41, %37 ]
%51 = add nuw i32 %34, 1
%52 = icmp eq i32 %51, %29
br i1 %52, label %53, label %32
53: ; preds = %49
%54 = add nuw nsw i32 %31, 1
%55 = load i32, i32* %1
%56 = icmp slt i32 %31, %55
%57 = add nuw i32 %29, 1
br i1 %56, label %28, label %58
58: ; preds = %53, %32, %25, %22, %19
%59 = phi i32 [ -1, %19 ], [ -1, %22 ], [ 0, %25 ], [ -1, %32 ], [ 0, %53 ]
%60 = call i32 @fclose(i32* %17)
br label %61
61: ; preds = %58, %4
%62 = phi i32 [ -1, %4 ], [ %59, %58 ]
ret i32 %62
}