#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 sscanf(char *, char *, float *, float *, float *, float *);
int /*<<< orphan*/ stderr;
scalar_t__ strncmp(char *, char *, int);
void read_bbpfile_3comp(char *file, float *per, float *sa1, float *sa2,
                        float *sa3, int np) {
  FILE *fpr;
  int i, nr;
  char str[1024];
  fpr = fopfile(file, "r");
  fgets(str, 1024, fpr);
  while (strncmp(str, "#", 1) == 0)
    fgets(str, 1024, fpr);
  for (i = 0; i < np; i++) {
    nr = sscanf(str, "%f %f %f %f", &per[i], &sa1[i], &sa2[i], &sa3[i]);
    if (nr < 3) {
      fprintf(stderr, "Error in file= %s\n", file);
      fprintf(stderr, "found %d columns, expecting at least 4, exiting...\n",
              nr);
      exit(-1);
    }
    if (i < np - 1)
      fgets(str, 1024, fpr);
  }
  fclose(fpr);
}


x86 assembly (clang, -O0):
<read_bbpfile_3comp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1090 <fopfile@plt>
mov    %rax,-0x38(%rbp)
lea    -0x440(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
lea    -0x440(%rbp),%rdi
lea    0xe38(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11f8 <read_bbpfile_3comp+0x88>
lea    -0x440(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
jmp    11bc <read_bbpfile_3comp+0x4c>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    12df <read_bbpfile_3comp+0x16f>
lea    -0x440(%rbp),%rdi
mov    -0x10(%rbp),%rdx
movslq -0x3c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
mov    -0x18(%rbp),%rcx
movslq -0x3c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rcx
mov    -0x20(%rbp),%r8
movslq -0x3c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%r8
mov    -0x28(%rbp),%r9
movslq -0x3c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%r9
lea    0xdaf(%rip),%rsi
call   1070 <sscanf@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x3,-0x40(%rbp)
jge    12a6 <read_bbpfile_3comp+0x136>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd95(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%edx
lea    0xd8e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x3c(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12cc <read_bbpfile_3comp+0x15c>
lea    -0x440(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
jmp    12d1 <read_bbpfile_3comp+0x161>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11ff <read_bbpfile_3comp+0x8f>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_bbpfile_3comp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %r9,(%rsp)
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
lea    0xe68(%rip),%rsi
mov    %rdi,0x10(%rsp)
call   1090 <fopfile@plt>
mov    %rax,%r14
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
lea    0xe41(%rip),%rsi
mov    %rbp,%rdi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1209 <read_bbpfile_3comp+0x99>
lea    0x20(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
mov    %rbp,%rdi
lea    0xe08(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11e0 <read_bbpfile_3comp+0x70>
mov    %r14,0x8(%rsp)
mov    (%rsp),%rax
test   %eax,%eax
jle    1289 <read_bbpfile_3comp+0x119>
lea    -0x1(%rax),%ecx
mov    %rcx,0x18(%rsp)
mov    %eax,%eax
mov    %rax,(%rsp)
xor    %r14d,%r14d
jmp    124a <read_bbpfile_3comp+0xda>
nopl   0x0(%rax)
add    $0x1,%r14
add    $0x4,%r15
add    $0x4,%r12
add    $0x4,%r13
add    $0x4,%rbx
cmp    %r14,(%rsp)
je     1289 <read_bbpfile_3comp+0x119>
lea    0x20(%rsp),%rdi
lea    0xdae(%rip),%rsi
mov    %rbx,%rdx
mov    %r13,%rcx
mov    %r12,%r8
mov    %r15,%r9
call   1070 <sscanf@plt>
cmp    $0x2,%eax
jle    12a5 <read_bbpfile_3comp+0x135>
cmp    0x18(%rsp),%r14
jae    1230 <read_bbpfile_3comp+0xc0>
lea    0x20(%rsp),%rdi
mov    $0x400,%esi
mov    0x8(%rsp),%rdx
call   1050 <fgets@plt>
jmp    1230 <read_bbpfile_3comp+0xc0>
mov    0x8(%rsp),%rdi
call   1040 <fclose@plt>
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
mov    0x2d32(%rip),%rbx
mov    (%rbx),%edi
lea    0xd59(%rip),%rsi
mov    0x10(%rsp),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd57(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"#\00"
@.str.2 = [12 x i8] c"%f %f %f %f\00"
@stderr = global i32 0
@.str.3 = [19 x i8] c"Error in file= %s\0A\00"
@.str.4 = [52 x i8] c"found %d columns, expecting at least 4, exiting...\0A\00"
define void @read_bbpfile_3comp(i8* %0, float* %1, float* %2, float* %3, float* %4, i32 %5) {
%7 = alloca i8*
%8 = alloca float*
%9 = alloca float*
%10 = alloca float*
%11 = alloca float*
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca [1024 x i8]
store i8* %0, i8** %7
store float* %1, float** %8
store float* %2, float** %9
store float* %3, float** %10
store float* %4, float** %11
store i32 %5, i32* %12
%17 = load i8*, i8** %7
%18 = call i32* @fopfile(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %13
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%20 = load i32*, i32** %13
%21 = call i32 @fgets(i8* %19, i32 1024, i32* %20)
br label %22
22: ; preds = %26, %6
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%24 = call i64 @strncmp(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%28 = load i32*, i32** %13
%29 = call i32 @fgets(i8* %27, i32 1024, i32* %28)
br label %22
30: ; preds = %22
store i32 0, i32* %14
br label %31
31: ; preds = %74, %30
%32 = load i32, i32* %14
%33 = load i32, i32* %12
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %77
35: ; preds = %31
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%37 = load float*, float** %8
%38 = load i32, i32* %14
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds float, float* %37, i64 %39
%41 = load float*, float** %9
%42 = load i32, i32* %14
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds float, float* %41, i64 %43
%45 = load float*, float** %10
%46 = load i32, i32* %14
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds float, float* %45, i64 %47
%49 = load float*, float** %11
%50 = load i32, i32* %14
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds float, float* %49, i64 %51
%53 = call i32 @sscanf(i8* %36, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), float* %40, float* %44, float* %48, float* %52)
store i32 %53, i32* %15
%54 = load i32, i32* %15
%55 = icmp slt i32 %54, 3
br i1 %55, label %56, label %64
56: ; preds = %35
%57 = load i32, i32* @stderr
%58 = load i8*, i8** %7
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %58)
%60 = load i32, i32* @stderr
%61 = load i32, i32* %15
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %61)
%63 = call i32 @exit(i32 -1)
unreachable
64: ; preds = %35
%65 = load i32, i32* %14
%66 = load i32, i32* %12
%67 = sub nsw i32 %66, 1
%68 = icmp slt i32 %65, %67
br i1 %68, label %69, label %73
69: ; preds = %64
%70 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%71 = load i32*, i32** %13
%72 = call i32 @fgets(i8* %70, i32 1024, i32* %71)
br label %73
73: ; preds = %69, %64
br label %74
74: ; preds = %73
%75 = load i32, i32* %14
%76 = add nsw i32 %75, 1
store i32 %76, i32* %14
br label %31
77: ; preds = %31
%78 = load i32*, i32** %13
%79 = call i32 @fclose(i32* %78)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"#\00"
@.str.2 = [12 x i8] c"%f %f %f %f\00"
@stderr = global i32 0
@.str.3 = [19 x i8] c"Error in file= %s\0A\00"
@.str.4 = [52 x i8] c"found %d columns, expecting at least 4, exiting...\0A\00"
define void @read_bbpfile_3comp(i8* %0, float* %1, float* %2, float* %3, float* %4, i32 %5) {
%7 = alloca [1024 x i8]
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%9 = tail call i32* @fopfile(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @fgets(i8* %8, i32 1024, i32* %9)
%11 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %19, %6
%14 = icmp sgt i32 %5, 0
br i1 %14, label %15, label %44
15: ; preds = %13
%16 = add nsw i32 %5, -1
%17 = zext i32 %16 to i64
%18 = zext i32 %5 to i64
br label %23
19: ; preds = %6, %19
%20 = call i32 @fgets(i8* %8, i32 1024, i32* %9)
%21 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%22 = icmp eq i64 %21, 0
br i1 %22, label %19, label %13
23: ; preds = %15, %41
%24 = phi i64 [ 0, %15 ], [ %42, %41 ]
%25 = getelementptr inbounds float, float* %1, i64 %24
%26 = getelementptr inbounds float, float* %2, i64 %24
%27 = getelementptr inbounds float, float* %3, i64 %24
%28 = getelementptr inbounds float, float* %4, i64 %24
%29 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), float* %25, float* %26, float* %27, float* %28)
%30 = icmp slt i32 %29, 3
br i1 %30, label %31, label %37
31: ; preds = %23
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%36 = call i32 @exit(i32 -1)
unreachable
37: ; preds = %23
%38 = icmp ult i64 %24, %17
br i1 %38, label %39, label %41
39: ; preds = %37
%40 = call i32 @fgets(i8* %8, i32 1024, i32* %9)
br label %41
41: ; preds = %37, %39
%42 = add nuw nsw i64 %24, 1
%43 = icmp eq i64 %42, %18
br i1 %43, label %44, label %23
44: ; preds = %41, %13
%45 = call i32 @fclose(i32* %9)
ret void
}