#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*/ SEEK_SET;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
scalar_t__ ftell(int /*<<< orphan*/ *);
long long *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
void ComputeBlockStartPoints(char *file_name, int num_blocks,
                             long long **blocks, long long *num_lines) {
  printf("# ComputeBlockStartPoints %s, num_blocks=%d\n", file_name,
         num_blocks);
  long long block_size;
  int line_count = 0;
  int curr_block = 0;
  char line[20000];
  FILE *file;
  *num_lines = 0;
  file = fopen(file_name, "r");
  while (1) {
    fgets(line, 20000, file);
    if (feof(file))
      break;
    ++(*num_lines);
  }
  printf("  num_lines=%lld, eof position %lld\n", *num_lines,
         (long long)ftell(file));
  fseek(file, 0, SEEK_SET);
  block_size = (*num_lines - 1) / num_blocks + 1;
  printf("  block_size=%lld lines\n  blocks = [0", block_size);
  *blocks = malloc((num_blocks + 1) * sizeof(long long));
  (*blocks)[0] = 0;
  curr_block = 0;
  long long int cur_size = 0;
  while (1) {
    fgets(line, 20000, file);
    line_count++;
    cur_size++;
    if (cur_size == block_size || line_count == (*num_lines)) {
      curr_block++;
      (*blocks)[curr_block] = (long long)ftell(file);
      printf(" %lld", (*blocks)[curr_block]);
      if (line_count == (*num_lines)) {
        break;
      }
      cur_size = 0;
    }
  }
  printf("]\n");
  assert(curr_block == num_blocks);
  assert(line_count == (*num_lines));
  fclose(file);
}


