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


x86 assembly (clang, -O0):
<rsampleTn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11d7 <rsampleTn+0xc7>
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)
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c4 <rsampleTn+0xb4>
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x38(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x38(%rbp)
mov    -0x24(%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    1179 <rsampleTn+0x69>
jmp    11c9 <rsampleTn+0xb9>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1141 <rsampleTn+0x31>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rsampleTn>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,0xc(%rsp)
mov    %rdx,0x20(%rsp)
mov    %rdi,0x18(%rsp)
test   %ecx,%ecx
jle    127b <rsampleTn+0x16b>
mov    %ecx,%r13d
mov    %esi,%ebx
mov    0x60(%rsp),%r12
movslq %r9d,%r14
lea    -0x1(%rbx),%eax
mov    %eax,0x8(%rsp)
mov    %esi,%r15d
and    $0x7,%r15d
mov    %esi,%eax
and    $0xfffffff8,%eax
mov    %eax,0x4(%rsp)
mov    %r14,%rax
shl    $0x6,%rax
mov    %rax,0x10(%rsp)
shl    $0x3,%r14
xor    %ebp,%ebp
jmp    117c <rsampleTn+0x6c>
nopl   (%rax)
add    $0x1,%ebp
cmp    %r13d,%ebp
je     127b <rsampleTn+0x16b>
mov    0x20(%rsp),%rdi
mov    0xc(%rsp),%esi
mov    %ebp,%edx
call   1030 <sample@plt>
test   %ebx,%ebx
jle    1170 <rsampleTn+0x60>
cltq
mov    0x18(%rsp),%rcx
lea    (%rcx,%rax,8),%rax
cmpl   $0x7,0x8(%rsp)
jb     1245 <rsampleTn+0x135>
mov    0x4(%rsp),%edx
nopw   0x0(%rax,%rax,1)
mov    %rax,%rcx
movsd  (%rax),%xmm0
movsd  %xmm0,(%r12)
add    %r14,%rax
movsd  (%rcx,%r14,1),%xmm0
movsd  %xmm0,0x8(%r12)
movsd  (%r14,%rax,1),%xmm0
add    %r14,%rax
movsd  %xmm0,0x10(%r12)
movsd  (%r14,%rax,1),%xmm0
add    %r14,%rax
movsd  %xmm0,0x18(%r12)
movsd  (%r14,%rax,1),%xmm0
add    %r14,%rax
movsd  %xmm0,0x20(%r12)
movsd  (%r14,%rax,1),%xmm0
add    %r14,%rax
movsd  %xmm0,0x28(%r12)
movsd  (%r14,%rax,1),%xmm0
add    %r14,%rax
movsd  %xmm0,0x30(%r12)
movsd  (%r14,%rax,1),%xmm0
add    %r14,%rax
movsd  %xmm0,0x38(%r12)
add    $0x40,%r12
add    %r14,%rax
add    $0xfffffff8,%edx
jne    11b0 <rsampleTn+0xa0>
add    0x10(%rsp),%rcx
mov    %rcx,%rax
test   %r15d,%r15d
je     1170 <rsampleTn+0x60>
mov    %r15d,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rax),%xmm0
movsd  %xmm0,(%r12)
add    $0x8,%r12
add    %r14,%rax
add    $0xffffffff,%ecx
jne    1260 <rsampleTn+0x150>
jmp    1170 <rsampleTn+0x60>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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