#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int hash_func(int);
int /*<<< orphan*/ printf(char *);
int rand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main(void) {
  int D[10000];
  int *Hash[(10000 * 2)] = {0};
  FILE *fp;
  srand((unsigned)time(NULL));
  for (int i = 0; i < 10000; i++) {
    D[i] = rand() % 20000;
  }
  for (int i = 0; i < 10000; i++) {
    int k;
    for (k = hash_func(D[i]); Hash[k]; k++) {
      k = k % (10000 * 2);
    }
    Hash[k] = &D[i];
  }
  if ((fp = fopen("hash.txt", "w"))) {
    for (int i = 0; i < (10000 * 2); i++) {
      if (Hash[i]) {
        fprintf(fp, "%d\n", *Hash[i]);
      } else {
        fprintf(fp, "NULL\n");
      }
    }
    printf("結果を"
           "hash.txt"
           "に書き込みました。\n");
  } else {
    printf("ファイルに結果を書き込めませんでした。\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30d70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30d50(%rbp),%rdi
xor    %esi,%esi
mov    $0x27100,%edx
call   1050 <memset@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x0,-0x30d5c(%rbp)
cmpl   $0x2710,-0x30d5c(%rbp)
jge    1200 <main+0x80>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x4e20,%ecx
cltd
idiv   %ecx
movslq -0x30d5c(%rbp),%rax
mov    %edx,-0x9c50(%rbp,%rax,4)
mov    -0x30d5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30d5c(%rbp)
jmp    11bf <main+0x3f>
movl   $0x0,-0x30d60(%rbp)
cmpl   $0x2710,-0x30d60(%rbp)
jge    12a9 <main+0x129>
movslq -0x30d60(%rbp),%rax
mov    -0x9c50(%rbp,%rax,4),%edi
call   1030 <hash_func@plt>
mov    %eax,-0x30d64(%rbp)
movslq -0x30d64(%rbp),%rax
cmpq   $0x0,-0x30d50(%rbp,%rax,8)
je     1271 <main+0xf1>
mov    -0x30d64(%rbp),%eax
mov    $0x4e20,%ecx
cltd
idiv   %ecx
mov    %edx,-0x30d64(%rbp)
mov    -0x30d64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30d64(%rbp)
jmp    1233 <main+0xb3>
movslq -0x30d60(%rbp),%rax
lea    -0x9c50(%rbp),%rcx
shl    $0x2,%rax
add    %rax,%rcx
movslq -0x30d64(%rbp),%rax
mov    %rcx,-0x30d50(%rbp,%rax,8)
ff
mov    -0x30d60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30d60(%rbp)
jmp    120a <main+0x8a>
lea    0xd50(%rip),%rdi
lea    0xd52(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30d58(%rbp)
cmp    $0x0,%rax
je     1367 <main+0x1e7>
movl   $0x0,-0x30d68(%rbp)
cmpl   $0x4e20,-0x30d68(%rbp)
jge    1356 <main+0x1d6>
movslq -0x30d68(%rbp),%rax
cmpq   $0x0,-0x30d50(%rbp,%rax,8)
je     1328 <main+0x1a8>
mov    -0x30d58(%rbp),%rdi
movslq -0x30d68(%rbp),%rax
mov    -0x30d50(%rbp,%rax,8),%rax
ff
mov    (%rax),%edx
lea    0xcef(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    133d <main+0x1bd>
mov    -0x30d58(%rbp),%rdi
lea    0xcd9(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1342 <main+0x1c2>
mov    -0x30d68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30d68(%rbp)
jmp    12d7 <main+0x157>
lea    0xcb8(%rip),%rdi
call   1040 <printf@plt>
jmp    137f <main+0x1ff>
lea    0xcd5(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1386 <main+0x206>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30d70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30d40,%rsp
lea    0x9c40(%rsp),%rdi
mov    $0x27100,%edx
xor    %esi,%esi
call   1050 <memset@plt>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   10b0 <rand@plt>
cltq
imul   $0x68db8bad,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2d,%rcx
add    %edx,%ecx
imul   $0x4e20,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x2710,%rbx
jne    11d0 <main+0x40>
xor    %ebx,%ebx
jmp    1229 <main+0x99>
nopl   0x0(%rax)
lea    (%rsp,%rbx,4),%rax
mov    %rax,0x9c40(%rsp,%rcx,8)
add    $0x1,%rbx
cmp    $0x2710,%rbx
je     127b <main+0xeb>
mov    (%rsp,%rbx,4),%edi
call   1040 <hash_func@plt>
movslq %eax,%rcx
cmpq   $0x0,0x9c40(%rsp,%rcx,8)
je     1210 <main+0x80>
nop
cltq
imul   $0x68db8bad,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2d,%rcx
add    %edx,%ecx
imul   $0x4e20,%ecx,%ecx
mov    %eax,%edx
sub    %ecx,%edx
neg    %ecx
add    %ecx,%eax
add    $0x1,%eax
movslq %edx,%rcx
cmpq   $0x0,0x9c48(%rsp,%rcx,8)
jne    1240 <main+0xb0>
add    $0x1,%rcx
jmp    1210 <main+0x80>
lea    0xd7e(%rip),%rdi
lea    0xd80(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12f4 <main+0x164>
mov    %rax,%r13
lea    0xd72(%rip),%r15
lea    0xdab(%rip),%r14
lea    0xd60(%rip),%r12
xor    %ebx,%ebx
jmp    12d2 <main+0x142>
nop
mov    $0x5,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %r13,%rcx
call   10a0 <fwrite@plt>
add    $0x1,%rbx
cmp    $0x4e20,%rbx
je     12f0 <main+0x160>
mov    0x9c40(%rsp,%rbx,8),%rax
test   %rax,%rax
je     12b0 <main+0x120>
mov    (%rax),%edx
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12c5 <main+0x135>
xor    %ebx,%ebx
jmp    1300 <main+0x170>
mov    $0xffffffff,%ebx
lea    0xd15(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x30d40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"hash.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [6 x i8] c"NULL\0A\00"
@.str.4 = [46 x i8] c"\E7\B5\90\E6\9E\9C\E3\82\92hash.txt\E3\81\AB\E6\9B\B8\E3\81\8D\E8\BE\BC\E3\81\BF\E3\81\BE\E3\81\97\E3\81\9F\E3\80\82\0A\00"
@.str.5 = [59 x i8] c"\E3\83\95\E3\82\A1\E3\82\A4\E3\83\AB\E3\81\AB\E7\B5\90\E6\9E\9C\E3\82\92\E6\9B\B8\E3\81\8D\E8\BE\BC\E3\82\81\E3\81\BE\E3\81\9B\E3\82\93\E3\81\A7\E3\81\97\E3\81\9F\E3\80\82\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10000 x i32]
%3 = alloca [20000 x i32*]
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = bitcast [20000 x i32*]* %3 to i8*
%10 = call i64 @time(i32* null)
%11 = trunc i64 %10 to i32
%12 = call i32 @srand(i32 %11)
store i32 0, i32* %5
br label %13
13: ; preds = %22, %0
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 10000
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = call i32 (...) @rand()
%18 = srem i32 %17, 20000
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 %20
store i32 %18, i32* %21
br label %22
22: ; preds = %16
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %13
25: ; preds = %13
store i32 0, i32* %6
br label %26
26: ; preds = %54, %25
%27 = load i32, i32* %6
%28 = icmp slt i32 %27, 10000
br i1 %28, label %29, label %57
29: ; preds = %26
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = call i32 @hash_func(i32 %33)
store i32 %34, i32* %7
br label %35
35: ; preds = %44, %29
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [20000 x i32*], [20000 x i32*]* %3, i64 0, i64 %37
%39 = load i32*, i32** %38
%40 = icmp ne i32* %39, null
br i1 %40, label %41, label %47
41: ; preds = %35
%42 = load i32, i32* %7
%43 = srem i32 %42, 20000
store i32 %43, i32* %7
br label %44
44: ; preds = %41
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %35
47: ; preds = %35
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 %49
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [20000 x i32*], [20000 x i32*]* %3, i64 0, i64 %52
store i32* %50, i32** %53
br label %54
54: ; preds = %47
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
store i32 %56, i32* %6
br label %26
57: ; preds = %26
%58 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %58, i32** %4
%59 = icmp ne i32* %58, null
br i1 %59, label %60, label %87
60: ; preds = %57
store i32 0, i32* %8
br label %61
61: ; preds = %82, %60
%62 = load i32, i32* %8
%63 = icmp slt i32 %62, 20000
br i1 %63, label %64, label %85
64: ; preds = %61
%65 = load i32, i32* %8
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [20000 x i32*], [20000 x i32*]* %3, i64 0, i64 %66
%68 = load i32*, i32** %67
%69 = icmp ne i32* %68, null
br i1 %69, label %70, label %78
70: ; preds = %64
%71 = load i32*, i32** %4
%72 = load i32, i32* %8
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [20000 x i32*], [20000 x i32*]* %3, i64 0, i64 %73
%75 = load i32*, i32** %74
%76 = load i32, i32* %75
%77 = call i32 (i32*, i8*, ...) @fprintf(i32* %71, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %76)
br label %81
78: ; preds = %64
%79 = load i32*, i32** %4
%80 = call i32 (i32*, i8*, ...) @fprintf(i32* %79, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %81
81: ; preds = %78, %70
br label %82
82: ; preds = %81
%83 = load i32, i32* %8
%84 = add nsw i32 %83, 1
store i32 %84, i32* %8
br label %61
85: ; preds = %61
%86 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
br label %89
87: ; preds = %57
%88 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %90
89: ; preds = %85
store i32 0, i32* %1
br label %90
90: ; preds = %89, %87
%91 = load i32, i32* %1
ret i32 %91
}

LLVM IR (-O2):
@.str = [9 x i8] c"hash.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [6 x i8] c"NULL\0A\00"
@str = [58 x i8] c"\E3\83\95\E3\82\A1\E3\82\A4\E3\83\AB\E3\81\AB\E7\B5\90\E6\9E\9C\E3\82\92\E6\9B\B8\E3\81\8D\E8\BE\BC\E3\82\81\E3\81\BE\E3\81\9B\E3\82\93\E3\81\A7\E3\81\97\E3\81\9F\E3\80\82\00"
@str.6 = [45 x i8] c"\E7\B5\90\E6\9E\9C\E3\82\92hash.txt\E3\81\AB\E6\9B\B8\E3\81\8D\E8\BE\BC\E3\81\BF\E3\81\BE\E3\81\97\E3\81\9F\E3\80\82\00"
define i32 @main() {
%1 = alloca [10000 x i32]
%2 = alloca [20000 x i32*]
%3 = bitcast [10000 x i32]* %1 to i8*
%4 = bitcast [20000 x i32*]* %2 to i8*
%5 = tail call i64 @time(i32* null)
%6 = trunc i64 %5 to i32
%7 = tail call i32 @srand(i32 %6)
br label %8
8: ; preds = %0, %8
%9 = phi i64 [ 0, %0 ], [ %13, %8 ]
%10 = tail call i32 (...) @rand()
%11 = srem i32 %10, 20000
%12 = getelementptr inbounds [10000 x i32], [10000 x i32]* %1, i64 0, i64 %9
store i32 %11, i32* %12
%13 = add nuw nsw i64 %9, 1
%14 = icmp eq i64 %13, 10000
br i1 %14, label %18, label %8
15: ; preds = %35
%16 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %53, label %40
18: ; preds = %8, %35
%19 = phi i64 [ %38, %35 ], [ 0, %8 ]
%20 = getelementptr inbounds [10000 x i32], [10000 x i32]* %1, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = call i32 @hash_func(i32 %21)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [20000 x i32*], [20000 x i32*]* %2, i64 0, i64 %23
%25 = load i32*, i32** %24
%26 = icmp eq i32* %25, null
br i1 %26, label %35, label %27
27: ; preds = %18, %27
%28 = phi i32 [ %30, %27 ], [ %22, %18 ]
%29 = srem i32 %28, 20000
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [20000 x i32*], [20000 x i32*]* %2, i64 0, i64 %31
%33 = load i32*, i32** %32
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %27
35: ; preds = %27, %18
%36 = phi i64 [ %23, %18 ], [ %31, %27 ]
%37 = getelementptr inbounds [20000 x i32*], [20000 x i32*]* %2, i64 0, i64 %36
store i32* %20, i32** %37
%38 = add nuw nsw i64 %19, 1
%39 = icmp eq i64 %38, 10000
br i1 %39, label %15, label %18
40: ; preds = %15, %50
%41 = phi i64 [ %51, %50 ], [ 0, %15 ]
%42 = getelementptr inbounds [20000 x i32*], [20000 x i32*]* %2, i64 0, i64 %41
%43 = load i32*, i32** %42
%44 = icmp eq i32* %43, null
br i1 %44, label %48, label %45
45: ; preds = %40
%46 = load i32, i32* %43
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %46)
br label %50
48: ; preds = %40
%49 = call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 5, i64 1, i32* %16)
br label %50
50: ; preds = %45, %48
%51 = add nuw nsw i64 %41, 1
%52 = icmp eq i64 %51, 20000
br i1 %52, label %53, label %40
53: ; preds = %50, %15
%54 = phi i8* [ getelementptr inbounds ([58 x i8], [58 x i8]* @str, i64 0, i64 0), %15 ], [ getelementptr inbounds ([45 x i8], [45 x i8]* @str.6, i64 0, i64 0), %50 ]
%55 = phi i32 [ -1, %15 ], [ 0, %50 ]
%56 = call i32 @puts(i8* dereferenceable(1) %54)
ret i32 %55
}