x86 assembly (clang, -O0):
<ComputeBlockStartPoints>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4e70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x4e58(%rbp)
lea    -0x4e50(%rbp),%rdi
mov    -0x4e58(%rbp),%rdx
mov    $0x4e20,%esi
call   1050 <fgets@plt>
mov    -0x4e58(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     1222 <ComputeBlockStartPoints+0x92>
jmp    1235 <ComputeBlockStartPoints+0xa5>
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    11ef <ComputeBlockStartPoints+0x5f>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x4e68(%rbp)
mov    -0x4e58(%rbp),%rdi
call   1070 <ftell@plt>
mov    -0x4e68(%rbp),%rsi
mov    %rax,%rdx
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4e58(%rbp),%rdi
mov    0x2d6b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
sub    $0x1,%rax
movslq -0xc(%rbp),%rcx
cqto
idiv   %rcx
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x30(%rbp)
movq   $0x0,-0x4e60(%rbp)
lea    -0x4e50(%rbp),%rdi
mov    -0x4e58(%rbp),%rdx
mov    $0x4e20,%esi
call   1050 <fgets@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x4e60(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x4e60(%rbp)
mov    -0x4e60(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     133e <ComputeBlockStartPoints+0x1ae>
movslq -0x2c(%rbp),%rax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%rax
jne    13a3 <ComputeBlockStartPoints+0x213>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x4e58(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x30(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xcff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x2c(%rbp),%rax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%rax
jne    1398 <ComputeBlockStartPoints+0x208>
jmp    13a8 <ComputeBlockStartPoints+0x218>
movq   $0x0,-0x4e60(%rbp)
jmp    12e9 <ComputeBlockStartPoints+0x159>
lea    0xcd1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movslq -0x2c(%rbp),%rax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x4e58(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x4e70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ComputeBlockStartPoints>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4e48,%rsp
mov    %rcx,%r15
mov    %rdx,0x8(%rsp)
mov    %esi,%r12d
mov    %rdi,%rbx
lea    0xe3a(%rip),%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
movq   $0x0,(%r15)
lea    0xe4c(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
mov    %rax,%r14
lea    0x20(%rsp),%rdi
mov    $0x4e20,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
mov    %r14,%rdi
call   1090 <feof@plt>
test   %rax,%rax
jne    1231 <ComputeBlockStartPoints+0x91>
lea    0x20(%rsp),%rbp
addq   $0x1,(%r15)
mov    %rbp,%rdi
mov    $0x4e20,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
mov    %r14,%rdi
call   1090 <feof@plt>
test   %rax,%rax
je     1210 <ComputeBlockStartPoints+0x70>
mov    (%r15),%rbp
mov    %r14,%rdi
call   1080 <ftell@plt>
lea    0xdec(%rip),%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    (%r15),%rax
add    $0xffffffffffffffff,%rax
movslq %r12d,%rcx
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     1283 <ComputeBlockStartPoints+0xe3>
cqto
idiv   %rcx
mov    %rax,%rbx
jmp    128a <ComputeBlockStartPoints+0xea>
xor    %edx,%edx
div    %r12d
mov    %eax,%ebx
lea    0x1(%rbx),%rsi
lea    0xdbf(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,0x10(%rsp)
lea    0x8(,%r12,8),%edi
call   10a0 <malloc@plt>
mov    0x8(%rsp),%rcx
mov    %rax,(%rcx)
movq   $0x0,(%rax)
lea    0x20(%rsp),%rbp
xor    %r12d,%r12d
xor    %r13d,%r13d
mov    %rbx,0x18(%rsp)
jmp    1309 <ComputeBlockStartPoints+0x169>
nop
mov    %r13,%rbx
add    $0x1,%r13d
mov    %r14,%rdi
call   1080 <ftell@plt>
mov    0x8(%rsp),%rcx
mov    (%rcx),%rcx
mov    %ebx,%edx
mov    %rax,0x8(%rcx,%rdx,8)
lea    0xd85(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %r12,(%r15)
mov    0x18(%rsp),%rbx
je     1335 <ComputeBlockStartPoints+0x195>
add    $0x1,%r12
mov    %r12,%rax
mov    %rax,%r12
mov    %rbp,%rdi
mov    $0x4e20,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
sub    $0x1,%rbx
jb     12d0 <ComputeBlockStartPoints+0x130>
lea    0x1(%r12),%rax
cmp    (%r15),%r12
jne    1310 <ComputeBlockStartPoints+0x170>
jmp    12d0 <ComputeBlockStartPoints+0x130>
mov    %r12d,%ebx
lea    0xd41(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
cmp    0x10(%rsp),%r13d
sete   %dil
call   1070 <assert@plt>
xor    %edi,%edi
cmp    %rbx,(%r15)
sete   %dil
call   1070 <assert@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
add    $0x4e48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"# ComputeBlockStartPoints %s, num_blocks=%d\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [37 x i8] c" num_lines=%lld, eof position %lld\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [38 x i8] c" block_size=%lld lines\0A blocks = [0\00"
@.str.4 = [6 x i8] c" %lld\00"
@.str.5 = [3 x i8] c"]\0A\00"
define void @ComputeBlockStartPoints(i8* %0, i32 %1, i64** %2, i64* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64**
%8 = alloca i64*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca [20000 x i8]
%13 = alloca i32*
%14 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store i64** %2, i64*** %7
store i64* %3, i64** %8
%15 = load i8*, i8** %5
%16 = load i32, i32* %6
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %16)
store i32 0, i32* %10
store i32 0, i32* %11
%18 = load i64*, i64** %8
store i64 0, i64* %18
%19 = load i8*, i8** %5
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %13
br label %21
21: ; preds = %4, %29
%22 = getelementptr inbounds [20000 x i8], [20000 x i8]* %12, i64 0, i64 0
%23 = load i32*, i32** %13
%24 = call i32 @fgets(i8* %22, i32 20000, i32* %23)
%25 = load i32*, i32** %13
%26 = call i64 @feof(i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %21
br label %33
29: ; preds = %21
%30 = load i64*, i64** %8
%31 = load i64, i64* %30
%32 = add nsw i64 %31, 1
store i64 %32, i64* %30
br label %21
33: ; preds = %28
%34 = load i64*, i64** %8
%35 = load i64, i64* %34
%36 = load i32*, i32** %13
%37 = call i64 @ftell(i32* %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i64 %35, i64 %37)
%39 = load i32*, i32** %13
%40 = load i32, i32* @SEEK_SET
%41 = call i32 @fseek(i32* %39, i32 0, i32 %40)
%42 = load i64*, i64** %8
%43 = load i64, i64* %42
%44 = sub nsw i64 %43, 1
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = sdiv i64 %44, %46
%48 = add nsw i64 %47, 1
store i64 %48, i64* %9
%49 = load i64, i64* %9
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i64 %49)
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
%53 = sext i32 %52 to i64
%54 = mul i64 %53, 8
%55 = trunc i64 %54 to i32
%56 = call i64* @malloc(i32 %55)
%57 = load i64**, i64*** %7
store i64* %56, i64** %57
%58 = load i64**, i64*** %7
%59 = load i64*, i64** %58
%60 = getelementptr inbounds i64, i64* %59, i64 0
store i64 0, i64* %60
store i32 0, i32* %11
store i64 0, i64* %14
br label %61
61: ; preds = %33, %102
%62 = getelementptr inbounds [20000 x i8], [20000 x i8]* %12, i64 0, i64 0
%63 = load i32*, i32** %13
%64 = call i32 @fgets(i8* %62, i32 20000, i32* %63)
%65 = load i32, i32* %10
%66 = add nsw i32 %65, 1
store i32 %66, i32* %10
%67 = load i64, i64* %14
%68 = add nsw i64 %67, 1
store i64 %68, i64* %14
%69 = load i64, i64* %14
%70 = load i64, i64* %9
%71 = icmp eq i64 %69, %70
br i1 %71, label %78, label %72
72: ; preds = %61
%73 = load i32, i32* %10
%74 = sext i32 %73 to i64
%75 = load i64*, i64** %8
%76 = load i64, i64* %75
%77 = icmp eq i64 %74, %76
br i1 %77, label %78, label %102
78: ; preds = %72, %61
%79 = load i32, i32* %11
%80 = add nsw i32 %79, 1
store i32 %80, i32* %11
%81 = load i32*, i32** %13
%82 = call i64 @ftell(i32* %81)
%83 = load i64**, i64*** %7
%84 = load i64*, i64** %83
%85 = load i32, i32* %11
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i64, i64* %84, i64 %86
store i64 %82, i64* %87
%88 = load i64**, i64*** %7
%89 = load i64*, i64** %88
%90 = load i32, i32* %11
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i64, i64* %89, i64 %91
%93 = load i64, i64* %92
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i64 %93)
%95 = load i32, i32* %10
%96 = sext i32 %95 to i64
%97 = load i64*, i64** %8
%98 = load i64, i64* %97
%99 = icmp eq i64 %96, %98
br i1 %99, label %100, label %101
100: ; preds = %78
br label %103
101: ; preds = %78
store i64 0, i64* %14
br label %102
102: ; preds = %101, %72
br label %61
103: ; preds = %100
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%105 = load i32, i32* %11
%106 = load i32, i32* %6
%107 = icmp eq i32 %105, %106
%108 = zext i1 %107 to i32
%109 = call i32 @assert(i32 %108)
%110 = load i32, i32* %10
%111 = sext i32 %110 to i64
%112 = load i64*, i64** %8
%113 = load i64, i64* %112
%114 = icmp eq i64 %111, %113
%115 = zext i1 %114 to i32
%116 = call i32 @assert(i32 %115)
%117 = load i32*, i32** %13
%118 = call i32 @fclose(i32* %117)
ret void
}

LLVM IR (-O2):
@.str = [45 x i8] c"# ComputeBlockStartPoints %s, num_blocks=%d\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [37 x i8] c" num_lines=%lld, eof position %lld\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [38 x i8] c" block_size=%lld lines\0A blocks = [0\00"
@.str.4 = [6 x i8] c" %lld\00"
@str = [2 x i8] c"]\00"
define void @ComputeBlockStartPoints(i8* %0, i32 %1, i64** nocapture %2, i64* nocapture %3) {
%5 = alloca [20000 x i8]
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
%7 = getelementptr inbounds [20000 x i8], [20000 x i8]* %5, i64 0, i64 0
store i64 0, i64* %3
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @fgets(i8* %7, i32 20000, i32* %8)
%10 = call i64 @feof(i32* %8)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %4, %12
%13 = load i64, i64* %3
%14 = add nsw i64 %13, 1
store i64 %14, i64* %3
%15 = call i32 @fgets(i8* %7, i32 20000, i32* %8)
%16 = call i64 @feof(i32* %8)
%17 = icmp eq i64 %16, 0
br i1 %17, label %12, label %18
18: ; preds = %12, %4
%19 = load i64, i64* %3
%20 = call i64 @ftell(i32* %8)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i64 %19, i64 %20)
%22 = load i32, i32* @SEEK_SET
%23 = call i32 @fseek(i32* %8, i32 0, i32 %22)
%24 = load i64, i64* %3
%25 = add nsw i64 %24, -1
%26 = sext i32 %1 to i64
%27 = sdiv i64 %25, %26
%28 = add nsw i64 %27, 1
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i64 %28)
%30 = shl i32 %1, 3
%31 = add i32 %30, 8
%32 = call i64* @malloc(i32 %31)
store i64* %32, i64** %2
store i64 0, i64* %32
br label %33
33: ; preds = %46, %18
%34 = phi i64 [ %40, %46 ], [ 0, %18 ]
%35 = phi i32 [ %47, %46 ], [ 0, %18 ]
br label %36
36: ; preds = %33, %42
%37 = phi i64 [ %40, %42 ], [ %34, %33 ]
%38 = phi i64 [ %43, %42 ], [ 0, %33 ]
%39 = call i32 @fgets(i8* %7, i32 20000, i32* %8)
%40 = add nuw i64 %37, 1
%41 = icmp eq i64 %38, %27
br i1 %41, label %46, label %42
42: ; preds = %36
%43 = add nuw nsw i64 %38, 1
%44 = load i64, i64* %3
%45 = icmp eq i64 %44, %40
br i1 %45, label %46, label %36
46: ; preds = %42, %36
%47 = add nuw nsw i32 %35, 1
%48 = call i64 @ftell(i32* %8)
%49 = load i64*, i64** %2
%50 = zext i32 %47 to i64
%51 = getelementptr inbounds i64, i64* %49, i64 %50
store i64 %48, i64* %51
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i64 %48)
%53 = load i64, i64* %3
%54 = icmp eq i64 %53, %40
br i1 %54, label %55, label %33
55: ; preds = %46
%56 = and i64 %40, 4294967295
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%58 = icmp eq i32 %47, %1
%59 = zext i1 %58 to i32
%60 = call i32 @assert(i32 %59)
%61 = load i64, i64* %3
%62 = icmp eq i64 %61, %56
%63 = zext i1 %62 to i32
%64 = call i32 @assert(i32 %63)
%65 = call i32 @fclose(i32* %8)
ret void
}