#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
double **readLabels() {
  size_t result;
  double **Y = (double **)malloc(10 * sizeof(double *));
  for (int i = 0; i < 10; i++) {
    Y[i] = (double *)malloc(5000 * sizeof(double));
    for (int j = 0; j < 5000; j++) {
      Y[i][j] = 0;
    }
  }
  FILE *in;
  in = fopen("train-labels.idx1-ubyte", "rb");
  unsigned char buffer[5000];
  result = fread(buffer, 1, 8, in);
  result = fread(buffer, 1, 5000, in);
  for (int j = 0; j < 5000; j++) {
    int num = (int)(buffer[j]);
    Y[num][j] = 1;
  }
  fclose(in);
  return Y;
}


x86 assembly (clang, -O0):
<readLabels>:
push   %rbp
mov    %rsp,%rbp
sub    $0x13c0,%rsp
mov    $0x50,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11d0 <readLabels+0x90>
mov    $0x9c40,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x18(%rbp)
cmpl   $0x1388,-0x18(%rbp)
jge    11bd <readLabels+0x7d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118a <readLabels+0x4a>
jmp    11c2 <readLabels+0x82>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1160 <readLabels+0x20>
lea    0xe31(%rip),%rdi
lea    0xe42(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    -0x13b0(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8,%edx
call   1030 <fread@plt>
mov    %rax,-0x8(%rbp)
lea    -0x13b0(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1388,%edx
call   1030 <fread@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x13b4(%rbp)
cmpl   $0x1388,-0x13b4(%rbp)
jge    1289 <readLabels+0x149>
movslq -0x13b4(%rbp),%rax
movzbl -0x13b0(%rbp,%rax,1),%eax
ff
mov    %eax,-0x13b8(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x13b8(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x13b4(%rbp),%rcx
movsd  0xd90(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x13b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13b4(%rbp)
jmp    122d <readLabels+0xed>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
add    $0x13c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readLabels>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1388,%rsp
mov    $0x50,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    $0x9c40,%edi
call   1060 <malloc@plt>
mov    %rax,(%r12)
xor    %ebx,%ebx
mov    $0x9c40,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    $0x9c40,%edi
call   1060 <malloc@plt>
mov    %rax,0x8(%r12)
mov    $0x9c40,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    $0x9c40,%edi
call   1060 <malloc@plt>
mov    %rax,0x10(%r12)
mov    $0x9c40,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    $0x9c40,%edi
call   1060 <malloc@plt>
mov    %rax,0x18(%r12)
mov    $0x9c40,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    $0x9c40,%edi
call   1060 <malloc@plt>
mov    %rax,0x20(%r12)
mov    $0x9c40,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    $0x9c40,%edi
call   1060 <malloc@plt>
mov    %rax,0x28(%r12)
mov    $0x9c40,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    $0x9c40,%edi
call   1060 <malloc@plt>
mov    %rax,0x30(%r12)
mov    $0x9c40,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    $0x9c40,%edi
call   1060 <malloc@plt>
mov    %rax,0x38(%r12)
mov    $0x9c40,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    $0x9c40,%edi
call   1060 <malloc@plt>
mov    %rax,0x40(%r12)
mov    $0x9c40,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    $0x9c40,%edi
call   1060 <malloc@plt>
mov    %rax,0x48(%r12)
mov    $0x9c40,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xd61(%rip),%rdi
lea    0xd72(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1388,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
movabs $0x3ff0000000000000,%rax
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rsp,%rbx,1),%ecx
mov    (%r12,%rcx,8),%rcx
mov    %rax,(%rcx,%rbx,8)
movzbl 0x1(%rsp,%rbx,1),%ecx
mov    (%r12,%rcx,8),%rcx
mov    %rax,0x8(%rcx,%rbx,8)
movzbl 0x2(%rsp,%rbx,1),%ecx
mov    (%r12,%rcx,8),%rcx
mov    %rax,0x10(%rcx,%rbx,8)
movzbl 0x3(%rsp,%rbx,1),%ecx
mov    (%r12,%rcx,8),%rcx
mov    %rax,0x18(%rcx,%rbx,8)
movzbl 0x4(%rsp,%rbx,1),%ecx
mov    (%r12,%rcx,8),%rcx
mov    %rax,0x20(%rcx,%rbx,8)
add    $0x5,%rbx
cmp    $0x1388,%rbx
jne    12f0 <readLabels+0x1a0>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rax
add    $0x1388,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [24 x i8] c"train-labels.idx1-ubyte\00"
@.str.1 = [3 x i8] c"rb\00"
define double** @readLabels() {
%1 = alloca i64
%2 = alloca double**
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [5000 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = call i64 @malloc(i32 80)
%10 = inttoptr i64 %9 to double**
store double** %10, double*** %2
store i32 0, i32* %3
br label %11
11: ; preds = %37, %0
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 10
br i1 %13, label %14, label %40
14: ; preds = %11
%15 = call i64 @malloc(i32 40000)
%16 = inttoptr i64 %15 to double*
%17 = load double**, double*** %2
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double*, double** %17, i64 %19
store double* %16, double** %20
store i32 0, i32* %4
br label %21
21: ; preds = %33, %14
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 5000
br i1 %23, label %24, label %36
24: ; preds = %21
%25 = load double**, double*** %2
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double*, double** %25, i64 %27
%29 = load double*, double** %28
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
store double 0.000000e+00, double* %32
br label %33
33: ; preds = %24
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %21
36: ; preds = %21
br label %37
37: ; preds = %36
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %11
40: ; preds = %11
%41 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %41, i32** %5
%42 = getelementptr inbounds [5000 x i8], [5000 x i8]* %6, i64 0, i64 0
%43 = load i32*, i32** %5
%44 = call i64 @fread(i8* %42, i32 1, i32 8, i32* %43)
store i64 %44, i64* %1
%45 = getelementptr inbounds [5000 x i8], [5000 x i8]* %6, i64 0, i64 0
%46 = load i32*, i32** %5
%47 = call i64 @fread(i8* %45, i32 1, i32 5000, i32* %46)
store i64 %47, i64* %1
store i32 0, i32* %7
br label %48
48: ; preds = %65, %40
%49 = load i32, i32* %7
%50 = icmp slt i32 %49, 5000
br i1 %50, label %51, label %68
51: ; preds = %48
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [5000 x i8], [5000 x i8]* %6, i64 0, i64 %53
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
store i32 %56, i32* %8
%57 = load double**, double*** %2
%58 = load i32, i32* %8
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double*, double** %57, i64 %59
%61 = load double*, double** %60
%62 = load i32, i32* %7
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %61, i64 %63
store double 1.000000e+00, double* %64
br label %65
65: ; preds = %51
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
store i32 %67, i32* %7
br label %48
68: ; preds = %48
%69 = load i32*, i32** %5
%70 = call i32 @fclose(i32* %69)
%71 = load double**, double*** %2
ret double** %71
}

LLVM IR (-O2):
@.str = [24 x i8] c"train-labels.idx1-ubyte\00"
@.str.1 = [3 x i8] c"rb\00"
define double** @readLabels() {
%1 = alloca [5000 x i8]
%2 = tail call i64 @malloc(i32 80)
%3 = inttoptr i64 %2 to double**
%4 = tail call i64 @malloc(i32 40000)
%5 = inttoptr i64 %4 to double*
%6 = inttoptr i64 %4 to i8*
store double* %5, double** %3
%7 = tail call i64 @malloc(i32 40000)
%8 = inttoptr i64 %7 to double*
%9 = inttoptr i64 %7 to i8*
%10 = getelementptr inbounds double*, double** %3, i64 1
store double* %8, double** %10
%11 = tail call i64 @malloc(i32 40000)
%12 = inttoptr i64 %11 to double*
%13 = inttoptr i64 %11 to i8*
%14 = getelementptr inbounds double*, double** %3, i64 2
store double* %12, double** %14
%15 = tail call i64 @malloc(i32 40000)
%16 = inttoptr i64 %15 to double*
%17 = inttoptr i64 %15 to i8*
%18 = getelementptr inbounds double*, double** %3, i64 3
store double* %16, double** %18
%19 = tail call i64 @malloc(i32 40000)
%20 = inttoptr i64 %19 to double*
%21 = inttoptr i64 %19 to i8*
%22 = getelementptr inbounds double*, double** %3, i64 4
store double* %20, double** %22
%23 = tail call i64 @malloc(i32 40000)
%24 = inttoptr i64 %23 to double*
%25 = inttoptr i64 %23 to i8*
%26 = getelementptr inbounds double*, double** %3, i64 5
store double* %24, double** %26
%27 = tail call i64 @malloc(i32 40000)
%28 = inttoptr i64 %27 to double*
%29 = inttoptr i64 %27 to i8*
%30 = getelementptr inbounds double*, double** %3, i64 6
store double* %28, double** %30
%31 = tail call i64 @malloc(i32 40000)
%32 = inttoptr i64 %31 to double*
%33 = inttoptr i64 %31 to i8*
%34 = getelementptr inbounds double*, double** %3, i64 7
store double* %32, double** %34
%35 = tail call i64 @malloc(i32 40000)
%36 = inttoptr i64 %35 to double*
%37 = inttoptr i64 %35 to i8*
%38 = getelementptr inbounds double*, double** %3, i64 8
store double* %36, double** %38
%39 = tail call i64 @malloc(i32 40000)
%40 = inttoptr i64 %39 to double*
%41 = inttoptr i64 %39 to i8*
%42 = getelementptr inbounds double*, double** %3, i64 9
store double* %40, double** %42
%43 = tail call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%44 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 0
%45 = call i64 @fread(i8* %44, i32 1, i32 8, i32* %43)
%46 = call i64 @fread(i8* %44, i32 1, i32 5000, i32* %43)
br label %49
47: ; preds = %49
%48 = tail call i32 @fclose(i32* %43)
ret double** %3
49: ; preds = %49, %0
%50 = phi i64 [ 0, %0 ], [ %85, %49 ]
%51 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = zext i8 %52 to i64
%54 = getelementptr inbounds double*, double** %3, i64 %53
%55 = load double*, double** %54
%56 = getelementptr inbounds double, double* %55, i64 %50
store double 1.000000e+00, double* %56
%57 = add nuw nsw i64 %50, 1
%58 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 %57
%59 = load i8, i8* %58
%60 = zext i8 %59 to i64
%61 = getelementptr inbounds double*, double** %3, i64 %60
%62 = load double*, double** %61
%63 = getelementptr inbounds double, double* %62, i64 %57
store double 1.000000e+00, double* %63
%64 = add nuw nsw i64 %50, 2
%65 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 %64
%66 = load i8, i8* %65
%67 = zext i8 %66 to i64
%68 = getelementptr inbounds double*, double** %3, i64 %67
%69 = load double*, double** %68
%70 = getelementptr inbounds double, double* %69, i64 %64
store double 1.000000e+00, double* %70
%71 = add nuw nsw i64 %50, 3
%72 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 %71
%73 = load i8, i8* %72
%74 = zext i8 %73 to i64
%75 = getelementptr inbounds double*, double** %3, i64 %74
%76 = load double*, double** %75
%77 = getelementptr inbounds double, double* %76, i64 %71
store double 1.000000e+00, double* %77
%78 = add nuw nsw i64 %50, 4
%79 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 %78
%80 = load i8, i8* %79
%81 = zext i8 %80 to i64
%82 = getelementptr inbounds double*, double** %3, i64 %81
%83 = load double*, double** %82
%84 = getelementptr inbounds double, double* %83, i64 %78
store double 1.000000e+00, double* %84
%85 = add nuw nsw i64 %50, 5
%86 = icmp eq i64 %85, 5000
br i1 %86, label %47, label %49
}