#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 string[512];
  fpr = fopfile(file, "r");
  if (flag) {
    fgets(string, 512, fpr);
    fgets(string, 512, fpr);
    fgets(string, 512, fpr);
    fgets(string, 512, fpr);
    sscanf(string, "%d", &np2);
    if (np2 != np) {
      fprintf(stderr, "No. periods not equal, exiting...\n");
      exit(-1);
    }
    for (i = 0; i < np; i++) {
      fgets(string, 512, fpr);
      sscanf(string, "%f %f %f %f %f %f %f %f", &v[0], &v[1], &v[2], &v[3],
             &v[4], &v[5], &v[6], &v[7]);
      sa[i] = v[sa_field - 1];
    }
  }
  fclose(fpr);
}


x86 assembly (clang, -O0):
<read_specfile>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x288,%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     12f3 <read_specfile+0x193>
lea    -0x270(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x200,%esi
call   1040 <fgets@plt>
lea    -0x270(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x200,%esi
call   1040 <fgets@plt>
lea    -0x270(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x200,%esi
call   1040 <fgets@plt>
lea    -0x270(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x200,%esi
call   1040 <fgets@plt>
lea    -0x270(%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    12ee <read_specfile+0x18e>
lea    -0x270(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x200,%esi
call   1040 <fgets@plt>
lea    -0x270(%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>
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    12f3 <read_specfile+0x193>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x288,%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    $0x248,%rsp
mov    %r9d,%ebp
mov    %r8d,%r15d
mov    %ecx,%r13d
mov    %rdx,%r14
lea    0xe7c(%rip),%rsi
call   1080 <fopfile@plt>
mov    %rax,%rbx
test   %ebp,%ebp
je     1297 <read_specfile+0x137>
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    %rbp,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    %rbp,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    %rbp,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
lea    0xe22(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbp,%rdi
xor    %eax,%eax
call   1060 <sscanf@plt>
cmp    %r13d,0xc(%rsp)
jne    12b1 <read_specfile+0x151>
test   %r13d,%r13d
jle    1297 <read_specfile+0x137>
mov    %r14,%rax
add    $0xffffffff,%r15d
movslq %r15d,%rcx
mov    %rcx,0x38(%rsp)
mov    %r13d,%r14d
lea    0x40(%rsp),%r12
xor    %r13d,%r13d
nopl   (%rax)
mov    %r12,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
mov    %rax,%r15
call   1040 <fgets@plt>
mov    %r12,%rdi
lea    0xdeb(%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
mov    %rbx,%rbp
lea    0x38(%rsp),%rbx
push   %rbx
mov    %rbp,%rbx
call   1060 <sscanf@plt>
mov    %r15,%rax
add    $0x20,%rsp
mov    0x38(%rsp),%rcx
movss  0x10(%rsp,%rcx,4),%xmm0
movss  %xmm0,(%r15,%r13,4)
add    $0x1,%r13
cmp    %r13,%r14
jne    1220 <read_specfile+0xc0>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x248,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
lea    0xd44(%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"
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 [512 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 %76
22: ; preds = %6
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i64 0, i64 0
%24 = load i32*, i32** %13
%25 = call i32 @fgets(i8* %23, i32 512, i32* %24)
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i64 0, i64 0
%27 = load i32*, i32** %13
%28 = call i32 @fgets(i8* %26, i32 512, i32* %27)
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i64 0, i64 0
%30 = load i32*, i32** %13
%31 = call i32 @fgets(i8* %29, i32 512, i32* %30)
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i64 0, i64 0
%33 = load i32*, i32** %13
%34 = call i32 @fgets(i8* %32, i32 512, i32* %33)
%35 = getelementptr inbounds [512 x i8], [512 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 = %72, %44
%46 = load i32, i32* %15
%47 = load i32, i32* %10
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %75
49: ; preds = %45
%50 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i64 0, i64 0
%51 = load i32*, i32** %13
%52 = call i32 @fgets(i8* %50, i32 512, i32* %51)
%53 = getelementptr inbounds [512 x i8], [512 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 = load i32, i32* %11
%64 = sub nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [8 x float], [8 x float]* %14, i64 0, i64 %65
%67 = load float, float* %66
%68 = load float*, float** %9
%69 = load i32, i32* %15
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds float, float* %68, i64 %70
store float %67, float* %71
br label %72
72: ; preds = %49
%73 = load i32, i32* %15
%74 = add nsw i32 %73, 1
store i32 %74, i32* %15
br label %45
75: ; preds = %45
br label %76
76: ; preds = %75, %6
%77 = load i32*, i32** %13
%78 = call i32 @fclose(i32* %77)
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"
define void @read_specfile(i8* %0, float* nocapture readnone %1, float* nocapture writeonly %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca [8 x float]
%8 = alloca i32
%9 = alloca [512 x i8]
%10 = bitcast [8 x float]* %7 to i8*
%11 = bitcast i32* %8 to i8*
%12 = getelementptr inbounds [512 x i8], [512 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 %50, label %15
15: ; preds = %6
%16 = call i32 @fgets(i8* %12, i32 512, i32* %13)
%17 = call i32 @fgets(i8* %12, i32 512, i32* %13)
%18 = call i32 @fgets(i8* %12, i32 512, i32* %13)
%19 = call i32 @fgets(i8* %12, i32 512, i32* %13)
%20 = call i32 (i8*, i8*, ...) @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%21 = load i32, i32* %8
%22 = icmp eq i32 %21, %3
br i1 %22, label %23, label %38
23: ; preds = %15
%24 = icmp sgt i32 %3, 0
br i1 %24, label %25, label %50
25: ; preds = %23
%26 = getelementptr inbounds [8 x float], [8 x float]* %7, i64 0, i64 0
%27 = getelementptr inbounds [8 x float], [8 x float]* %7, i64 0, i64 1
%28 = getelementptr inbounds [8 x float], [8 x float]* %7, i64 0, i64 2
%29 = getelementptr inbounds [8 x float], [8 x float]* %7, i64 0, i64 3
%30 = getelementptr inbounds [8 x float], [8 x float]* %7, i64 0, i64 4
%31 = getelementptr inbounds [8 x float], [8 x float]* %7, i64 0, i64 5
%32 = getelementptr inbounds [8 x float], [8 x float]* %7, i64 0, i64 6
%33 = getelementptr inbounds [8 x float], [8 x float]* %7, i64 0, i64 7
%34 = add nsw i32 %4, -1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [8 x float], [8 x float]* %7, i64 0, i64 %35
%37 = zext i32 %3 to i64
br label %42
38: ; preds = %15
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %25, %42
%43 = phi i64 [ 0, %25 ], [ %48, %42 ]
%44 = call i32 @fgets(i8* %12, i32 512, i32* %13)
%45 = call i32 (i8*, i8*, ...) @sscanf(i8* %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), float* %26, float* %27, float* %28, float* %29, float* %30, float* %31, float* %32, float* %33)
%46 = load float, float* %36
%47 = getelementptr inbounds float, float* %2, i64 %43
store float %46, float* %47
%48 = add nuw nsw i64 %43, 1
%49 = icmp eq i64 %48, %37
br i1 %49, label %50, label %42
50: ; preds = %42, %23, %6
%51 = call i32 @fclose(i32* %13)
ret void
}