#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 sample(int *, int, int);
void rsample(double *data, int dat_siz, int *pool, int size, int max_sz,
             double *dst) {
  double *src, *p;
  int i, j, q;
  for (i = 0; i < size; i++) {
    q = sample(pool, max_sz, i);
    src = data + q;
    p = dst + i;
    for (j = 0; j < dat_siz; j++) {
      *p = *src;
      p += size;
      src += max_sz;
    }
  }
}


x86 assembly (clang, -O0):
<rsample>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e7 <rsample+0xd7>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x3c(%rbp),%edx
call   1030 <sample@plt>
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d4 <rsample+0xc4>
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1180 <rsample+0x70>
jmp    11d9 <rsample+0xc9>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1135 <rsample+0x25>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rsample>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9,0x18(%rsp)
mov    %r8d,0xc(%rsp)
mov    %rdx,0x40(%rsp)
mov    %rsi,0x20(%rsp)
mov    %rdi,0x38(%rsp)
test   %ecx,%ecx
jle    12c8 <rsample+0x1b8>
mov    %ecx,%eax
movslq 0xc(%rsp),%r12
mov    0x20(%rsp),%rcx
lea    -0x1(%rcx),%edx
mov    %edx,0x14(%rsp)
mov    %ecx,%r15d
and    $0x7,%r15d
and    $0xfffffff8,%ecx
mov    %ecx,0x10(%rsp)
mov    %r12,%rcx
shl    $0x6,%rcx
mov    %rcx,0x30(%rsp)
mov    %rax,%rcx
shl    $0x6,%rcx
mov    %rcx,0x28(%rsp)
shl    $0x3,%r12
mov    %rax,%rbx
lea    0x0(,%rax,8),%r13
xor    %ebp,%ebp
mov    0x18(%rsp),%r14
jmp    11a1 <rsample+0x91>
add    $0x1,%rbp
add    $0x8,%r14
cmp    %rbx,%rbp
je     12c8 <rsample+0x1b8>
mov    0x40(%rsp),%rdi
mov    0xc(%rsp),%esi
mov    %ebp,%edx
call   1030 <sample@plt>
cmpl   $0x0,0x20(%rsp)
jle    1190 <rsample+0x80>
cltq
mov    0x38(%rsp),%rcx
lea    (%rcx,%rax,8),%rcx
cmpl   $0x7,0x14(%rsp)
jae    11e0 <rsample+0xd0>
mov    0x18(%rsp),%rax
lea    (%rax,%rbp,8),%rax
test   %r15d,%r15d
jne    12a7 <rsample+0x197>
jmp    1190 <rsample+0x80>
xchg   %ax,%ax
mov    0x10(%rsp),%esi
mov    %r14,%rdi
nopw   0x0(%rax,%rax,1)
mov    %rcx,%rdx
mov    %rdi,%rax
movsd  (%rcx),%xmm0
movsd  %xmm0,(%rdi)
add    %r12,%rcx
movsd  (%rdx,%r12,1),%xmm0
add    %r13,%rdi
movsd  %xmm0,(%rax,%r13,1)
movsd  (%r12,%rcx,1),%xmm0
add    %r12,%rcx
movsd  %xmm0,0x0(%r13,%rdi,1)
add    %r13,%rdi
movsd  (%r12,%rcx,1),%xmm0
add    %r12,%rcx
movsd  %xmm0,0x0(%r13,%rdi,1)
add    %r13,%rdi
movsd  (%r12,%rcx,1),%xmm0
add    %r12,%rcx
movsd  %xmm0,0x0(%r13,%rdi,1)
add    %r13,%rdi
movsd  (%r12,%rcx,1),%xmm0
add    %r12,%rcx
movsd  %xmm0,0x0(%r13,%rdi,1)
add    %r13,%rdi
movsd  (%r12,%rcx,1),%xmm0
add    %r12,%rcx
movsd  %xmm0,0x0(%r13,%rdi,1)
add    %r13,%rdi
movsd  (%r12,%rcx,1),%xmm0
add    %r12,%rcx
movsd  %xmm0,0x0(%r13,%rdi,1)
add    %r13,%rdi
add    %r12,%rcx
add    %r13,%rdi
add    $0xfffffff8,%esi
jne    11f0 <rsample+0xe0>
add    0x30(%rsp),%rdx
add    0x28(%rsp),%rax
mov    %rdx,%rcx
test   %r15d,%r15d
je     1190 <rsample+0x80>
mov    %r15d,%edx
nopw   0x0(%rax,%rax,1)
movsd  (%rcx),%xmm0
movsd  %xmm0,(%rax)
add    %r12,%rcx
add    %r13,%rax
add    $0xffffffff,%edx
jne    12b0 <rsample+0x1a0>
jmp    1190 <rsample+0x80>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @rsample(double* %0, i32 %1, i32* %2, i32 %3, i32 %4, double* %5) {
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca double*
%13 = alloca double*
%14 = alloca double*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store double* %0, double** %7
store i32 %1, i32* %8
store i32* %2, i32** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store double* %5, double** %12
store i32 0, i32* %15
br label %18
18: ; preds = %55, %6
%19 = load i32, i32* %15
%20 = load i32, i32* %10
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %58
22: ; preds = %18
%23 = load i32*, i32** %9
%24 = load i32, i32* %11
%25 = load i32, i32* %15
%26 = call i32 @sample(i32* %23, i32 %24, i32 %25)
store i32 %26, i32* %17
%27 = load double*, double** %7
%28 = load i32, i32* %17
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
store double* %30, double** %13
%31 = load double*, double** %12
%32 = load i32, i32* %15
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
store double* %34, double** %14
store i32 0, i32* %16
br label %35
35: ; preds = %51, %22
%36 = load i32, i32* %16
%37 = load i32, i32* %8
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %54
39: ; preds = %35
%40 = load double*, double** %13
%41 = load double, double* %40
%42 = load double*, double** %14
store double %41, double* %42
%43 = load i32, i32* %10
%44 = load double*, double** %14
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds double, double* %44, i64 %45
store double* %46, double** %14
%47 = load i32, i32* %11
%48 = load double*, double** %13
%49 = sext i32 %47 to i64
%50 = getelementptr inbounds double, double* %48, i64 %49
store double* %50, double** %13
br label %51
51: ; preds = %39
%52 = load i32, i32* %16
%53 = add nsw i32 %52, 1
store i32 %53, i32* %16
br label %35
54: ; preds = %35
br label %55
55: ; preds = %54
%56 = load i32, i32* %15
%57 = add nsw i32 %56, 1
store i32 %57, i32* %15
br label %18
58: ; preds = %18
ret void
}

