#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 ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int VerifyFileFormat(char const *, int *, int *);
double atof(char *);
long atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
scalar_t__ malloc(long);
int /*<<< orphan*/ strcmp(char *, char *);
char *strtok_r(char *, char *, char **);
int ReadLibSVM(const char *filename, double **X, double **y, int *d, int *n) {
  if (VerifyFileFormat(filename, d, n) == -1) {
    return -1;
  }
  long ln = (long)(*n);
  long ld = (long)(*d);
  FILE *fp = NULL;
  fp = fopen(filename, "r");
  (*X) = (double *)malloc(ln * ld * sizeof(double));
  (*y) = (double *)malloc(ln * sizeof(double));
  long i = 0;
  long numi = 0;
  double numf = 0.0;
  char *line = NULL, *str = NULL, *saveptr = NULL, *subtoken = NULL;
  ssize_t read = 0;
  size_t len = 0;
  while ((read = getline(&line, &len, fp)) != -1) {
    long cnt = 0;
    for (str = line;; str = NULL) {
      subtoken = strtok_r(str, ": ", &saveptr);
      if (subtoken == NULL || !strcmp(subtoken, "\n")) {
        break;
      } else {
        cnt++;
      }
      if (cnt == 1) {
        (*y)[i] = atof(subtoken);
      } else if (cnt % 2 == 0) {
        numi = atoi(subtoken);
      } else {
        numf = atof(subtoken);
        (*X)[i + ln * (numi - 1)] = numf;
      }
    }
    i++;
  }
  if (line) {
    free(line);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<ReadLibSVM>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   10c0 <VerifyFileFormat@plt>
cmp    $0xffffffff,%eax
jne    11e5 <ReadLibSVM+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    13fb <ReadLibSVM+0x25b>
mov    -0x30(%rbp),%rax
movslq (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
movslq (%rax),%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
imul   -0x40(%rbp),%rdi
shl    $0x3,%rdi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rdi
shl    $0x3,%rdi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
movq   $0x0,-0x70(%rbp)
movq   $0x0,-0x78(%rbp)
movq   $0x0,-0x80(%rbp)
movl   $0x0,-0x84(%rbp)
movq   $0x0,-0x90(%rbp)
mov    -0x48(%rbp),%rdx
lea    -0x68(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   10b0 <getline@plt>
mov    %eax,-0x84(%rbp)
cmp    $0xffffffff,%eax
je     13d7 <ReadLibSVM+0x237>
movq   $0x0,-0x98(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rdi
lea    0xd2a(%rip),%rsi
lea    -0x78(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
je     1309 <ReadLibSVM+0x169>
mov    -0x80(%rbp),%rdi
lea    0xd0a(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    130e <ReadLibSVM+0x16e>
jmp    13c6 <ReadLibSVM+0x226>
mov    -0x98(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x98(%rbp)
cmpq   $0x1,-0x98(%rbp)
01
jne    134c <ReadLibSVM+0x1ac>
mov    -0x80(%rbp),%rdi
call   1040 <atof@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x50(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    13b4 <ReadLibSVM+0x214>
mov    -0x98(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    1379 <ReadLibSVM+0x1d9>
mov    -0x80(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %rax,-0x58(%rbp)
jmp    13af <ReadLibSVM+0x20f>
mov    -0x80(%rbp),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x50(%rbp),%rcx
mov    -0x38(%rbp),%rdx
mov    -0x58(%rbp),%rsi
sub    $0x1,%rsi
imul   %rsi,%rdx
add    %rdx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    13b4 <ReadLibSVM+0x214>
jmp    13b9 <ReadLibSVM+0x219>
movq   $0x0,-0x70(%rbp)
jmp    12cd <ReadLibSVM+0x12d>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    1297 <ReadLibSVM+0xf7>
cmpq   $0x0,-0x68(%rbp)
je     13eb <ReadLibSVM+0x24b>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadLibSVM>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8,%r14
mov    %rcx,%rbp
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    %rcx,%rsi
mov    %r8,%rdx
call   10c0 <VerifyFileFormat@plt>
cmp    $0xffffffff,%eax
je     1363 <ReadLibSVM+0x1c3>
movslq (%r14),%r13
movslq 0x0(%rbp),%rbp
lea    0xe21(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
mov    %rax,%r14
mov    %r13,0x28(%rsp)
lea    0x0(,%r13,8),%rbx
imul   %rbx,%rbp
mov    %rbp,%rdi
call   1080 <malloc@plt>
mov    %r12,0x30(%rsp)
mov    %rax,(%r12)
mov    %rbx,%rdi
call   1080 <malloc@plt>
mov    %r15,0x38(%rsp)
mov    %rax,(%r15)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x40(%rsp)
movq   $0x0,0x20(%rsp)
lea    0x8(%rsp),%rdi
lea    0x20(%rsp),%rsi
mov    %r14,0x10(%rsp)
mov    %r14,%rdx
call   10b0 <getline@plt>
cmp    $0xffffffff,%eax
je     1346 <ReadLibSVM+0x1a6>
xor    %eax,%eax
mov    %rax,0x18(%rsp)
lea    0xd9d(%rip),%r13
lea    0x40(%rsp),%rbx
lea    0xd94(%rip),%r15
xor    %r12d,%r12d
jmp    12a1 <ReadLibSVM+0x101>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r12
lea    0x8(%rsp),%rdi
lea    0x20(%rsp),%rsi
mov    0x10(%rsp),%rdx
call   10b0 <getline@plt>
cmp    $0xffffffff,%eax
je     1346 <ReadLibSVM+0x1a6>
mov    0x8(%rsp),%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1060 <strtok_r@plt>
test   %rax,%rax
je     1280 <ReadLibSVM+0xe0>
mov    %rax,%r14
mov    $0x1,%ebp
jmp    12ec <ReadLibSVM+0x14c>
call   1040 <atof@plt>
mov    0x38(%rsp),%rax
mov    (%rax),%rax
movsd  %xmm0,(%rax,%r12,8)
xor    %edi,%edi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1060 <strtok_r@plt>
mov    %rax,%r14
add    $0x1,%rbp
test   %rax,%rax
je     1280 <ReadLibSVM+0xe0>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1280 <ReadLibSVM+0xe0>
mov    %r14,%rdi
cmp    $0x1,%rbp
je     12c0 <ReadLibSVM+0x120>
test   $0x1,%bpl
jne    1320 <ReadLibSVM+0x180>
call   10a0 <atoi@plt>
mov    %rax,0x18(%rsp)
jmp    12d3 <ReadLibSVM+0x133>
cs nopw 0x0(%rax,%rax,1)
call   1040 <atof@plt>
mov    0x30(%rsp),%rax
mov    (%rax),%rax
mov    0x18(%rsp),%rcx
add    $0xffffffffffffffff,%rcx
imul   0x28(%rsp),%rcx
add    %r12,%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    12d3 <ReadLibSVM+0x133>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1355 <ReadLibSVM+0x1b5>
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    1368 <ReadLibSVM+0x1c8>
mov    $0xffffffff,%eax
add    $0x48,%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 = [3 x i8] c": \00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @ReadLibSVM(i8* %0, double** %1, double** %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca double**
%9 = alloca double**
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i64
%13 = alloca i64
%14 = alloca i32*
%15 = alloca i64
%16 = alloca i64
%17 = alloca double
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i8*
%21 = alloca i8*
%22 = alloca i32
%23 = alloca i64
%24 = alloca i64
store i8* %0, i8** %7
store double** %1, double*** %8
store double** %2, double*** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
%25 = load i8*, i8** %7
%26 = load i32*, i32** %10
%27 = load i32*, i32** %11
%28 = call i32 @VerifyFileFormat(i8* %25, i32* %26, i32* %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %31
30: ; preds = %5
store i32 -1, i32* %6
br label %116
31: ; preds = %5
%32 = load i32*, i32** %11
%33 = load i32, i32* %32
%34 = sext i32 %33 to i64
store i64 %34, i64* %12
%35 = load i32*, i32** %10
%36 = load i32, i32* %35
%37 = sext i32 %36 to i64
store i64 %37, i64* %13
store i32* null, i32** %14
%38 = load i8*, i8** %7
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %39, i32** %14
%40 = load i64, i64* %12
%41 = load i64, i64* %13
%42 = mul nsw i64 %40, %41
%43 = mul i64 %42, 8
%44 = call i64 @malloc(i64 %43)
%45 = inttoptr i64 %44 to double*
%46 = load double**, double*** %8
store double* %45, double** %46
%47 = load i64, i64* %12
%48 = mul i64 %47, 8
%49 = call i64 @malloc(i64 %48)
%50 = inttoptr i64 %49 to double*
%51 = load double**, double*** %9
store double* %50, double** %51
store i64 0, i64* %15
store i64 0, i64* %16
store double 0.000000e+00, double* %17
store i8* null, i8** %18
store i8* null, i8** %19
store i8* null, i8** %20
store i8* null, i8** %21
store i32 0, i32* %22
store i64 0, i64* %23
br label %52
52: ; preds = %104, %31
%53 = load i32*, i32** %14
%54 = call i32 @getline(i8** %18, i64* %23, i32* %53)
store i32 %54, i32* %22
%55 = icmp ne i32 %54, -1
br i1 %55, label %56, label %107
56: ; preds = %52
store i64 0, i64* %24
%57 = load i8*, i8** %18
store i8* %57, i8** %19
br label %58
58: ; preds = %103, %56
%59 = load i8*, i8** %19
%60 = call i8* @strtok_r(i8* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %20)
store i8* %60, i8** %21
%61 = load i8*, i8** %21
%62 = icmp eq i8* %61, null
br i1 %62, label %67, label %63
63: ; preds = %58
%64 = load i8*, i8** %21
%65 = call i32 @strcmp(i8* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%66 = icmp ne i32 %65, 0
br i1 %66, label %68, label %67
67: ; preds = %63, %58
br label %104
68: ; preds = %63
%69 = load i64, i64* %24
%70 = add nsw i64 %69, 1
store i64 %70, i64* %24
br label %71
71: ; preds = %68
%72 = load i64, i64* %24
%73 = icmp eq i64 %72, 1
br i1 %73, label %74, label %81
74: ; preds = %71
%75 = load i8*, i8** %21
%76 = call double @atof(i8* %75)
%77 = load double**, double*** %9
%78 = load double*, double** %77
%79 = load i64, i64* %15
%80 = getelementptr inbounds double, double* %78, i64 %79
store double %76, double* %80
br label %102
81: ; preds = %71
%82 = load i64, i64* %24
%83 = srem i64 %82, 2
%84 = icmp eq i64 %83, 0
br i1 %84, label %85, label %88
85: ; preds = %81
%86 = load i8*, i8** %21
%87 = call i64 @atoi(i8* %86)
store i64 %87, i64* %16
br label %101
88: ; preds = %81
%89 = load i8*, i8** %21
%90 = call double @atof(i8* %89)
store double %90, double* %17
%91 = load double, double* %17
%92 = load double**, double*** %8
%93 = load double*, double** %92
%94 = load i64, i64* %15
%95 = load i64, i64* %12
%96 = load i64, i64* %16
%97 = sub nsw i64 %96, 1
%98 = mul nsw i64 %95, %97
%99 = add nsw i64 %94, %98
%100 = getelementptr inbounds double, double* %93, i64 %99
store double %91, double* %100
br label %101
101: ; preds = %88, %85
br label %102
102: ; preds = %101, %74
br label %103
103: ; preds = %102
store i8* null, i8** %19
br label %58
104: ; preds = %67
%105 = load i64, i64* %15
%106 = add nsw i64 %105, 1
store i64 %106, i64* %15
br label %52
107: ; preds = %52
%108 = load i8*, i8** %18
%109 = icmp ne i8* %108, null
br i1 %109, label %110, label %113
110: ; preds = %107
%111 = load i8*, i8** %18
%112 = call i32 @free(i8* %111)
br label %113
113: ; preds = %110, %107
%114 = load i32*, i32** %14
%115 = call i32 @fclose(i32* %114)
store i32 0, i32* %6
br label %116
116: ; preds = %113, %30
%117 = load i32, i32* %6
ret i32 %117
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c": \00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @ReadLibSVM(i8* %0, double** nocapture %1, double** nocapture %2, i32* %3, i32* %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = tail call i32 @VerifyFileFormat(i8* %0, i32* %3, i32* %4)
%10 = icmp eq i32 %9, -1
br i1 %10, label %75, label %11
11: ; preds = %5
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = shl nsw i64 %13, 3
%18 = mul i64 %17, %15
%19 = tail call i64 @malloc(i64 %18)
%20 = inttoptr i64 %19 to double*
store double* %20, double** %1
%21 = tail call i64 @malloc(i64 %17)
%22 = inttoptr i64 %21 to double*
store double* %22, double** %2
%23 = bitcast i8** %6 to i8*
store i8* null, i8** %6
%24 = bitcast i8** %7 to i8*
store i8* null, i8** %7
%25 = bitcast i64* %8 to i8*
store i64 0, i64* %8
%26 = call i32 @getline(i8** %6, i64* %8, i32* %16)
%27 = icmp eq i32 %26, -1
br i1 %27, label %68, label %28
28: ; preds = %11, %63
%29 = phi i64 [ %64, %63 ], [ 0, %11 ]
%30 = phi i64 [ %65, %63 ], [ 0, %11 ]
%31 = load i8*, i8** %6
%32 = call i8* @strtok_r(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %7)
%33 = icmp eq i8* %32, null
br i1 %33, label %63, label %34
34: ; preds = %28, %59
%35 = phi i8* [ %61, %59 ], [ %32, %28 ]
%36 = phi i64 [ %41, %59 ], [ 0, %28 ]
%37 = phi i64 [ %60, %59 ], [ %29, %28 ]
%38 = call i32 @strcmp(i8* %35, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%39 = icmp eq i32 %38, 0
br i1 %39, label %63, label %40
40: ; preds = %34
%41 = add nuw nsw i64 %36, 1
%42 = icmp eq i64 %36, 0
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = call double @atof(i8* %35)
%45 = load double*, double** %2
%46 = getelementptr inbounds double, double* %45, i64 %30
store double %44, double* %46
br label %59
47: ; preds = %40
%48 = and i64 %41, 1
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = call i64 @atoi(i8* %35)
br label %59
52: ; preds = %47
%53 = call double @atof(i8* %35)
%54 = load double*, double** %1
%55 = add nsw i64 %37, -1
%56 = mul nsw i64 %55, %13
%57 = add nsw i64 %56, %30
%58 = getelementptr inbounds double, double* %54, i64 %57
store double %53, double* %58
br label %59
59: ; preds = %43, %52, %50
%60 = phi i64 [ %37, %43 ], [ %51, %50 ], [ %37, %52 ]
%61 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %7)
%62 = icmp eq i8* %61, null
br i1 %62, label %63, label %34
63: ; preds = %34, %59, %28
%64 = phi i64 [ %29, %28 ], [ %60, %59 ], [ %37, %34 ]
%65 = add nuw nsw i64 %30, 1
%66 = call i32 @getline(i8** %6, i64* %8, i32* %16)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %28
68: ; preds = %63, %11
%69 = load i8*, i8** %6
%70 = icmp eq i8* %69, null
br i1 %70, label %73, label %71
71: ; preds = %68
%72 = call i32 @free(i8* %69)
br label %73
73: ; preds = %71, %68
%74 = call i32 @fclose(i32* %16)
br label %75
75: ; preds = %5, %73
%76 = phi i32 [ 0, %73 ], [ -1, %5 ]
ret i32 %76
}