#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 */
scalar_t__ calloc(int, int);
unsigned int get_random_value(int, unsigned int);
int *reservoir_sample(int *population) {
  unsigned int i, j;
  int *sample = (int *)calloc(100, sizeof(int));
  for (i = 0; i < 100; i++) {
    sample[i] = population[i];
  }
  for (i = 100 + 1; i < 2000; i++) {
    j = get_random_value(1, i + 1);
    if (j <= 100) {
      sample[j] = population[i];
    }
  }
  return sample;
}


x86 assembly (clang, -O0):
<reservoir_sample>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x64,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x64,-0xc(%rbp)
jae    1172 <reservoir_sample+0x52>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    (%rax,%rcx,4),%edx
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1146 <reservoir_sample+0x26>
movl   $0x65,-0xc(%rbp)
cmpl   $0x7d0,-0xc(%rbp)
jae    11ca <reservoir_sample+0xaa>
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    $0x1,%edi
call   1040 <get_random_value@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x64,-0x10(%rbp)
ja     11b7 <reservoir_sample+0x97>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    (%rax,%rcx,4),%edx
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
jmp    11bc <reservoir_sample+0x9c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1179 <reservoir_sample+0x59>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reservoir_sample>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x64,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,%r15
lea    0x190(%r14),%rax
cmp    %rax,%r15
jae    119f <reservoir_sample+0x7f>
mov    %r15,%rax
add    $0x190,%rax
cmp    %r14,%rax
jbe    119f <reservoir_sample+0x7f>
mov    $0x4,%eax
nopl   0x0(%rax)
mov    -0x10(%r14,%rax,4),%ecx
mov    %ecx,-0x10(%r15,%rax,4)
mov    -0xc(%r14,%rax,4),%ecx
mov    %ecx,-0xc(%r15,%rax,4)
mov    -0x8(%r14,%rax,4),%ecx
mov    %ecx,-0x8(%r15,%rax,4)
mov    -0x4(%r14,%rax,4),%ecx
mov    %ecx,-0x4(%r15,%rax,4)
mov    (%r14,%rax,4),%ecx
mov    %ecx,(%r15,%rax,4)
add    $0x5,%rax
cmp    $0x68,%rax
jne    1160 <reservoir_sample+0x40>
jmp    12fd <reservoir_sample+0x1dd>
movups (%r14),%xmm0
movups %xmm0,(%r15)
movups 0x10(%r14),%xmm0
movups %xmm0,0x10(%r15)
movups 0x20(%r14),%xmm0
movups %xmm0,0x20(%r15)
movups 0x30(%r14),%xmm0
movups %xmm0,0x30(%r15)
movups 0x40(%r14),%xmm0
movups %xmm0,0x40(%r15)
movups 0x50(%r14),%xmm0
movups %xmm0,0x50(%r15)
movups 0x60(%r14),%xmm0
movups %xmm0,0x60(%r15)
movups 0x70(%r14),%xmm0
movups %xmm0,0x70(%r15)
movups 0x80(%r14),%xmm0
movups %xmm0,0x80(%r15)
movups 0x90(%r14),%xmm0
movups %xmm0,0x90(%r15)
movups 0xa0(%r14),%xmm0
movups %xmm0,0xa0(%r15)
movups 0xb0(%r14),%xmm0
movups %xmm0,0xb0(%r15)
movups 0xc0(%r14),%xmm0
movups %xmm0,0xc0(%r15)
movups 0xd0(%r14),%xmm0
movups %xmm0,0xd0(%r15)
movups 0xe0(%r14),%xmm0
movups %xmm0,0xe0(%r15)
movups 0xf0(%r14),%xmm0
movups %xmm0,0xf0(%r15)
movups 0x100(%r14),%xmm0
movups %xmm0,0x100(%r15)
movups 0x110(%r14),%xmm0
movups %xmm0,0x110(%r15)
movups 0x120(%r14),%xmm0
movups %xmm0,0x120(%r15)
movups 0x130(%r14),%xmm0
movups %xmm0,0x130(%r15)
movups 0x140(%r14),%xmm0
movups %xmm0,0x140(%r15)
movups 0x150(%r14),%xmm0
movups %xmm0,0x150(%r15)
movups 0x160(%r14),%xmm0
movups %xmm0,0x160(%r15)
movups 0x170(%r14),%xmm0
movups %xmm0,0x170(%r15)
movups 0x180(%r14),%xmm0
movups %xmm0,0x180(%r15)
mov    $0x65,%ebx
jmp    131c <reservoir_sample+0x1fc>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rbx
cmp    $0x7d0,%r12
je     133e <reservoir_sample+0x21e>
lea    0x1(%rbx),%r12
mov    $0x1,%edi
mov    %r12d,%esi
call   1040 <get_random_value@plt>
cmp    $0x64,%eax
ja     1310 <reservoir_sample+0x1f0>
mov    (%r14,%rbx,4),%ecx
mov    %eax,%eax
mov    %ecx,(%r15,%rax,4)
jmp    1310 <reservoir_sample+0x1f0>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @reservoir_sample(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store i32* %0, i32** %2
%6 = call i64 @calloc(i32 100, i32 4)
%7 = inttoptr i64 %6 to i32*
store i32* %7, i32** %5
store i32 0, i32* %3
br label %8
8: ; preds = %21, %1
%9 = load i32, i32* %3
%10 = icmp ult i32 %9, 100
br i1 %10, label %11, label %24
11: ; preds = %8
%12 = load i32*, i32** %2
%13 = load i32, i32* %3
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
%16 = load i32, i32* %15
%17 = load i32*, i32** %5
%18 = load i32, i32* %3
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
store i32 %16, i32* %20
br label %21
21: ; preds = %11
%22 = load i32, i32* %3
%23 = add i32 %22, 1
store i32 %23, i32* %3
br label %8
24: ; preds = %8
store i32 101, i32* %3
br label %25
25: ; preds = %45, %24
%26 = load i32, i32* %3
%27 = icmp ult i32 %26, 2000
br i1 %27, label %28, label %48
28: ; preds = %25
%29 = load i32, i32* %3
%30 = add i32 %29, 1
%31 = call i32 @get_random_value(i32 1, i32 %30)
store i32 %31, i32* %4
%32 = load i32, i32* %4
%33 = icmp ule i32 %32, 100
br i1 %33, label %34, label %44
34: ; preds = %28
%35 = load i32*, i32** %2
%36 = load i32, i32* %3
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = load i32, i32* %38
%40 = load i32*, i32** %5
%41 = load i32, i32* %4
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
store i32 %39, i32* %43
br label %44
44: ; preds = %34, %28
br label %45
45: ; preds = %44
%46 = load i32, i32* %3
%47 = add i32 %46, 1
store i32 %47, i32* %3
br label %25
48: ; preds = %25
%49 = load i32*, i32** %5
ret i32* %49
}

