#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*/ *fgets(char *, int const, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
char *strtok(char *, char *);
int strtol(char *, char **, int);
int *maxFreqFromSeqFile(FILE *seqFile, int totalDocs) {
  const int MAX_BYTES_READ_PER_LINE = 1000;
  char line[MAX_BYTES_READ_PER_LINE];
  int docsCount = 0;
  int *maxFreqPerDocs = (int *)malloc(sizeof(int) * totalDocs);
  int docId;
  int maxFreqInCurrentDoc;
  char *tokens;
  while (fgets(line, MAX_BYTES_READ_PER_LINE, seqFile) != NULL &&
         docsCount < totalDocs) {
    strtok(line, "\n");
    tokens = strtok(line, ":");
    char *ptr1, *ptr2;
    docId = strtol(tokens, &ptr1, 10);
    tokens = strtok(NULL, ":");
    maxFreqInCurrentDoc = strtol(tokens, &ptr2, 10);
    maxFreqPerDocs[docId] = maxFreqInCurrentDoc;
    docsCount++;
  }
  return maxFreqPerDocs;
}


x86 assembly (clang, -O0):
<maxFreqFromSeqFile>:
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   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdx
lea    -0x430(%rbp),%rdi
mov    $0x3e8,%esi
call   1030 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x431(%rbp)
je     11b3 <maxFreqFromSeqFile+0x73>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
setl   %al
mov    %al,-0x431(%rbp)
mov    -0x431(%rbp),%al
test   $0x1,%al
jne    11c6 <maxFreqFromSeqFile+0x86>
jmp    124a <maxFreqFromSeqFile+0x10a>
lea    -0x430(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1060 <strtok@plt>
lea    -0x430(%rbp),%rdi
lea    0xe1b(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdf2(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x48(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117a <maxFreqFromSeqFile+0x3a>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
add    $0x440,%rsp
pop    %rbp
ret

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

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