#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 */

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
int **load_labels_s(char *input, int *D, int *K) {
  int **labels;
  int n, m;
  char *buffer = (char *)malloc(1024 * sizeof(char));
  char *line = (char *)malloc(1024 * sizeof(char));
  char *field;
  size_t nbytes;
  n = 0;
  strcpy(buffer, input);
  line = strtok(buffer, "\n");
  do {
    m = 0;
    field = strtok(line, " ");
    while (field != NULL) {
      field = strtok(NULL, " ");
      m += 1;
    }
    n += 1;
  } while ((line = strtok(NULL, "\n")) != NULL);
  *D = n;
  *K = m;
  labels = (int **)malloc(n * sizeof(int *));
  n = 0;
  strcpy(buffer, input);
  line = strtok(buffer, "\n");
  do {
    m = 0;
    labels[n] = (int *)malloc(*K * sizeof(int));
    field = strtok(line, " ");
    while (field != NULL) {
      labels[n][m] = atoi(field);
      field = strtok(NULL, " ");
      m += 1;
    }
    n += 1;
  } while ((line = strtok(NULL, "\n")) != NULL);
  free(buffer);
  free(line);
  return labels;
}


x86 assembly (clang, -O0):
<load_labels_s>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     11f0 <load_labels_s+0xa0>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe29(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11c3 <load_labels_s+0x73>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdfc(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11a8 <load_labels_s+0x58>
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movslq -0x24(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xda5(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x38(%rbp),%rdi
lea    0xd6b(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12eb <load_labels_s+0x19b>
mov    -0x40(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd2e(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12a0 <load_labels_s+0x150>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd01(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1264 <load_labels_s+0x114>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_labels_s>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,0x10(%rsp)
mov    %rdi,%r12
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
lea    0xe6e(%rip),%r14
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strtok@plt>
xor    %ebx,%ebx
lea    0xe57(%rip),%r13
jmp    11c2 <load_labels_s+0x72>
nopl   (%rax)
add    $0x1,%ebx
xor    %edi,%edi
mov    %r14,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     11f4 <load_labels_s+0xa4>
mov    %rax,%rdi
mov    %r13,%rsi
call   1060 <strtok@plt>
mov    $0x0,%ebp
test   %rax,%rax
je     11b0 <load_labels_s+0x60>
xor    %ebp,%ebp
nopl   0x0(%rax)
xor    %edi,%edi
mov    %r13,%rsi
call   1060 <strtok@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    11e0 <load_labels_s+0x90>
jmp    11b0 <load_labels_s+0x60>
mov    0x10(%rsp),%rax
mov    %ebx,(%rax)
mov    %ebp,(%r15)
shl    $0x3,%ebx
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
lea    0xdde(%rip),%r12
mov    %rbp,%rdi
mov    %r12,%rsi
call   1060 <strtok@plt>
mov    %rax,%rbp
xor    %r14d,%r14d
lea    0xdc8(%rip),%r13
jmp    1256 <load_labels_s+0x106>
nopl   0x0(%rax)
add    $0x1,%r14
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <strtok@plt>
mov    %rax,%rbp
test   %rax,%rax
je     12a4 <load_labels_s+0x154>
mov    (%r15),%edi
shl    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,(%rbx,%r14,8)
mov    %rbp,%rdi
mov    %r13,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     1240 <load_labels_s+0xf0>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    (%rbx,%r14,8),%rcx
mov    %eax,(%rcx,%rbp,1)
xor    %edi,%edi
mov    %r13,%rsi
call   1060 <strtok@plt>
add    $0x4,%rbp
test   %rax,%rax
jne    1280 <load_labels_s+0x130>
jmp    1240 <load_labels_s+0xf0>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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