#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 */

/* Variables and functions */
int *find(int, int *, int *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int rand();
int /*<<< orphan*/ sort(int *, int *);
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main(void) {
  int D[10000];
  int k[5];
  int count_sum = 0;
  srand((unsigned)time(NULL));
  for (int i = 0; i < 10000; i++) {
    D[i] = rand() % 20000;
  }
  sort(&D[0], &D[10000 - 1]);
  for (int i = 0; i < 5; i++) {
    k[i] = rand() % 20000;
  }
  for (int i = 0; i < 5; i++) {
    int count = 0;
    int *result;
    printf("%d回目: %dを探索します。\n", i + 1, k[i]);
    result = find(k[i], &D[0], &D[10000 - 1], &count);
    if (result) {
      printf("データが見つかりました。\n");
      printf("探索回数: %d\n", count);
      printf("探索データのあったデータ番号: %"
             "td"
             "\n",
             result - D);
    } else {
      printf("データが見つかりませんでした。\n");
      printf("探索回数: %d\n", count);
    }
    putchar('\n');
    count_sum += count;
  }
  printf("探索が終了するまでの平均回数: %f\n", (double)count_sum / 5);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x9c74(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x0,-0x9c78(%rbp)
cmpl   $0x2710,-0x9c78(%rbp)
jge    11e7 <main+0x77>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x4e20,%ecx
cltd
idiv   %ecx
movslq -0x9c78(%rbp),%rax
mov    %edx,-0x9c50(%rbp,%rax,4)
mov    -0x9c78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c78(%rbp)
jmp    11a6 <main+0x36>
lea    -0x9c50(%rbp),%rdi
lea    -0x9c50(%rbp),%rsi
add    $0x9c3c,%rsi
call   1050 <sort@plt>
movl   $0x0,-0x9c7c(%rbp)
cmpl   $0x5,-0x9c7c(%rbp)
jge    1249 <main+0xd9>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x4e20,%ecx
cltd
idiv   %ecx
movslq -0x9c7c(%rbp),%rax
mov    %edx,-0x9c70(%rbp,%rax,4)
mov    -0x9c7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c7c(%rbp)
jmp    120b <main+0x9b>
movl   $0x0,-0x9c80(%rbp)
cmpl   $0x5,-0x9c80(%rbp)
jge    136f <main+0x1ff>
movl   $0x0,-0x9c84(%rbp)
mov    -0x9c80(%rbp),%esi
add    $0x1,%esi
movslq -0x9c80(%rbp),%rax
mov    -0x9c70(%rbp,%rax,4),%edx
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x9c80(%rbp),%rax
mov    -0x9c70(%rbp,%rax,4),%edi
lea    -0x9c50(%rbp),%rsi
lea    -0x9c50(%rbp),%rdx
add    $0x9c3c,%rdx
lea    -0x9c84(%rbp),%rcx
call   1080 <find@plt>
mov    %rax,-0x9c90(%rbp)
cmpq   $0x0,-0x9c90(%rbp)
je     131d <main+0x1ad>
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x9c84(%rbp),%esi
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x9c90(%rbp),%rsi
lea    -0x9c50(%rbp),%rax
sub    %rax,%rsi
sar    $0x2,%rsi
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    133f <main+0x1cf>
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x9c84(%rbp),%esi
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x9c84(%rbp),%eax
add    -0x9c74(%rbp),%eax
mov    %eax,-0x9c74(%rbp)
mov    -0x9c80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c80(%rbp)
jmp    1253 <main+0xe3>
cvtsi2sdl -0x9c74(%rbp),%xmm0
ff
movsd  0xc81(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xd39(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x9c90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x9c78,%rsp
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10a0 <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,0x30(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x2710,%rbx
jne    11b0 <main+0x30>
lea    0x9c6c(%rsp),%rsi
lea    0x30(%rsp),%rdi
call   1060 <sort@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
movslq %eax,%r12
imul   $0x68db8bad,%r12,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2d,%rax
add    %ecx,%eax
imul   $0x4e20,%eax,%eax
sub    %eax,%r12d
mov    %r12d,0x10(%rsp)
xor    %eax,%eax
call   10a0 <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,0x14(%rsp)
xor    %eax,%eax
call   10a0 <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,0x18(%rsp)
xor    %eax,%eax
call   10a0 <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,0x1c(%rsp)
xor    %eax,%eax
call   10a0 <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,0x20(%rsp)
mov    $0x1,%ebx
lea    0xc(%rsp),%r15
lea    0xd52(%rip),%r14
xor    %r13d,%r13d
nopl   0x0(%rax)
movl   $0x0,0xc(%rsp)
lea    0xd19(%rip),%rdi
mov    %ebx,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12d,%edi
lea    0x30(%rsp),%r12
mov    %r12,%rsi
lea    0x9c6c(%rsp),%rdx
mov    %r15,%rcx
call   1090 <find@plt>
test   %rax,%rax
je     1360 <main+0x1e0>
mov    %rax,%rbp
lea    0xda7(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
sub    %r12,%rbp
sar    $0x2,%rbp
lea    0xcf7(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    137a <main+0x1fa>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xd37(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    0xc(%rsp),%r13d
cmp    $0x5,%rbx
je     139d <main+0x21d>
mov    0x10(%rsp,%rbx,4),%r12d
add    $0x1,%rbx
jmp    12e0 <main+0x160>
cvtsi2sd %r13d,%xmm0
divsd  0xc56(%rip),%xmm0
lea    0xcbd(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x9c78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"%d\E5\9B\9E\E7\9B\AE: %d\E3\82\92\E6\8E\A2\E7\B4\A2\E3\81\97\E3\81\BE\E3\81\99\E3\80\82\0A\00"
@.str.1 = [38 x i8] c"\E3\83\87\E3\83\BC\E3\82\BF\E3\81\8C\E8\A6\8B\E3\81\A4\E3\81\8B\E3\82\8A\E3\81\BE\E3\81\97\E3\81\9F\E3\80\82\0A\00"
@.str.2 = [18 x i8] c"\E6\8E\A2\E7\B4\A2\E5\9B\9E\E6\95\B0: %d\0A\00"
@.str.3 = [49 x i8] c"\E6\8E\A2\E7\B4\A2\E3\83\87\E3\83\BC\E3\82\BF\E3\81\AE\E3\81\82\E3\81\A3\E3\81\9F\E3\83\87\E3\83\BC\E3\82\BF\E7\95\AA\E5\8F\B7: %td\0A\00"
@.str.4 = [47 x i8] c"\E3\83\87\E3\83\BC\E3\82\BF\E3\81\8C\E8\A6\8B\E3\81\A4\E3\81\8B\E3\82\8A\E3\81\BE\E3\81\9B\E3\82\93\E3\81\A7\E3\81\97\E3\81\9F\E3\80\82\0A\00"
@.str.5 = [48 x i8] c"\E6\8E\A2\E7\B4\A2\E3\81\8C\E7\B5\82\E4\BA\86\E3\81\99\E3\82\8B\E3\81\BE\E3\81\A7\E3\81\AE\E5\B9\B3\E5\9D\87\E5\9B\9E\E6\95\B0: %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10000 x i32]
%3 = alloca [5 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %4
%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
%26 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 0
%27 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 9999
%28 = call i32 @sort(i32* %26, i32* %27)
store i32 0, i32* %6
br label %29
29: ; preds = %38, %25
%30 = load i32, i32* %6
%31 = icmp slt i32 %30, 5
br i1 %31, label %32, label %41
32: ; preds = %29
%33 = call i32 (...) @rand()
%34 = srem i32 %33, 20000
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 %36
store i32 %34, i32* %37
br label %38
38: ; preds = %32
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %29
41: ; preds = %29
store i32 0, i32* %7
br label %42
42: ; preds = %82, %41
%43 = load i32, i32* %7
%44 = icmp slt i32 %43, 5
br i1 %44, label %45, label %85
45: ; preds = %42
store i32 0, i32* %8
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
%48 = load i32, i32* %7
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 %49
%51 = load i32, i32* %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %47, i32 %51)
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 %54
%56 = load i32, i32* %55
%57 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 0
%58 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 9999
%59 = call i32* @find(i32 %56, i32* %57, i32* %58, i32* %8)
store i32* %59, i32** %9
%60 = load i32*, i32** %9
%61 = icmp ne i32* %60, null
br i1 %61, label %62, label %73
62: ; preds = %45
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%64 = load i32, i32* %8
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %64)
%66 = load i32*, i32** %9
%67 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 0
%68 = ptrtoint i32* %66 to i64
%69 = ptrtoint i32* %67 to i64
%70 = sub i64 %68, %69
%71 = sdiv exact i64 %70, 4
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i64 %71)
br label %77
73: ; preds = %45
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
%75 = load i32, i32* %8
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %75)
br label %77
77: ; preds = %73, %62
%78 = call i32 @putchar(i8 signext 10)
%79 = load i32, i32* %8
%80 = load i32, i32* %4
%81 = add nsw i32 %80, %79
store i32 %81, i32* %4
br label %82
82: ; preds = %77
%83 = load i32, i32* %7
%84 = add nsw i32 %83, 1
store i32 %84, i32* %7
br label %42
85: ; preds = %42
%86 = load i32, i32* %4
%87 = sitofp i32 %86 to double
%88 = fdiv double %87, 5.000000e+00
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), double %88)
ret i32 0
}

LLVM IR (-O2):
@.str = [35 x i8] c"%d\E5\9B\9E\E7\9B\AE: %d\E3\82\92\E6\8E\A2\E7\B4\A2\E3\81\97\E3\81\BE\E3\81\99\E3\80\82\0A\00"
@.str.2 = [18 x i8] c"\E6\8E\A2\E7\B4\A2\E5\9B\9E\E6\95\B0: %d\0A\00"
@.str.3 = [49 x i8] c"\E6\8E\A2\E7\B4\A2\E3\83\87\E3\83\BC\E3\82\BF\E3\81\AE\E3\81\82\E3\81\A3\E3\81\9F\E3\83\87\E3\83\BC\E3\82\BF\E7\95\AA\E5\8F\B7: %td\0A\00"
@.str.5 = [48 x i8] c"\E6\8E\A2\E7\B4\A2\E3\81\8C\E7\B5\82\E4\BA\86\E3\81\99\E3\82\8B\E3\81\BE\E3\81\A7\E3\81\AE\E5\B9\B3\E5\9D\87\E5\9B\9E\E6\95\B0: %f\0A\00"
@str = [46 x i8] c"\E3\83\87\E3\83\BC\E3\82\BF\E3\81\8C\E8\A6\8B\E3\81\A4\E3\81\8B\E3\82\8A\E3\81\BE\E3\81\9B\E3\82\93\E3\81\A7\E3\81\97\E3\81\9F\E3\80\82\00"
@str.6 = [37 x i8] c"\E3\83\87\E3\83\BC\E3\82\BF\E3\81\8C\E8\A6\8B\E3\81\A4\E3\81\8B\E3\82\8A\E3\81\BE\E3\81\97\E3\81\9F\E3\80\82\00"
define i32 @main() {
%1 = alloca [10000 x i32]
%2 = alloca [5 x i32]
%3 = alloca i32
%4 = bitcast [10000 x i32]* %1 to i8*
%5 = bitcast [5 x i32]* %2 to i8*
%6 = tail call i64 @time(i32* null)
%7 = trunc i64 %6 to i32
%8 = tail call i32 @srand(i32 %7)
br label %30
9: ; preds = %30
%10 = getelementptr inbounds [10000 x i32], [10000 x i32]* %1, i64 0, i64 0
%11 = getelementptr inbounds [10000 x i32], [10000 x i32]* %1, i64 0, i64 9999
%12 = call i32 @sort(i32* %10, i32* %11)
%13 = call i32 (...) @rand()
%14 = srem i32 %13, 20000
%15 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
store i32 %14, i32* %15
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 20000
%18 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 1
store i32 %17, i32* %18
%19 = call i32 (...) @rand()
%20 = srem i32 %19, 20000
%21 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 2
store i32 %20, i32* %21
%22 = call i32 (...) @rand()
%23 = srem i32 %22, 20000
%24 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 3
store i32 %23, i32* %24
%25 = call i32 (...) @rand()
%26 = srem i32 %25, 20000
%27 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 4
store i32 %26, i32* %27
%28 = bitcast i32* %3 to i8*
%29 = ptrtoint [10000 x i32]* %1 to i64
br label %41
30: ; preds = %0, %30
%31 = phi i64 [ 0, %0 ], [ %35, %30 ]
%32 = tail call i32 (...) @rand()
%33 = srem i32 %32, 20000
%34 = getelementptr inbounds [10000 x i32], [10000 x i32]* %1, i64 0, i64 %31
store i32 %33, i32* %34
%35 = add nuw nsw i64 %31, 1
%36 = icmp eq i64 %35, 10000
br i1 %36, label %9, label %30
37: ; preds = %62
%38 = sitofp i32 %65 to double
%39 = fdiv double %38, 5.000000e+00
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), double %39)
ret i32 0
41: ; preds = %67, %9
%42 = phi i32 [ %14, %9 ], [ %69, %67 ]
%43 = phi i64 [ 0, %9 ], [ %45, %67 ]
%44 = phi i32 [ 0, %9 ], [ %65, %67 ]
store i32 0, i32* %3
%45 = add nuw nsw i64 %43, 1
%46 = trunc i64 %45 to i32
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %46, i32 %42)
%48 = call i32* @find(i32 %42, i32* %10, i32* %11, i32* %3)
%49 = icmp eq i32* %48, null
br i1 %49, label %58, label %50
50: ; preds = %41
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.6, i64 0, i64 0))
%52 = load i32, i32* %3
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %52)
%54 = ptrtoint i32* %48 to i64
%55 = sub i64 %54, %29
%56 = ashr exact i64 %55, 2
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i64 %56)
br label %62
58: ; preds = %41
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%60 = load i32, i32* %3
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %60)
br label %62
62: ; preds = %58, %50
%63 = call i32 @putchar(i8 signext 10)
%64 = load i32, i32* %3
%65 = add nsw i32 %64, %44
%66 = icmp eq i64 %45, 5
br i1 %66, label %37, label %67
67: ; preds = %62
%68 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 %45
%69 = load i32, i32* %68
br label %41
}