#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 */
scalar_t__ EOF;
double atof(char *);
char *calloc(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
scalar_t__ sscanf(char *, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
int load_beta_sparse(double *beta, char *filename, int p) {
  int j = 0, k, K = 0, m;
  FILE *in = NULL;
  char line[1024 * 10];
  char *tmp = NULL;
  if (!(tmp = calloc(10001, sizeof(char)))) {
    fprintf(stderr, "can't calloc %ld bytes\n", (long)10001 * sizeof(char));
    return 0;
  };
  if (!(in = fopen(filename, "rt"))) {
    fprintf(stderr, "can't open file %s\n", filename);
    return 0;
  };
  while (!feof(in)) {
    if (fscanf(in, "%d,", &j) < 0)
      break;
    if (fgets(line, 1024 * 10, in) == NULL) {
      if (!feof(in)) {
        fprintf(stderr, "error in reading FAM file '%s'\n", filename);
        if (tmp) {
          free(tmp);
          tmp = NULL;
        };
        return 0;
      }
      break;
    } else {
      m = 0;
      k = 0;
      while (k < 1024 && sscanf(&line[m], "%[^,\n]", tmp) != EOF) {
        beta[k * p + j] = atof(tmp);
        m += strlen(tmp) + 1;
        k++;
      }
      K = k;
    }
  }
  fclose(in);
  if (tmp) {
    free(tmp);
    tmp = NULL;
  };
  return K;
}


x86 assembly (clang, -O0):
<load_beta_sparse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2850,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x2848(%rbp)
mov    $0x2711,%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,-0x2848(%rbp)
cmp    $0x0,%rax
jne    122f <load_beta_sparse+0x7f>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xde9(%rip),%rsi
mov    $0x2711,%edx
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1432 <load_beta_sparse+0x282>
mov    -0x18(%rbp),%rdi
lea    0xdde(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1274 <load_beta_sparse+0xc4>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1432 <load_beta_sparse+0x282>
jmp    1279 <load_beta_sparse+0xc9>
mov    -0x38(%rbp),%rdi
call   10b0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1297 <load_beta_sparse+0xe7>
jmp    13fe <load_beta_sparse+0x24e>
mov    -0x38(%rbp),%rdi
lea    0xd8d(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <fscanf@plt>
cmp    $0x0,%rax
jge    12ba <load_beta_sparse+0x10a>
jmp    13fe <load_beta_sparse+0x24e>
lea    -0x2840(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x2800,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
jne    133c <load_beta_sparse+0x18c>
mov    -0x38(%rbp),%rdi
call   10b0 <feof@plt>
cmp    $0x0,%eax
jne    1337 <load_beta_sparse+0x187>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd34(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
cmpq   $0x0,-0x2848(%rbp)
je     132b <load_beta_sparse+0x17b>
mov    -0x2848(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x2848(%rbp)
movl   $0x0,-0x4(%rbp)
jmp    1432 <load_beta_sparse+0x282>
jmp    13fe <load_beta_sparse+0x24e>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x24(%rbp)
xor    %eax,%eax
cmpl   $0x400,-0x24(%rbp)
mov    %al,-0x2849(%rbp)
jge    1393 <load_beta_sparse+0x1e3>
movslq -0x2c(%rbp),%rax
lea    -0x2840(%rbp),%rdi
add    %rax,%rdi
mov    -0x2848(%rbp),%rdx
lea    0xcd8(%rip),%rsi
call   10c0 <sscanf@plt>
mov    0x2c61(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
mov    %al,-0x2849(%rbp)
mov    -0x2849(%rbp),%al
test   $0x1,%al
jne    13a6 <load_beta_sparse+0x1f6>
jmp    13f3 <load_beta_sparse+0x243>
mov    -0x2848(%rbp),%rdi
call   1040 <atof@plt>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2848(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
add    $0x1,%rcx
movslq -0x2c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    134a <load_beta_sparse+0x19a>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1279 <load_beta_sparse+0xc9>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x2848(%rbp)
je     142c <load_beta_sparse+0x27c>
mov    -0x2848(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x2848(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_beta_sparse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2828,%rsp
mov    %edx,%r15d
mov    %rsi,%rbp
mov    %rdi,%r12
movl   $0x0,0xc(%rsp)
mov    $0x2711,%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
test   %rax,%rax
je     1225 <load_beta_sparse+0x75>
mov    %rax,%rbx
lea    0xe28(%rip),%rsi
mov    %rbp,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     123e <load_beta_sparse+0x8e>
mov    %rax,%r14
mov    %rbp,0x18(%rsp)
mov    %rax,%rdi
call   10b0 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     126e <load_beta_sparse+0xbe>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    125a <load_beta_sparse+0xaa>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
xor    %ebp,%ebp
mov    $0x2711,%edx
jmp    1253 <load_beta_sparse+0xa3>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
mov    %rbp,%rdx
xor    %ebp,%ebp
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %ebp,%eax
add    $0x2828,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
mov    %r14,0x10(%rsp)
jmp    1291 <load_beta_sparse+0xe1>
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp),%r14
mov    %r14,%rdi
call   10b0 <feof@plt>
test   %eax,%eax
jne    1213 <load_beta_sparse+0x63>
mov    %r14,%rdi
lea    0xd94(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1070 <fscanf@plt>
test   %rax,%rax
js     1213 <load_beta_sparse+0x63>
lea    0x20(%rsp),%rdi
mov    $0x2800,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1334 <load_beta_sparse+0x184>
xor    %r13d,%r13d
xor    %eax,%eax
xor    %ebp,%ebp
nopl   0x0(%rax)
movslq %eax,%r14
lea    (%rsp,%r14,1),%rdi
add    $0x20,%rdi
lea    0xd71(%rip),%rsi
mov    %rbx,%rdx
call   10c0 <sscanf@plt>
mov    0x2cf7(%rip),%rcx
cmp    (%rcx),%rax
je     1280 <load_beta_sparse+0xd0>
mov    %rbx,%rdi
call   1040 <atof@plt>
mov    0xc(%rsp),%eax
add    %r13d,%eax
cltq
movsd  %xmm0,(%r12,%rax,8)
mov    %rbx,%rdi
call   1060 <strlen@plt>
add    %r14,%rax
add    $0x1,%rax
add    $0x1,%ebp
add    %r15d,%r13d
cmp    $0x400,%ebp
jne    12d0 <load_beta_sparse+0x120>
mov    $0x400,%ebp
jmp    1280 <load_beta_sparse+0xd0>
mov    %r14,%rdi
call   10b0 <feof@plt>
test   %eax,%eax
jne    1213 <load_beta_sparse+0x63>
mov    0x2c8d(%rip),%rax
mov    (%rax),%edi
lea    0xcdf(%rip),%rsi
xor    %ebp,%ebp
mov    0x18(%rsp),%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    121b <load_beta_sparse+0x6b>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"can't calloc %ld bytes\0A\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [20 x i8] c"can't open file %s\0A\00"
@.str.3 = [4 x i8] c"%d,\00"
@.str.4 = [32 x i8] c"error in reading FAM file '%s'\0A\00"
@.str.5 = [7 x i8] c"%[^,\0A]\00"
@EOF = global i64 0
define i32 @load_beta_sparse(double* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca [10240 x i8]
%14 = alloca i8*
store double* %0, double** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
store i32 0, i32* %10
store i32* null, i32** %12
store i8* null, i8** %14
%15 = call i8* @calloc(i32 10001, i32 1)
store i8* %15, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %20, label %17
17: ; preds = %3
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 10001)
store i32 0, i32* %4
br label %106
20: ; preds = %3
%21 = load i8*, i8** %6
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %12
%23 = icmp ne i32* %22, null
br i1 %23, label %28, label %24
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %6
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %26)
store i32 0, i32* %4
br label %106
28: ; preds = %20
br label %29
29: ; preds = %95, %28
%30 = load i32*, i32** %12
%31 = call i32 @feof(i32* %30)
%32 = icmp ne i32 %31, 0
%33 = xor i1 %32, true
br i1 %33, label %34, label %96
34: ; preds = %29
%35 = load i32*, i32** %12
%36 = call i64 @fscanf(i32* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %8)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
br label %96
39: ; preds = %34
%40 = getelementptr inbounds [10240 x i8], [10240 x i8]* %13, i64 0, i64 0
%41 = load i32*, i32** %12
%42 = call i32* @fgets(i8* %40, i32 10240, i32* %41)
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %59
44: ; preds = %39
%45 = load i32*, i32** %12
%46 = call i32 @feof(i32* %45)
%47 = icmp ne i32 %46, 0
br i1 %47, label %58, label %48
48: ; preds = %44
%49 = load i32, i32* @stderr
%50 = load i8*, i8** %6
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %50)
%52 = load i8*, i8** %14
%53 = icmp ne i8* %52, null
br i1 %53, label %54, label %57
54: ; preds = %48
%55 = load i8*, i8** %14
%56 = call i32 @free(i8* %55)
store i8* null, i8** %14
br label %57
57: ; preds = %54, %48
store i32 0, i32* %4
br label %106
58: ; preds = %44
br label %96
59: ; preds = %39
store i32 0, i32* %11
store i32 0, i32* %9
br label %60
60: ; preds = %73, %59
%61 = load i32, i32* %9
%62 = icmp slt i32 %61, 1024
br i1 %62, label %63, label %71
63: ; preds = %60
%64 = load i32, i32* %11
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [10240 x i8], [10240 x i8]* %13, i64 0, i64 %65
%67 = load i8*, i8** %14
%68 = call i64 @sscanf(i8* %66, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %67)
%69 = load i64, i64* @EOF
%70 = icmp ne i64 %68, %69
br label %71
71: ; preds = %63, %60
%72 = phi i1 [ false, %60 ], [ %70, %63 ]
br i1 %72, label %73, label %93
73: ; preds = %71
%74 = load i8*, i8** %14
%75 = call double @atof(i8* %74)
%76 = load double*, double** %5
%77 = load i32, i32* %9
%78 = load i32, i32* %7
%79 = mul nsw i32 %77, %78
%80 = load i32, i32* %8
%81 = add nsw i32 %79, %80
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds double, double* %76, i64 %82
store double %75, double* %83
%84 = load i8*, i8** %14
%85 = call i64 @strlen(i8* %84)
%86 = add nsw i64 %85, 1
%87 = load i32, i32* %11
%88 = sext i32 %87 to i64
%89 = add nsw i64 %88, %86
%90 = trunc i64 %89 to i32
store i32 %90, i32* %11
%91 = load i32, i32* %9
%92 = add nsw i32 %91, 1
store i32 %92, i32* %9
br label %60
93: ; preds = %71
%94 = load i32, i32* %9
store i32 %94, i32* %10
br label %95
95: ; preds = %93
br label %29
96: ; preds = %58, %38, %29
%97 = load i32*, i32** %12
%98 = call i32 @fclose(i32* %97)
%99 = load i8*, i8** %14
%100 = icmp ne i8* %99, null
br i1 %100, label %101, label %104
101: ; preds = %96
%102 = load i8*, i8** %14
%103 = call i32 @free(i8* %102)
store i8* null, i8** %14
br label %104
104: ; preds = %101, %96
%105 = load i32, i32* %10
store i32 %105, i32* %4
br label %106
106: ; preds = %104, %57, %24, %17
%107 = load i32, i32* %4
ret i32 %107
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"can't calloc %ld bytes\0A\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [20 x i8] c"can't open file %s\0A\00"
@.str.3 = [4 x i8] c"%d,\00"
@.str.4 = [32 x i8] c"error in reading FAM file '%s'\0A\00"
@.str.5 = [7 x i8] c"%[^,\0A]\00"
@EOF = global i64 0
define i32 @load_beta_sparse(double* nocapture writeonly %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca [10240 x i8]
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = getelementptr inbounds [10240 x i8], [10240 x i8]* %5, i64 0, i64 0
%8 = tail call dereferenceable_or_null(10001) i8* @calloc(i32 10001, i32 1)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 10001)
br label %65
13: ; preds = %3
%14 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = call i32 @feof(i32* %14)
%18 = icmp eq i32 %17, 0
br i1 %18, label %22, label %61
19: ; preds = %13
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %65
22: ; preds = %16, %57
%23 = phi i32 [ %58, %57 ], [ 0, %16 ]
%24 = call i64 @fscanf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%25 = icmp slt i64 %24, 0
br i1 %25, label %61, label %26
26: ; preds = %22
%27 = call i32* @fgets(i8* %7, i32 10240, i32* %14)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = call i32 @feof(i32* %14)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %61
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %1)
%35 = call i32 @free(i8* %8)
br label %65
36: ; preds = %26, %45
%37 = phi i64 [ %54, %45 ], [ 0, %26 ]
%38 = phi i32 [ %55, %45 ], [ 0, %26 ]
%39 = shl i64 %37, 32
%40 = ashr exact i64 %39, 32
%41 = getelementptr inbounds [10240 x i8], [10240 x i8]* %5, i64 0, i64 %40
%42 = call i64 @sscanf(i8* %41, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%43 = load i64, i64* @EOF
%44 = icmp eq i64 %42, %43
br i1 %44, label %57, label %45
45: ; preds = %36
%46 = call double @atof(i8* %8)
%47 = mul nsw i32 %38, %2
%48 = load i32, i32* %4
%49 = add nsw i32 %48, %47
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %0, i64 %50
store double %46, double* %51
%52 = call i64 @strlen(i8* %8)
%53 = add nsw i64 %40, 1
%54 = add i64 %53, %52
%55 = add nuw nsw i32 %38, 1
%56 = icmp eq i32 %55, 1024
br i1 %56, label %57, label %36
57: ; preds = %45, %36
%58 = phi i32 [ 1024, %45 ], [ %38, %36 ]
%59 = call i32 @feof(i32* %14)
%60 = icmp eq i32 %59, 0
br i1 %60, label %22, label %61
61: ; preds = %57, %22, %16, %29
%62 = phi i32 [ %23, %29 ], [ 0, %16 ], [ %58, %57 ], [ %23, %22 ]
%63 = call i32 @fclose(i32* %14)
%64 = call i32 @free(i8* %8)
br label %65
65: ; preds = %61, %32, %19, %10
%66 = phi i32 [ %62, %61 ], [ 0, %32 ], [ 0, %19 ], [ 0, %10 ]
ret i32 %66
}