#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 */
double atof(int /*<<< orphan*/);
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ strsep(char **, char *);
int setRowWithSparseVectorDouble(double *mat, int row_i, int row_length,
                                 const char *fileName) {
  FILE *fp;
  char *line = NULL;
  char *ptr;
  size_t len = 0;
  ssize_t read;
  fp = fopen(fileName, "r");
  if (fp == NULL)
    return -1;
  int i;
  double val;
  while ((read = getline(&line, &len, fp)) != -1) {
    ptr = line;
    i = atoi(strsep(&line, ";"));
    val = atof(strsep(&line, ";"));
    line = ptr;
    mat[i + row_i * row_length] = val;
  }
  free(line);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<setRowWithSparseVectorDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe5f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c1 <setRowWithSparseVectorDouble+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    1264 <setRowWithSparseVectorDouble+0xf4>
jmp    11c6 <setRowWithSparseVectorDouble+0x56>
mov    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1090 <getline@plt>
mov    %eax,-0x44(%rbp)
cmp    $0xffffffff,%eax
je     124b <setRowWithSparseVectorDouble+0xdb>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe0c(%rip),%rsi
call   1060 <strsep@plt>
mov    %eax,%edi
call   1080 <atoi@plt>
mov    %eax,-0x48(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   1060 <strsep@plt>
mov    %eax,%edi
call   1040 <atof@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
movsd  -0x50(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x48(%rbp),%ecx
mov    -0x14(%rbp),%edx
imul   -0x18(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    11c6 <setRowWithSparseVectorDouble+0x56>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setRowWithSparseVectorDouble>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%rbp
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe62(%rip),%rsi
mov    %rcx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1244 <setRowWithSparseVectorDouble+0xd4>
mov    %rax,%r15
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     122f <setRowWithSparseVectorDouble+0xbf>
imul   %r14d,%ebx
mov    %rbp,0x10(%rsp)
mov    (%rsp),%rbp
mov    %rsp,%r14
mov    %r14,%rdi
lea    0xe21(%rip),%r12
mov    %r12,%rsi
call   1060 <strsep@plt>
mov    %eax,%edi
call   1080 <atoi@plt>
mov    %eax,%r13d
mov    %r14,%rdi
mov    %r12,%rsi
call   1060 <strsep@plt>
mov    %eax,%edi
call   1040 <atof@plt>
mov    %rbp,(%rsp)
mov    0x10(%rsp),%rbp
add    %ebx,%r13d
movslq %r13d,%rax
movsd  %xmm0,0x0(%rbp,%rax,8)
mov    %r14,%rdi
lea    0x8(%rsp),%rsi
mov    %r15,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
jne    11d0 <setRowWithSparseVectorDouble+0x60>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    1249 <setRowWithSparseVectorDouble+0xd9>
mov    $0xffffffff,%eax
add    $0x18,%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 = [2 x i8] c";\00"
define i32 @setRowWithSparseVectorDouble(double* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
%15 = alloca i32
%16 = alloca double
store double* %0, double** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i8* null, i8** %11
store i64 0, i64* %13
%17 = load i8*, i8** %9
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %10
%19 = load i32*, i32** %10
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %4
store i32 -1, i32* %5
br label %48
22: ; preds = %4
br label %23
23: ; preds = %27, %22
%24 = load i32*, i32** %10
%25 = call i32 @getline(i8** %11, i64* %13, i32* %24)
store i32 %25, i32* %14
%26 = icmp ne i32 %25, -1
br i1 %26, label %27, label %43
27: ; preds = %23
%28 = load i8*, i8** %11
store i8* %28, i8** %12
%29 = call i32 @strsep(i8** %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @atoi(i32 %29)
store i32 %30, i32* %15
%31 = call i32 @strsep(i8** %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%32 = call double @atof(i32 %31)
store double %32, double* %16
%33 = load i8*, i8** %12
store i8* %33, i8** %11
%34 = load double, double* %16
%35 = load double*, double** %6
%36 = load i32, i32* %15
%37 = load i32, i32* %7
%38 = load i32, i32* %8
%39 = mul nsw i32 %37, %38
%40 = add nsw i32 %36, %39
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %35, i64 %41
store double %34, double* %42
br label %23
43: ; preds = %23
%44 = load i8*, i8** %11
%45 = call i32 @free(i8* %44)
%46 = load i32*, i32** %10
%47 = call i32 @fclose(i32* %46)
store i32 0, i32* %5
br label %48
48: ; preds = %43, %21
%49 = load i32, i32* %5
ret i32 %49
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c";\00"
define i32 @setRowWithSparseVectorDouble(double* nocapture writeonly %0, i32 %1, i32 %2, i8* nocapture %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%8 = bitcast i64* %6 to i8*
store i64 0, i64* %6
%9 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %31, label %11
11: ; preds = %4
%12 = call i32 @getline(i8** %5, i64* %6, i32* %9)
%13 = icmp eq i32 %12, -1
br i1 %13, label %27, label %14
14: ; preds = %11
%15 = mul nsw i32 %2, %1
br label %16
16: ; preds = %14, %16
%17 = load i8*, i8** %5
%18 = call i32 @strsep(i8** %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @atoi(i32 %18)
%20 = call i32 @strsep(i8** %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = call double @atof(i32 %20)
store i8* %17, i8** %5
%22 = add nsw i32 %19, %15
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %0, i64 %23
store double %21, double* %24
%25 = call i32 @getline(i8** %5, i64* %6, i32* %9)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %16
27: ; preds = %16, %11
%28 = load i8*, i8** %5
%29 = call i32 @free(i8* %28)
%30 = call i32 @fclose(i32* %9)
br label %31
31: ; preds = %4, %27
%32 = phi i32 [ 0, %27 ], [ -1, %4 ]
ret i32 %32
}