#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 */
float atof(char *);
int /*<<< orphan*/ *fgets(char *, int const, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
char *strtok(char *, char *);
int strtol(char *, char **, int);
float *docsNormFromSeqFile(FILE *docsNormFile, int totalDocs) {
  const int MAX_BYTES_READ_PER_LINE = 1000;
  char line[MAX_BYTES_READ_PER_LINE];
  int docsCount = 0;
  float *docsNorm = (float *)malloc(sizeof(float) * totalDocs);
  int docId;
  float docNorm;
  char *tokens;
  while (fgets(line, MAX_BYTES_READ_PER_LINE, docsNormFile) != NULL &&
         docsCount < totalDocs) {
    strtok(line, "\n");
    tokens = strtok(line, ":");
    char *ptr;
    docId = strtol(tokens, &ptr, 10);
    tokens = strtok(NULL, ":");
    docNorm = atof(tokens);
    docsNorm[docId] = docNorm;
    docsCount++;
  }
  return docsNorm;
}


x86 assembly (clang, -O0):
<docsNormFromSeqFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x3e8,-0x10(%rbp)
mov    %rsp,%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdx
lea    -0x430(%rbp),%rdi
mov    $0x3e8,%esi
call   1040 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x431(%rbp)
je     11c3 <docsNormFromSeqFile+0x73>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
setl   %al
mov    %al,-0x431(%rbp)
mov    -0x431(%rbp),%al
test   $0x1,%al
jne    11d6 <docsNormFromSeqFile+0x86>
jmp    1257 <docsNormFromSeqFile+0x107>
lea    -0x430(%rbp),%rdi
lea    0xe1c(%rip),%rsi
call   1070 <strtok@plt>
lea    -0x430(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xde2(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <atof@plt>
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118a <docsNormFromSeqFile+0x3a>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<docsNormFromSeqFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f8,%rsp
mov    %rdi,%rbx
mov    %rsi,(%rsp)
lea    0x0(,%rsi,4),%edi
call   1060 <malloc@plt>
mov    %rax,%r13
lea    0x10(%rsp),%rdi
mov    $0x3e8,%esi
mov    %rbx,%r15
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     122d <docsNormFromSeqFile+0xdd>
cmpl   $0x0,(%rsp)
jle    122d <docsNormFromSeqFile+0xdd>
mov    $0x1,%r14d
lea    0x10(%rsp),%rbx
lea    0xe51(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xe36(%rip),%rsi
call   1070 <strtok@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <strtok@plt>
mov    %rax,%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%r12d
xor    %edi,%edi
mov    %rbp,%rsi
call   1070 <strtok@plt>
mov    %rax,%rdi
call   1030 <atof@plt>
movslq %r12d,%rax
movss  %xmm0,0x0(%r13,%rax,4)
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     122d <docsNormFromSeqFile+0xdd>
lea    0x1(%r14),%eax
cmp    (%rsp),%r14d
mov    %eax,%r14d
jl     11c0 <docsNormFromSeqFile+0x70>
mov    %r13,%rax
add    $0x3f8,%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 float* @docsNormFromSeqFile(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca float*
%9 = alloca i32
%10 = alloca float
%11 = alloca i8*
%12 = alloca i8*
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 1000, i32* %5
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca i8, i64 1000
store i32 0, i32* %7
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = mul i64 4, %16
%18 = trunc i64 %17 to i32
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to float*
store float* %20, float** %8
br label %21
21: ; preds = %31, %2
%22 = load i32*, i32** %3
%23 = call i32* @fgets(i8* %14, i32 1000, i32* %22)
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i32, i32* %7
%27 = load i32, i32* %4
%28 = icmp slt i32 %26, %27
br label %29
29: ; preds = %25, %21
%30 = phi i1 [ false, %21 ], [ %28, %25 ]
br i1 %30, label %31, label %46
31: ; preds = %29
%32 = call i8* @strtok(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%33 = call i8* @strtok(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %33, i8** %11
%34 = load i8*, i8** %11
%35 = call i32 @strtol(i8* %34, i8** %12, i32 10)
store i32 %35, i32* %9
%36 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %36, i8** %11
%37 = load i8*, i8** %11
%38 = call float @atof(i8* %37)
store float %38, float* %10
%39 = load float, float* %10
%40 = load float*, float** %8
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds float, float* %40, i64 %42
store float %39, float* %43
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %21
46: ; preds = %29
%47 = load float*, float** %8
%48 = load i8*, i8** %6
ret float* %47
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [2 x i8] c":\00"
define float* @docsNormFromSeqFile(i32* nocapture %0, i32 %1) {
%3 = alloca i8*
%4 = alloca [1000 x i8]
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%6 = shl i32 %1, 2
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to float*
%9 = call i32* @fgets(i8* %5, i32 1000, i32* %0)
%10 = icmp ne i32* %9, null
%11 = icmp sgt i32 %1, 0
%12 = and i1 %10, %11
br i1 %12, label %13, label %29
13: ; preds = %2
%14 = bitcast i8** %3 to i8*
br label %15
15: ; preds = %13, %15
%16 = phi i32 [ 0, %13 ], [ %24, %15 ]
%17 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @strtol(i8* %18, i8** %3, i32 10)
%20 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = call float @atof(i8* %20)
%22 = sext i32 %19 to i64
%23 = getelementptr inbounds float, float* %8, i64 %22
store float %21, float* %23
%24 = add nuw nsw i32 %16, 1
%25 = call i32* @fgets(i8* %5, i32 1000, i32* %0)
%26 = icmp ne i32* %25, null
%27 = icmp slt i32 %24, %1
%28 = select i1 %26, i1 %27, i1 false
br i1 %28, label %15, label %29
29: ; preds = %15, %2
ret float* %8
}