#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 atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
int **loadStrings(char *filename, int *len, int *nStr) {
  int **S;
  char *str, *linetemp, *line, *next_elem;
  int i, j, c;
  int elem;
  FILE *inpfile;
  inpfile = fopen(filename, "r");
  nStr[0] = 10000;
  S = (int **)malloc(nStr[0] * sizeof(int *));
  if (inpfile) {
    line = (char *)malloc(1000 * sizeof(char));
    i = 0;
    while (fgets(line, 1000, inpfile)) {
      c = 0;
      linetemp = (char *)malloc(1000 * sizeof(char));
      strcpy(linetemp, line);
      next_elem = strtok(linetemp, " ");
      while (next_elem != NULL) {
        c++;
        next_elem = strtok(NULL, " ");
      }
      free(linetemp);
      len[i] = c - 2;
      S[i] = (int *)malloc(len[i] * sizeof(int));
      linetemp = (char *)malloc(1000 * sizeof(char));
      strcpy(linetemp, line);
      c = 0;
      next_elem = strtok(linetemp, " ");
      while (next_elem != NULL) {
        elem = atoi(next_elem);
        S[i][c] = elem;
        c++;
        next_elem = strtok(NULL, " ");
      }
      free(linetemp);
      i++;
    }
    nStr[0] = i;
    fclose(inpfile);
    free(line);
  } else {
    perror(filename);
  }
  return S;
}


