#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopfile(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ sscanf(char *, char *, ...);
int /*<<< orphan*/ stderr;
void read_specfile(char *file, float *per, float *sa, int np, int sa_field,
                   int flag) {
  FILE *fpr;
  float v[8];
  int i, np2;
  char str[1024];
  fpr = fopfile(file, "r");
  if (flag) {
    fgets(str, 1024, fpr);
    fgets(str, 1024, fpr);
    fgets(str, 1024, fpr);
    fgets(str, 1024, fpr);
    sscanf(str, "%d", &np2);
    if (np2 != np) {
      fprintf(stderr, "No. periods not equal, exiting...\n");
      exit(-1);
    }
    for (i = 0; i < np; i++) {
      fgets(str, 1024, fpr);
      sscanf(str, "%f %f %f %f %f %f %f %f", &v[0], &v[1], &v[2], &v[3], &v[4],
             &v[5], &v[6], &v[7]);
      per[i] = v[1];
      sa[i] = v[sa_field - 1];
    }
  } else {
    for (i = 0; i < np; i++) {
      fgets(str, 1024, fpr);
      sscanf(str, "%f %f", &per[i], &sa[i]);
    }
  }
  fclose(fpr);
}


x86 assembly (clang, -O0):
<read_specfile>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x488,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1080 <fopfile@plt>
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1305 <read_specfile+0x1a5>
lea    -0x470(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
lea    -0x470(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
lea    -0x470(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
lea    -0x470(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
lea    -0x470(%rbp),%rdi
lea    0xdff(%rip),%rsi
lea    -0x68(%rbp),%rdx
mov    $0x0,%al
call   1060 <sscanf@plt>
mov    -0x68(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     1239 <read_specfile+0xd9>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    0xddb(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1300 <read_specfile+0x1a0>
lea    -0x470(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
lea    -0x470(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    -0x60(%rbp),%rcx
add    $0x4,%rcx
lea    -0x60(%rbp),%r8
add    $0x8,%r8
lea    -0x60(%rbp),%r9
add    $0xc,%r9
lea    -0x60(%rbp),%rbx
add    $0x10,%rbx
lea    -0x60(%rbp),%r11
add    $0x14,%r11
lea    -0x60(%rbp),%r10
add    $0x18,%r10
lea    -0x60(%rbp),%rax
add    $0x1c,%rax
lea    0xd7d(%rip),%rsi
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
mov    $0x0,%al
call   1060 <sscanf@plt>
movss  -0x5c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x64(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
cltq
movss  -0x60(%rbp,%rax,4),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x64(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1240 <read_specfile+0xe0>
jmp    1373 <read_specfile+0x213>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    136e <read_specfile+0x20e>
lea    -0x470(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
lea    -0x470(%rbp),%rdi
mov    -0x18(%rbp),%rdx
movslq -0x64(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
mov    -0x20(%rbp),%rcx
movslq -0x64(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rcx
lea    0xce1(%rip),%rsi
mov    $0x0,%al
call   1060 <sscanf@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    130c <read_specfile+0x1ac>
jmp    1373 <read_specfile+0x213>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x488,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_specfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x448,%rsp
mov    %r9d,%ebp
mov    %r8d,%r15d
mov    %ecx,%r13d
mov    %rdx,%r14
mov    %rsi,%rbx
lea    0xe79(%rip),%rsi
call   1080 <fopfile@plt>
test   %ebp,%ebp
mov    %rax,%r12
je     12ad <read_specfile+0x14d>
mov    %r15d,(%rsp)
lea    0x40(%rsp),%r15
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rax,%rbp
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rbp,%rdx
call   1040 <fgets@plt>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rbp,%rdx
call   1040 <fgets@plt>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rbp,%rdx
call   1040 <fgets@plt>
lea    0xe18(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <sscanf@plt>
cmp    %r13d,0xc(%rsp)
jne    131e <read_specfile+0x1be>
test   %r13d,%r13d
mov    %r12,%rax
mov    (%rsp),%ecx
jle    1304 <read_specfile+0x1a4>
add    $0xffffffff,%ecx
movslq %ecx,%rax
mov    %rax,(%rsp)
mov    %r13d,%eax
mov    %rax,0x38(%rsp)
lea    0x40(%rsp),%r13
xor    %r15d,%r15d
nopl   (%rax)
mov    %r13,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1040 <fgets@plt>
mov    %r13,%rdi
lea    0xdde(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x14(%rsp),%rcx
lea    0x18(%rsp),%r8
lea    0x1c(%rsp),%r9
xor    %eax,%eax
lea    0x2c(%rsp),%rbp
push   %rbp
lea    0x30(%rsp),%rbp
push   %rbp
lea    0x34(%rsp),%rbp
push   %rbp
lea    0x38(%rsp),%rbp
push   %rbp
call   1060 <sscanf@plt>
mov    %r12,%rax
add    $0x20,%rsp
movss  0x14(%rsp),%xmm0
movss  %xmm0,(%rbx,%r15,4)
mov    (%rsp),%rcx
movss  0x10(%rsp,%rcx,4),%xmm0
movss  %xmm0,(%r14,%r15,4)
add    $0x1,%r15
cmp    %r15,0x38(%rsp)
jne    1230 <read_specfile+0xd0>
jmp    1304 <read_specfile+0x1a4>
test   %r13d,%r13d
jle    1304 <read_specfile+0x1a4>
mov    %r13d,%ebp
lea    0x40(%rsp),%r13
lea    0xd79(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1040 <fgets@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1060 <sscanf@plt>
mov    %r12,%rax
add    $0x4,%r14
add    $0x4,%rbx
add    $0xffffffffffffffff,%rbp
jne    12d0 <read_specfile+0x170>
mov    %rax,%rdi
call   1030 <fclose@plt>
add    $0x448,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
lea    0xcd7(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [35 x i8] c"No. periods not equal, exiting...\0A\00"
@.str.3 = [24 x i8] c"%f %f %f %f %f %f %f %f\00"
@.str.4 = [6 x i8] c"%f %f\00"
define void @read_specfile(i8* %0, float* %1, float* %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca [8 x float]
%8 = alloca i32
%9 = alloca [1024 x i8]
%10 = bitcast [8 x float]* %7 to i8*
%11 = bitcast i32* %8 to i8*
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%13 = tail call i32* @fopfile(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32 %5, 0
br i1 %14, label %15, label %19
15: ; preds = %6
%16 = icmp sgt i32 %3, 0
br i1 %16, label %17, label %64
17: ; preds = %15
%18 = zext i32 %3 to i64
br label %56
19: ; preds = %6
%20 = call i32 @fgets(i8* %12, i32 1024, i32* %13)
%21 = call i32 @fgets(i8* %12, i32 1024, i32* %13)
%22 = call i32 @fgets(i8* %12, i32 1024, i32* %13)
%23 = call i32 @fgets(i8* %12, i32 1024, i32* %13)
%24 = call i32 (i8*, i8*, ...) @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%25 = load i32, i32* %8
%26 = icmp eq i32 %25, %3
br i1 %26, label %27, label %42
27: ; preds = %19
%28 = icmp sgt i32 %3, 0
br i1 %28, label %29, label %64
29: ; preds = %27
%30 = getelementptr inbounds [8 x float], [8 x float]* %7, i64 0, i64 0
%31 = getelementptr inbounds [8 x float], [8 x float]* %7, i64 0, i64 1
%32 = getelementptr inbounds [8 x float], [8 x float]* %7, i64 0, i64 2
%33 = getelementptr inbounds [8 x float], [8 x float]* %7, i64 0, i64 3
%34 = getelementptr inbounds [8 x float], [8 x float]* %7, i64 0, i64 4
%35 = getelementptr inbounds [8 x float], [8 x float]* %7, i64 0, i64 5
%36 = getelementptr inbounds [8 x float], [8 x float]* %7, i64 0, i64 6
%37 = getelementptr inbounds [8 x float], [8 x float]* %7, i64 0, i64 7
%38 = add nsw i32 %4, -1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [8 x float], [8 x float]* %7, i64 0, i64 %39
%41 = zext i32 %3 to i64
br label %46
42: ; preds = %19
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%45 = call i32 @exit(i32 -1)
unreachable
46: ; preds = %29, %46
%47 = phi i64 [ 0, %29 ], [ %54, %46 ]
%48 = call i32 @fgets(i8* %12, i32 1024, i32* %13)
%49 = call i32 (i8*, i8*, ...) @sscanf(i8* %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), float* %30, float* %31, float* %32, float* %33, float* %34, float* %35, float* %36, float* %37)
%50 = load float, float* %31
%51 = getelementptr inbounds float, float* %1, i64 %47
store float %50, float* %51
%52 = load float, float* %40
%53 = getelementptr inbounds float, float* %2, i64 %47
store float %52, float* %53
%54 = add nuw nsw i64 %47, 1
%55 = icmp eq i64 %54, %41
br i1 %55, label %64, label %46
56: ; preds = %17, %56
%57 = phi i64 [ 0, %17 ], [ %62, %56 ]
%58 = call i32 @fgets(i8* %12, i32 1024, i32* %13)
%59 = getelementptr inbounds float, float* %1, i64 %57
%60 = getelementptr inbounds float, float* %2, i64 %57
%61 = call i32 (i8*, i8*, ...) @sscanf(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), float* %59, float* %60)
%62 = add nuw nsw i64 %57, 1
%63 = icmp eq i64 %62, %18
br i1 %63, label %64, label %56
64: ; preds = %46, %56, %27, %15
%65 = call i32 @fclose(i32* %13)
ret void
}