LLVM IR (-O2):
define i32* @reservoir_sample(i32* nocapture %0) {
%2 = tail call i64 @calloc(i32 100, i32 4)
%3 = inttoptr i64 %2 to i32*
%4 = inttoptr i64 %2 to i8*
%5 = getelementptr i32, i32* %3, i64 100
%6 = getelementptr i32, i32* %0, i64 100
%7 = bitcast i32* %6 to i8*
%8 = icmp ult i8* %4, %7
%9 = icmp ugt i32* %5, %0
%10 = and i1 %8, %9
br i1 %10, label %135, label %11
11: ; preds = %1
%12 = bitcast i32* %0 to <4 x i32>*
%13 = load <4 x i32>, <4 x i32>* %12
%14 = inttoptr i64 %2 to <4 x i32>*
store <4 x i32> %13, <4 x i32>* %14
%15 = getelementptr inbounds i32, i32* %0, i64 4
%16 = bitcast i32* %15 to <4 x i32>*
%17 = load <4 x i32>, <4 x i32>* %16
%18 = getelementptr inbounds i32, i32* %3, i64 4
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> %17, <4 x i32>* %19
%20 = getelementptr inbounds i32, i32* %0, i64 8
%21 = bitcast i32* %20 to <4 x i32>*
%22 = load <4 x i32>, <4 x i32>* %21
%23 = getelementptr inbounds i32, i32* %3, i64 8
%24 = bitcast i32* %23 to <4 x i32>*
store <4 x i32> %22, <4 x i32>* %24
%25 = getelementptr inbounds i32, i32* %0, i64 12
%26 = bitcast i32* %25 to <4 x i32>*
%27 = load <4 x i32>, <4 x i32>* %26
%28 = getelementptr inbounds i32, i32* %3, i64 12
%29 = bitcast i32* %28 to <4 x i32>*
store <4 x i32> %27, <4 x i32>* %29
%30 = getelementptr inbounds i32, i32* %0, i64 16
%31 = bitcast i32* %30 to <4 x i32>*
%32 = load <4 x i32>, <4 x i32>* %31
%33 = getelementptr inbounds i32, i32* %3, i64 16
%34 = bitcast i32* %33 to <4 x i32>*
store <4 x i32> %32, <4 x i32>* %34
%35 = getelementptr inbounds i32, i32* %0, i64 20
%36 = bitcast i32* %35 to <4 x i32>*
%37 = load <4 x i32>, <4 x i32>* %36
%38 = getelementptr inbounds i32, i32* %3, i64 20
%39 = bitcast i32* %38 to <4 x i32>*
store <4 x i32> %37, <4 x i32>* %39
%40 = getelementptr inbounds i32, i32* %0, i64 24
%41 = bitcast i32* %40 to <4 x i32>*
%42 = load <4 x i32>, <4 x i32>* %41
%43 = getelementptr inbounds i32, i32* %3, i64 24
%44 = bitcast i32* %43 to <4 x i32>*
store <4 x i32> %42, <4 x i32>* %44
%45 = getelementptr inbounds i32, i32* %0, i64 28
%46 = bitcast i32* %45 to <4 x i32>*
%47 = load <4 x i32>, <4 x i32>* %46
%48 = getelementptr inbounds i32, i32* %3, i64 28
%49 = bitcast i32* %48 to <4 x i32>*
store <4 x i32> %47, <4 x i32>* %49
%50 = getelementptr inbounds i32, i32* %0, i64 32
%51 = bitcast i32* %50 to <4 x i32>*
%52 = load <4 x i32>, <4 x i32>* %51
%53 = getelementptr inbounds i32, i32* %3, i64 32
%54 = bitcast i32* %53 to <4 x i32>*
store <4 x i32> %52, <4 x i32>* %54
%55 = getelementptr inbounds i32, i32* %0, i64 36
%56 = bitcast i32* %55 to <4 x i32>*
%57 = load <4 x i32>, <4 x i32>* %56
%58 = getelementptr inbounds i32, i32* %3, i64 36
%59 = bitcast i32* %58 to <4 x i32>*
store <4 x i32> %57, <4 x i32>* %59
%60 = getelementptr inbounds i32, i32* %0, i64 40
%61 = bitcast i32* %60 to <4 x i32>*
%62 = load <4 x i32>, <4 x i32>* %61
%63 = getelementptr inbounds i32, i32* %3, i64 40
%64 = bitcast i32* %63 to <4 x i32>*
store <4 x i32> %62, <4 x i32>* %64
%65 = getelementptr inbounds i32, i32* %0, i64 44
%66 = bitcast i32* %65 to <4 x i32>*
%67 = load <4 x i32>, <4 x i32>* %66
%68 = getelementptr inbounds i32, i32* %3, i64 44
%69 = bitcast i32* %68 to <4 x i32>*
store <4 x i32> %67, <4 x i32>* %69
%70 = getelementptr inbounds i32, i32* %0, i64 48
%71 = bitcast i32* %70 to <4 x i32>*
%72 = load <4 x i32>, <4 x i32>* %71
%73 = getelementptr inbounds i32, i32* %3, i64 48
%74 = bitcast i32* %73 to <4 x i32>*
store <4 x i32> %72, <4 x i32>* %74
%75 = getelementptr inbounds i32, i32* %0, i64 52
%76 = bitcast i32* %75 to <4 x i32>*
%77 = load <4 x i32>, <4 x i32>* %76
%78 = getelementptr inbounds i32, i32* %3, i64 52
%79 = bitcast i32* %78 to <4 x i32>*
store <4 x i32> %77, <4 x i32>* %79
%80 = getelementptr inbounds i32, i32* %0, i64 56
%81 = bitcast i32* %80 to <4 x i32>*
%82 = load <4 x i32>, <4 x i32>* %81
%83 = getelementptr inbounds i32, i32* %3, i64 56
%84 = bitcast i32* %83 to <4 x i32>*
store <4 x i32> %82, <4 x i32>* %84
%85 = getelementptr inbounds i32, i32* %0, i64 60
%86 = bitcast i32* %85 to <4 x i32>*
%87 = load <4 x i32>, <4 x i32>* %86
%88 = getelementptr inbounds i32, i32* %3, i64 60
%89 = bitcast i32* %88 to <4 x i32>*
store <4 x i32> %87, <4 x i32>* %89
%90 = getelementptr inbounds i32, i32* %0, i64 64
%91 = bitcast i32* %90 to <4 x i32>*
%92 = load <4 x i32>, <4 x i32>* %91
%93 = getelementptr inbounds i32, i32* %3, i64 64
%94 = bitcast i32* %93 to <4 x i32>*
store <4 x i32> %92, <4 x i32>* %94
%95 = getelementptr inbounds i32, i32* %0, i64 68
%96 = bitcast i32* %95 to <4 x i32>*
%97 = load <4 x i32>, <4 x i32>* %96
%98 = getelementptr inbounds i32, i32* %3, i64 68
%99 = bitcast i32* %98 to <4 x i32>*
store <4 x i32> %97, <4 x i32>* %99
%100 = getelementptr inbounds i32, i32* %0, i64 72
%101 = bitcast i32* %100 to <4 x i32>*
%102 = load <4 x i32>, <4 x i32>* %101
%103 = getelementptr inbounds i32, i32* %3, i64 72
%104 = bitcast i32* %103 to <4 x i32>*
store <4 x i32> %102, <4 x i32>* %104
%105 = getelementptr inbounds i32, i32* %0, i64 76
%106 = bitcast i32* %105 to <4 x i32>*
%107 = load <4 x i32>, <4 x i32>* %106
%108 = getelementptr inbounds i32, i32* %3, i64 76
%109 = bitcast i32* %108 to <4 x i32>*
store <4 x i32> %107, <4 x i32>* %109
%110 = getelementptr inbounds i32, i32* %0, i64 80
%111 = bitcast i32* %110 to <4 x i32>*
%112 = load <4 x i32>, <4 x i32>* %111
%113 = getelementptr inbounds i32, i32* %3, i64 80
%114 = bitcast i32* %113 to <4 x i32>*
store <4 x i32> %112, <4 x i32>* %114
%115 = getelementptr inbounds i32, i32* %0, i64 84
%116 = bitcast i32* %115 to <4 x i32>*
%117 = load <4 x i32>, <4 x i32>* %116
%118 = getelementptr inbounds i32, i32* %3, i64 84
%119 = bitcast i32* %118 to <4 x i32>*
store <4 x i32> %117, <4 x i32>* %119
%120 = getelementptr inbounds i32, i32* %0, i64 88
%121 = bitcast i32* %120 to <4 x i32>*
%122 = load <4 x i32>, <4 x i32>* %121
%123 = getelementptr inbounds i32, i32* %3, i64 88
%124 = bitcast i32* %123 to <4 x i32>*
store <4 x i32> %122, <4 x i32>* %124
%125 = getelementptr inbounds i32, i32* %0, i64 92
%126 = bitcast i32* %125 to <4 x i32>*
%127 = load <4 x i32>, <4 x i32>* %126
%128 = getelementptr inbounds i32, i32* %3, i64 92
%129 = bitcast i32* %128 to <4 x i32>*
store <4 x i32> %127, <4 x i32>* %129
%130 = getelementptr inbounds i32, i32* %0, i64 96
%131 = bitcast i32* %130 to <4 x i32>*
%132 = load <4 x i32>, <4 x i32>* %131
%133 = getelementptr inbounds i32, i32* %3, i64 96
%134 = bitcast i32* %133 to <4 x i32>*
store <4 x i32> %132, <4 x i32>* %134
br label %158
135: ; preds = %1, %135
%136 = phi i64 [ %156, %135 ], [ 0, %1 ]
%137 = getelementptr inbounds i32, i32* %0, i64 %136
%138 = load i32, i32* %137
%139 = getelementptr inbounds i32, i32* %3, i64 %136
store i32 %138, i32* %139
%140 = add nuw nsw i64 %136, 1
%141 = getelementptr inbounds i32, i32* %0, i64 %140
%142 = load i32, i32* %141
%143 = getelementptr inbounds i32, i32* %3, i64 %140
store i32 %142, i32* %143
%144 = add nuw nsw i64 %136, 2
%145 = getelementptr inbounds i32, i32* %0, i64 %144
%146 = load i32, i32* %145
%147 = getelementptr inbounds i32, i32* %3, i64 %144
store i32 %146, i32* %147
%148 = add nuw nsw i64 %136, 3
%149 = getelementptr inbounds i32, i32* %0, i64 %148
%150 = load i32, i32* %149
%151 = getelementptr inbounds i32, i32* %3, i64 %148
store i32 %150, i32* %151
%152 = add nuw nsw i64 %136, 4
%153 = getelementptr inbounds i32, i32* %0, i64 %152
%154 = load i32, i32* %153
%155 = getelementptr inbounds i32, i32* %3, i64 %152
store i32 %154, i32* %155
%156 = add nuw nsw i64 %136, 5
%157 = icmp eq i64 %156, 100
br i1 %157, label %158, label %135
158: ; preds = %135, %11
br label %159
159: ; preds = %158, %170
%160 = phi i64 [ %161, %170 ], [ 101, %158 ]
%161 = add nuw nsw i64 %160, 1
%162 = trunc i64 %161 to i32
%163 = tail call i32 @get_random_value(i32 1, i32 %162)
%164 = icmp ult i32 %163, 101
br i1 %164, label %165, label %170
165: ; preds = %159
%166 = getelementptr inbounds i32, i32* %0, i64 %160
%167 = load i32, i32* %166
%168 = zext i32 %163 to i64
%169 = getelementptr inbounds i32, i32* %3, i64 %168
store i32 %167, i32* %169
br label %170
170: ; preds = %159, %165
%171 = icmp eq i64 %161, 2000
br i1 %171, label %172, label %159
172: ; preds = %170
ret i32* %3
}