x86 assembly (clang, -O0):
<loadStrings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x2710,(%rax)
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     1373 <loadStrings+0x1e3>
mov    $0x3e8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    $0x3e8,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1353 <loadStrings+0x1c3>
movl   $0x0,-0x4c(%rbp)
mov    $0x3e8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xdc1(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1277 <loadStrings+0xe7>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd99(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x40(%rbp)
jmp    124a <loadStrings+0xba>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4c(%rbp),%edx
sub    $0x2,%edx
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
movslq (%rax,%rcx,4),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    $0x3e8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x4c(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xd1e(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     133c <loadStrings+0x1ac>
mov    -0x40(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x4c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xcd4(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x40(%rbp)
jmp    12ed <loadStrings+0x15d>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11f8 <loadStrings+0x68>
mov    -0x44(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x58(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    137c <loadStrings+0x1ec>
mov    -0x8(%rbp),%rdi
call   1090 <perror@plt>
mov    -0x20(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadStrings>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbp
mov    %rsi,0x10(%rsp)
mov    %rdi,%r14
lea    0xe50(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
movl   $0x2710,0x0(%rbp)
mov    $0x13880,%edi
call   1070 <malloc@plt>
mov    %rax,%r13
test   %rbx,%rbx
je     1337 <loadStrings+0x1a7>
mov    $0x3e8,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x3e8,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     130e <loadStrings+0x17e>
mov    %rbp,(%rsp)
xor    %r12d,%r12d
lea    0xdf9(%rip),%rbp
mov    %rbx,0x8(%rsp)
jmp    123a <loadStrings+0xaa>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x1,%r12
mov    %r15,%rdi
mov    $0x3e8,%esi
mov    0x8(%rsp),%rbx
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1308 <loadStrings+0x178>
mov    $0x3e8,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15,%rbx
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   10a0 <strtok@plt>
mov    $0x0,%r15d
test   %rax,%rax
je     1283 <loadStrings+0xf3>
xor    %r15d,%r15d
xchg   %ax,%ax
add    $0x1,%r15d
xor    %edi,%edi
mov    %rbp,%rsi
call   10a0 <strtok@plt>
test   %rax,%rax
jne    1270 <loadStrings+0xe0>
mov    %r14,%rdi
call   1030 <free@plt>
lea    -0x2(%r15),%eax
mov    0x10(%rsp),%rcx
mov    %eax,(%rcx,%r12,4)
lea    -0x8(,%r15,4),%edi
ff
call   1070 <malloc@plt>
mov    %rax,0x0(%r13,%r12,8)
mov    $0x3e8,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%r15
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   10a0 <strtok@plt>
test   %rax,%rax
je     1210 <loadStrings+0x80>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
call   10b0 <atoi@plt>
mov    0x0(%r13,%r12,8),%rcx
mov    %eax,(%rcx,%rbx,1)
xor    %edi,%edi
mov    %rbp,%rsi
call   10a0 <strtok@plt>
add    $0x4,%rbx
test   %rax,%rax
jne    12e0 <loadStrings+0x150>
jmp    1210 <loadStrings+0x80>
mov    (%rsp),%rbp
jmp    1311 <loadStrings+0x181>
xor    %r12d,%r12d
mov    %r12d,0x0(%rbp)
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r13,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1090 <perror@plt>
jmp    1325 <loadStrings+0x195>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c" \00"
define i32** @loadStrings(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%17 = load i8*, i8** %4
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %16
%19 = load i32*, i32** %6
%20 = getelementptr inbounds i32, i32* %19, i64 0
store i32 10000, i32* %20
%21 = load i32*, i32** %6
%22 = getelementptr inbounds i32, i32* %21, i64 0
%23 = load i32, i32* %22
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 8
%26 = trunc i64 %25 to i32
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i32**
store i32** %28, i32*** %7
%29 = load i32*, i32** %16
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %115
31: ; preds = %3
%32 = call i64 @malloc(i32 1000)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %10
store i32 0, i32* %12
br label %34
34: ; preds = %102, %31
%35 = load i8*, i8** %10
%36 = load i32*, i32** %16
%37 = call i64 @fgets(i8* %35, i32 1000, i32* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %107
39: ; preds = %34
store i32 0, i32* %14
%40 = call i64 @malloc(i32 1000)
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** %9
%42 = load i8*, i8** %9
%43 = load i8*, i8** %10
%44 = call i32 @strcpy(i8* %42, i8* %43)
%45 = load i8*, i8** %9
%46 = call i8* @strtok(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %46, i8** %11
br label %47
47: ; preds = %50, %39
%48 = load i8*, i8** %11
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %54
50: ; preds = %47
%51 = load i32, i32* %14
%52 = add nsw i32 %51, 1
store i32 %52, i32* %14
%53 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %53, i8** %11
br label %47
54: ; preds = %47
%55 = load i8*, i8** %9
%56 = call i32 @free(i8* %55)
%57 = load i32, i32* %14
%58 = sub nsw i32 %57, 2
%59 = load i32*, i32** %5
%60 = load i32, i32* %12
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %59, i64 %61
store i32 %58, i32* %62
%63 = load i32*, i32** %5
%64 = load i32, i32* %12
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %63, i64 %65
%67 = load i32, i32* %66
%68 = sext i32 %67 to i64
%69 = mul i64 %68, 4
%70 = trunc i64 %69 to i32
%71 = call i64 @malloc(i32 %70)
%72 = inttoptr i64 %71 to i32*
%73 = load i32**, i32*** %7
%74 = load i32, i32* %12
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i32*, i32** %73, i64 %75
store i32* %72, i32** %76
%77 = call i64 @malloc(i32 1000)
%78 = inttoptr i64 %77 to i8*
store i8* %78, i8** %9
%79 = load i8*, i8** %9
%80 = load i8*, i8** %10
%81 = call i32 @strcpy(i8* %79, i8* %80)
store i32 0, i32* %14
%82 = load i8*, i8** %9
%83 = call i8* @strtok(i8* %82, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %83, i8** %11
br label %84
84: ; preds = %87, %54
%85 = load i8*, i8** %11
%86 = icmp ne i8* %85, null
br i1 %86, label %87, label %102
87: ; preds = %84
%88 = load i8*, i8** %11
%89 = call i32 @atoi(i8* %88)
store i32 %89, i32* %15
%90 = load i32, i32* %15
%91 = load i32**, i32*** %7
%92 = load i32, i32* %12
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i32*, i32** %91, i64 %93
%95 = load i32*, i32** %94
%96 = load i32, i32* %14
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i32, i32* %95, i64 %97
store i32 %90, i32* %98
%99 = load i32, i32* %14
%100 = add nsw i32 %99, 1
store i32 %100, i32* %14
%101 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %101, i8** %11
br label %84
102: ; preds = %84
%103 = load i8*, i8** %9
%104 = call i32 @free(i8* %103)
%105 = load i32, i32* %12
%106 = add nsw i32 %105, 1
store i32 %106, i32* %12
br label %34
107: ; preds = %34
%108 = load i32, i32* %12
%109 = load i32*, i32** %6
%110 = getelementptr inbounds i32, i32* %109, i64 0
store i32 %108, i32* %110
%111 = load i32*, i32** %16
%112 = call i32 @fclose(i32* %111)
%113 = load i8*, i8** %10
%114 = call i32 @free(i8* %113)
br label %118
115: ; preds = %3
%116 = load i8*, i8** %4
%117 = call i32 @perror(i8* %116)
br label %118
118: ; preds = %115, %107
%119 = load i32**, i32*** %7
ret i32** %119
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c" \00"
define i32** @loadStrings(i8* nocapture %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 10000, i32* %2
%5 = tail call i64 @malloc(i32 80000)
%6 = inttoptr i64 %5 to i32**
%7 = icmp eq i32* %4, null
br i1 %7, label %59, label %8
8: ; preds = %3
%9 = tail call i64 @malloc(i32 1000)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i64 @fgets(i8* %10, i32 1000, i32* %4)
%12 = icmp eq i64 %11, 0
br i1 %12, label %55, label %13
13: ; preds = %8, %48
%14 = phi i64 [ %50, %48 ], [ 0, %8 ]
%15 = tail call i64 @malloc(i32 1000)
%16 = inttoptr i64 %15 to i8*
%17 = tail call i32 @strcpy(i8* %16, i8* %10)
%18 = tail call i8* @strtok(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %25, label %20
20: ; preds = %13, %20
%21 = phi i32 [ %22, %20 ], [ 0, %13 ]
%22 = add nuw nsw i32 %21, 1
%23 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %20
25: ; preds = %20, %13
%26 = phi i32 [ 0, %13 ], [ %22, %20 ]
%27 = tail call i32 @free(i8* %16)
%28 = add nsw i32 %26, -2
%29 = getelementptr inbounds i32, i32* %1, i64 %14
store i32 %28, i32* %29
%30 = shl i32 %28, 2
%31 = tail call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to i32*
%33 = getelementptr inbounds i32*, i32** %6, i64 %14
store i32* %32, i32** %33
%34 = tail call i64 @malloc(i32 1000)
%35 = inttoptr i64 %34 to i8*
%36 = tail call i32 @strcpy(i8* %35, i8* %10)
%37 = tail call i8* @strtok(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp eq i8* %37, null
br i1 %38, label %48, label %39
39: ; preds = %25, %39
%40 = phi i64 [ %45, %39 ], [ 0, %25 ]
%41 = phi i8* [ %46, %39 ], [ %37, %25 ]
%42 = tail call i32 @atoi(i8* %41)
%43 = load i32*, i32** %33
%44 = getelementptr inbounds i32, i32* %43, i64 %40
store i32 %42, i32* %44
%45 = add nuw i64 %40, 1
%46 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %39
48: ; preds = %39, %25
%49 = tail call i32 @free(i8* %35)
%50 = add nuw i64 %14, 1
%51 = tail call i64 @fgets(i8* %10, i32 1000, i32* %4)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %13
53: ; preds = %48
%54 = trunc i64 %50 to i32
br label %55
55: ; preds = %53, %8
%56 = phi i32 [ 0, %8 ], [ %54, %53 ]
store i32 %56, i32* %2
%57 = tail call i32 @fclose(i32* %4)
%58 = tail call i32 @free(i8* %10)
br label %61
59: ; preds = %3
%60 = tail call i32 @perror(i8* %0)
br label %61
61: ; preds = %59, %55
ret i32** %6
}