#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;
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
char *strtok(char *, char *);
int **load_labels(char *fname, int *D, int *K) {
  FILE *f;
  int **labels;
  int n, m;
  char *line = (char *)malloc(1024 * sizeof(char));
  char *field;
  size_t nbytes;
  n = 0;
  f = fopen(fname, "r");
  while (getline(&line, &nbytes, f) != EOF) {
    m = 0;
    line = strtok(line, "\n");
    field = strtok(line, " ");
    while (field != NULL) {
      field = strtok(NULL, " ");
      m += 1;
    }
    n += 1;
  }
  fclose(f);
  *D = n;
  *K = m;
  labels = (int **)malloc(n * sizeof(int *));
  f = fopen(fname, "r");
  n = 0;
  while (getline(&line, &nbytes, f) != EOF) {
    m = 0;
    labels[n] = (int *)malloc(*K * sizeof(int));
    line = strtok(line, "\n");
    field = strtok(line, " ");
    while (field != NULL) {
      labels[n][m] = atoi(field);
      field = strtok(NULL, " ");
      m += 1;
    }
    n += 1;
  }
  fclose(f);
  return labels;
}


x86 assembly (clang, -O0):
<load_labels>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x400,%edi
call   1040 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdx
lea    -0x38(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1080 <getline@plt>
mov    0x2e33(%rip),%rcx
cmp    (%rcx),%rax
je     1228 <load_labels+0xc8>
movl   $0x0,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe20(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     121a <load_labels+0xba>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe01(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11ed <load_labels+0x8d>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119d <load_labels+0x3d>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x2c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xd9f(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rdx
lea    -0x38(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1080 <getline@plt>
mov    0x2d5f(%rip),%rcx
cmp    (%rcx),%rax
je     133b <load_labels+0x1db>
movl   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x38(%rbp),%rdi
lea    0xd3d(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xd2b(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     132d <load_labels+0x1cd>
mov    -0x40(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
xor    %eax,%eax
mov    %eax,%edi
lea    0xcee(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    12e2 <load_labels+0x182>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1271 <load_labels+0x111>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_labels>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,0x18(%rsp)
mov    %rdi,%rbx
mov    $0x400,%edi
call   1040 <malloc@plt>
mov    %rax,(%rsp)
lea    0xe70(%rip),%rsi
mov    %rbx,0x20(%rsp)
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    %rax,%r13
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   1080 <getline@plt>
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%rax
jne    1230 <load_labels+0xd0>
xor    %ebx,%ebx
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    0x18(%rsp),%rax
mov    %ebx,(%rax)
mov    0x10(%rsp),%rax
mov    %r15d,(%rax)
shl    $0x3,%ebx
mov    %ebx,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
lea    0xe17(%rip),%rsi
mov    0x20(%rsp),%rdi
call   1050 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   1080 <getline@plt>
mov    0x2ddb(%rip),%rcx
cmp    (%rcx),%rax
jne    12b5 <load_labels+0x155>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
lea    0xdcb(%rip),%rbp
mov    %rsp,%r12
lea    0x8(%rsp),%r14
jmp    1271 <load_labels+0x111>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebx
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1080 <getline@plt>
mov    0x2d80(%rip),%rcx
cmp    (%rcx),%rax
je     11be <load_labels+0x5e>
mov    (%rsp),%rdi
lea    0xd86(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,(%rsp)
mov    %rax,%rdi
mov    %rbp,%rsi
call   1060 <strtok@plt>
mov    $0x0,%r15d
test   %rax,%rax
je     1250 <load_labels+0xf0>
xor    %r15d,%r15d
xchg   %ax,%ax
xor    %edi,%edi
mov    %rbp,%rsi
call   1060 <strtok@plt>
add    $0x1,%r15d
test   %rax,%rax
jne    12a0 <load_labels+0x140>
jmp    1250 <load_labels+0xf0>
xor    %r12d,%r12d
lea    0xd45(%rip),%r13
lea    0x8(%rsp),%r15
jmp    12f2 <load_labels+0x192>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r12
mov    %rsp,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1080 <getline@plt>
mov    0x2cff(%rip),%rcx
cmp    (%rcx),%rax
je     1216 <load_labels+0xb6>
mov    0x10(%rsp),%rax
mov    (%rax),%edi
shl    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx,%r12,8)
mov    (%rsp),%rdi
lea    0xcf2(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,(%rsp)
mov    %rax,%rdi
mov    %r13,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     12d0 <load_labels+0x170>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    (%rbx,%r12,8),%rcx
mov    %eax,(%rcx,%rbp,1)
xor    %edi,%edi
mov    %r13,%rsi
call   1060 <strtok@plt>
add    $0x4,%rbp
test   %rax,%rax
jne    1330 <load_labels+0x1d0>
jmp    12d0 <load_labels+0x170>

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

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