#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] = 500000;
  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;
      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   $0x7a120,(%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     1370 <loadStrings+0x1e0>
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     1350 <loadStrings+0x1c0>
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
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    0xd21(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1339 <loadStrings+0x1a9>
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    0xcd7(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x40(%rbp)
jmp    12ea <loadStrings+0x15a>
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    1379 <loadStrings+0x1e9>
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   $0x7a120,0x0(%rbp)
mov    $0x3d0900,%edi
call   1070 <malloc@plt>
mov    %rax,%r13
test   %rbx,%rbx
je     1337 <loadStrings+0x1a7>
mov    $0x3e8,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0x3e8,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     130e <loadStrings+0x17e>
mov    %rbp,(%rsp)
xor    %r15d,%r15d
lea    0xdf9(%rip),%rbp
mov    %rbx,0x8(%rsp)
jmp    123a <loadStrings+0xaa>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x1,%r15
mov    %r12,%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    %r12,%rbx
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   10a0 <strtok@plt>
mov    $0x0,%r12d
test   %rax,%rax
je     1283 <loadStrings+0xf3>
xor    %r12d,%r12d
xchg   %ax,%ax
add    $0x1,%r12d
xor    %edi,%edi
mov    %rbp,%rsi
call   10a0 <strtok@plt>
test   %rax,%rax
jne    1270 <loadStrings+0xe0>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rax
mov    %r12d,(%rax,%r15,4)
shl    $0x2,%r12d
mov    %r12d,%edi
call   1070 <malloc@plt>
mov    %rax,0x0(%r13,%r15,8)
mov    $0x3e8,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%r12
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
cs nopw 0x0(%rax,%rax,1)
mov    %rax,%rdi
call   10b0 <atoi@plt>
mov    0x0(%r13,%r15,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    %r15d,%r15d
mov    %r15d,0x0(%rbp)
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r12,%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 500000, 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 %114
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 = %101, %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 %106
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 = load i32*, i32** %5
%59 = load i32, i32* %12
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32, i32* %58, i64 %60
store i32 %57, i32* %61
%62 = load i32*, i32** %5
%63 = load i32, i32* %12
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i32, i32* %62, i64 %64
%66 = load i32, i32* %65
%67 = sext i32 %66 to i64
%68 = mul i64 %67, 4
%69 = trunc i64 %68 to i32
%70 = call i64 @malloc(i32 %69)
%71 = inttoptr i64 %70 to i32*
%72 = load i32**, i32*** %7
%73 = load i32, i32* %12
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i32*, i32** %72, i64 %74
store i32* %71, i32** %75
%76 = call i64 @malloc(i32 1000)
%77 = inttoptr i64 %76 to i8*
store i8* %77, i8** %9
%78 = load i8*, i8** %9
%79 = load i8*, i8** %10
%80 = call i32 @strcpy(i8* %78, i8* %79)
store i32 0, i32* %14
%81 = load i8*, i8** %9
%82 = call i8* @strtok(i8* %81, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %82, i8** %11
br label %83
83: ; preds = %86, %54
%84 = load i8*, i8** %11
%85 = icmp ne i8* %84, null
br i1 %85, label %86, label %101
86: ; preds = %83
%87 = load i8*, i8** %11
%88 = call i32 @atoi(i8* %87)
store i32 %88, i32* %15
%89 = load i32, i32* %15
%90 = load i32**, i32*** %7
%91 = load i32, i32* %12
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i32*, i32** %90, i64 %92
%94 = load i32*, i32** %93
%95 = load i32, i32* %14
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i32, i32* %94, i64 %96
store i32 %89, i32* %97
%98 = load i32, i32* %14
%99 = add nsw i32 %98, 1
store i32 %99, i32* %14
%100 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %100, i8** %11
br label %83
101: ; preds = %83
%102 = load i8*, i8** %9
%103 = call i32 @free(i8* %102)
%104 = load i32, i32* %12
%105 = add nsw i32 %104, 1
store i32 %105, i32* %12
br label %34
106: ; preds = %34
%107 = load i32, i32* %12
%108 = load i32*, i32** %6
%109 = getelementptr inbounds i32, i32* %108, i64 0
store i32 %107, i32* %109
%110 = load i32*, i32** %16
%111 = call i32 @fclose(i32* %110)
%112 = load i8*, i8** %10
%113 = call i32 @free(i8* %112)
br label %117
114: ; preds = %3
%115 = load i8*, i8** %4
%116 = call i32 @perror(i8* %115)
br label %117
117: ; preds = %114, %106
%118 = load i32**, i32*** %7
ret i32** %118
}

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 500000, i32* %2
%5 = tail call i64 @malloc(i32 4000000)
%6 = inttoptr i64 %5 to i32**
%7 = icmp eq i32* %4, null
br i1 %7, label %58, 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 %54, label %13
13: ; preds = %8, %47
%14 = phi i64 [ %49, %47 ], [ 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 = getelementptr inbounds i32, i32* %1, i64 %14
store i32 %26, i32* %28
%29 = shl i32 %26, 2
%30 = tail call i64 @malloc(i32 %29)
%31 = inttoptr i64 %30 to i32*
%32 = getelementptr inbounds i32*, i32** %6, i64 %14
store i32* %31, i32** %32
%33 = tail call i64 @malloc(i32 1000)
%34 = inttoptr i64 %33 to i8*
%35 = tail call i32 @strcpy(i8* %34, i8* %10)
%36 = tail call i8* @strtok(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp eq i8* %36, null
br i1 %37, label %47, label %38
38: ; preds = %25, %38
%39 = phi i64 [ %44, %38 ], [ 0, %25 ]
%40 = phi i8* [ %45, %38 ], [ %36, %25 ]
%41 = tail call i32 @atoi(i8* %40)
%42 = load i32*, i32** %32
%43 = getelementptr inbounds i32, i32* %42, i64 %39
store i32 %41, i32* %43
%44 = add nuw i64 %39, 1
%45 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %38
47: ; preds = %38, %25
%48 = tail call i32 @free(i8* %34)
%49 = add nuw i64 %14, 1
%50 = tail call i64 @fgets(i8* %10, i32 1000, i32* %4)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %13
52: ; preds = %47
%53 = trunc i64 %49 to i32
br label %54
54: ; preds = %52, %8
%55 = phi i32 [ 0, %8 ], [ %53, %52 ]
store i32 %55, i32* %2
%56 = tail call i32 @fclose(i32* %4)
%57 = tail call i32 @free(i8* %10)
br label %60
58: ; preds = %3
%59 = tail call i32 @perror(i8* %0)
br label %60
60: ; preds = %58, %54
ret i32** %6
}