#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 atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ malloc(int);
scalar_t__ realloc(int *, int);
int *read_hash(char *hash_filename, int *num_idx) {
  *num_idx = 0;
  char temp_line[2000];
  int *hash = (int *)malloc(100000 * sizeof(int));
  FILE *fp = fopen(hash_filename, "r");
  int t;
  while (fgets(temp_line, 2000, fp) != NULL) {
    t = 0;
    while (temp_line[t] >= '0' && temp_line[t] <= '9')
      t++;
    temp_line[t] = '\0';
    hash[*num_idx] = atoi(temp_line);
    (*num_idx)++;
  }
  fclose(fp);
  hash = (int *)realloc(hash, (*num_idx) * sizeof(int));
  return hash;
}


x86 assembly (clang, -O0):
<read_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x800,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    $0x61a80,%edi
call   1050 <malloc@plt>
mov    %rax,-0x7e8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x7f0(%rbp)
lea    -0x7e0(%rbp),%rdi
mov    -0x7f0(%rbp),%rdx
mov    $0x7d0,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1271 <read_hash+0x111>
movl   $0x0,-0x7f4(%rbp)
movslq -0x7f4(%rbp),%rax
movsbl -0x7e0(%rbp,%rax,1),%ecx
ff
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x7f5(%rbp)
jl     120c <read_hash+0xac>
movslq -0x7f4(%rbp),%rax
movsbl -0x7e0(%rbp,%rax,1),%eax
ff
cmp    $0x39,%eax
setle  %al
mov    %al,-0x7f5(%rbp)
mov    -0x7f5(%rbp),%al
test   $0x1,%al
jne    121f <read_hash+0xbf>
jmp    1233 <read_hash+0xd3>
mov    -0x7f4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7f4(%rbp)
jmp    11d1 <read_hash+0x71>
movslq -0x7f4(%rbp),%rax
movb   $0x0,-0x7e0(%rbp,%rax,1)
lea    -0x7e0(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%edx
mov    -0x7e8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    11a5 <read_hash+0x45>
mov    -0x7f0(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x7e8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x7e8(%rbp)
mov    -0x7e8(%rbp),%rax
add    $0x800,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_hash>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x7d8,%rsp
mov    %rsi,%rbx
mov    %rdi,%r15
movl   $0x0,(%rsi)
mov    $0x61a80,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
lea    0xe72(%rip),%rsi
mov    %r15,%rdi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x7d0,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1205 <read_hash+0xa5>
xor    %ecx,%ecx
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rcx,%rax
movzbl (%rsp,%rcx,1),%edx
add    $0xd0,%dl
add    $0x1,%rcx
cmp    $0xa,%dl
jb     11c0 <read_hash+0x60>
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %r12,%rdi
call   1080 <atoi@plt>
movslq (%rbx),%rcx
mov    %eax,(%r14,%rcx,4)
addl   $0x1,(%rbx)
mov    %r12,%rdi
mov    $0x7d0,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
mov    $0x0,%ecx
test   %rax,%rax
jne    11c0 <read_hash+0x60>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    (%rbx),%esi
shl    $0x2,%esi
mov    %r14,%rdi
call   1060 <realloc@plt>
add    $0x7d8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32* @read_hash(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [2000 x i8]
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%9 = load i32*, i32** %4
store i32 0, i32* %9
%10 = call i64 @malloc(i32 400000)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %6
%12 = load i8*, i8** %3
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %7
br label %14
14: ; preds = %39, %2
%15 = getelementptr inbounds [2000 x i8], [2000 x i8]* %5, i64 0, i64 0
%16 = load i32*, i32** %7
%17 = call i32* @fgets(i8* %15, i32 2000, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %53
19: ; preds = %14
store i32 0, i32* %8
br label %20
20: ; preds = %36, %19
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [2000 x i8], [2000 x i8]* %5, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp sge i32 %25, 48
br i1 %26, label %27, label %34
27: ; preds = %20
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [2000 x i8], [2000 x i8]* %5, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp sle i32 %32, 57
br label %34
34: ; preds = %27, %20
%35 = phi i1 [ false, %20 ], [ %33, %27 ]
br i1 %35, label %36, label %39
36: ; preds = %34
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %20
39: ; preds = %34
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [2000 x i8], [2000 x i8]* %5, i64 0, i64 %41
store i8 0, i8* %42
%43 = getelementptr inbounds [2000 x i8], [2000 x i8]* %5, i64 0, i64 0
%44 = call i32 @atoi(i8* %43)
%45 = load i32*, i32** %6
%46 = load i32*, i32** %4
%47 = load i32, i32* %46
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %45, i64 %48
store i32 %44, i32* %49
%50 = load i32*, i32** %4
%51 = load i32, i32* %50
%52 = add nsw i32 %51, 1
store i32 %52, i32* %50
br label %14
53: ; preds = %14
%54 = load i32*, i32** %7
%55 = call i32 @fclose(i32* %54)
%56 = load i32*, i32** %6
%57 = load i32*, i32** %4
%58 = load i32, i32* %57
%59 = sext i32 %58 to i64
%60 = mul i64 %59, 4
%61 = trunc i64 %60 to i32
%62 = call i64 @realloc(i32* %56, i32 %61)
%63 = inttoptr i64 %62 to i32*
store i32* %63, i32** %6
%64 = load i32*, i32** %6
ret i32* %64
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32* @read_hash(i8* nocapture %0, i32* nocapture %1) {
%3 = alloca [2000 x i8]
store i32 0, i32* %1
%4 = getelementptr inbounds [2000 x i8], [2000 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @malloc(i32 400000)
%6 = inttoptr i64 %5 to i32*
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = call i32* @fgets(i8* %4, i32 2000, i32* %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %30, label %10
10: ; preds = %2, %17
%11 = phi i64 [ %18, %17 ], [ 0, %2 ]
%12 = getelementptr inbounds [2000 x i8], [2000 x i8]* %3, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = add i8 %13, -48
%15 = icmp ult i8 %14, 10
%16 = add nuw i64 %11, 1
br i1 %15, label %17, label %19
17: ; preds = %10, %19
%18 = phi i64 [ %16, %10 ], [ 0, %19 ]
br label %10
19: ; preds = %10
%20 = and i64 %11, 4294967295
%21 = getelementptr inbounds [2000 x i8], [2000 x i8]* %3, i64 0, i64 %20
store i8 0, i8* %21
%22 = call i32 @atoi(i8* %4)
%23 = load i32, i32* %1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %6, i64 %24
store i32 %22, i32* %25
%26 = load i32, i32* %1
%27 = add nsw i32 %26, 1
store i32 %27, i32* %1
%28 = call i32* @fgets(i8* %4, i32 2000, i32* %7)
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %17
30: ; preds = %19, %2
%31 = call i32 @fclose(i32* %7)
%32 = load i32, i32* %1
%33 = shl i32 %32, 2
%34 = call i64 @realloc(i32* %6, i32 %33)
%35 = inttoptr i64 %34 to i32*
ret i32* %35
}