LLVM IR (-O2):
define void @rsample(double* nocapture %0, i32 %1, i32* %2, i32 %3, i32 %4, double* nocapture writeonly %5) {
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %71
8: ; preds = %6
%9 = icmp sgt i32 %1, 0
%10 = zext i32 %3 to i64
%11 = sext i32 %4 to i64
%12 = zext i32 %3 to i64
%13 = add i32 %1, -1
%14 = and i32 %1, 7
%15 = icmp ult i32 %13, 7
%16 = and i32 %1, -8
%17 = icmp eq i32 %14, 0
br label %18
18: ; preds = %8, %68
%19 = phi i64 [ 0, %8 ], [ %69, %68 ]
%20 = trunc i64 %19 to i32
%21 = tail call i32 @sample(i32* %2, i32 %4, i32 %20)
br i1 %9, label %22, label %68
22: ; preds = %18
%23 = getelementptr inbounds double, double* %5, i64 %19
%24 = sext i32 %21 to i64
%25 = getelementptr inbounds double, double* %0, i64 %24
br i1 %15, label %56, label %26
26: ; preds = %22, %26
%27 = phi double* [ %53, %26 ], [ %25, %22 ]
%28 = phi double* [ %52, %26 ], [ %23, %22 ]
%29 = phi i32 [ %54, %26 ], [ 0, %22 ]
%30 = load double, double* %27
store double %30, double* %28
%31 = getelementptr inbounds double, double* %28, i64 %10
%32 = getelementptr inbounds double, double* %27, i64 %11
%33 = load double, double* %32
store double %33, double* %31
%34 = getelementptr inbounds double, double* %31, i64 %10
%35 = getelementptr inbounds double, double* %32, i64 %11
%36 = load double, double* %35
store double %36, double* %34
%37 = getelementptr inbounds double, double* %34, i64 %10
%38 = getelementptr inbounds double, double* %35, i64 %11
%39 = load double, double* %38
store double %39, double* %37
%40 = getelementptr inbounds double, double* %37, i64 %10
%41 = getelementptr inbounds double, double* %38, i64 %11
%42 = load double, double* %41
store double %42, double* %40
%43 = getelementptr inbounds double, double* %40, i64 %10
%44 = getelementptr inbounds double, double* %41, i64 %11
%45 = load double, double* %44
store double %45, double* %43
%46 = getelementptr inbounds double, double* %43, i64 %10
%47 = getelementptr inbounds double, double* %44, i64 %11
%48 = load double, double* %47
store double %48, double* %46
%49 = getelementptr inbounds double, double* %46, i64 %10
%50 = getelementptr inbounds double, double* %47, i64 %11
%51 = load double, double* %50
store double %51, double* %49
%52 = getelementptr inbounds double, double* %49, i64 %10
%53 = getelementptr inbounds double, double* %50, i64 %11
%54 = add i32 %29, 8
%55 = icmp eq i32 %54, %16
br i1 %55, label %56, label %26
56: ; preds = %26, %22
%57 = phi double* [ %25, %22 ], [ %53, %26 ]
%58 = phi double* [ %23, %22 ], [ %52, %26 ]
br i1 %17, label %68, label %59
59: ; preds = %56, %59
%60 = phi double* [ %65, %59 ], [ %57, %56 ]
%61 = phi double* [ %64, %59 ], [ %58, %56 ]
%62 = phi i32 [ %66, %59 ], [ 0, %56 ]
%63 = load double, double* %60
store double %63, double* %61
%64 = getelementptr inbounds double, double* %61, i64 %10
%65 = getelementptr inbounds double, double* %60, i64 %11
%66 = add i32 %62, 1
%67 = icmp eq i32 %66, %14
br i1 %67, label %68, label %59
68: ; preds = %56, %59, %18
%69 = add nuw nsw i64 %19, 1
%70 = icmp eq i64 %69, %12
br i1 %70, label %71, label %18
71: ; preds = %68, %6
ret void
}