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


x86 assembly (clang, -O0):
<rsampleT>:
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)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11d3 <rsampleT+0xc3>
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    11c0 <rsampleT+0xb0>
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    -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    1175 <rsampleT+0x65>
jmp    11c5 <rsampleT+0xb5>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    113d <rsampleT+0x2d>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rsampleT>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,0x4(%rsp)
mov    %rdx,0x20(%rsp)
mov    %rdi,0x18(%rsp)
test   %ecx,%ecx
jle    1259 <rsampleT+0x149>
mov    %r9,%rbx
mov    %ecx,%r12d
mov    %esi,%ebp
movslq 0x4(%rsp),%r15
lea    -0x1(%rbp),%eax
mov    %eax,0xc(%rsp)
mov    %esi,%r14d
and    $0x7,%r14d
mov    %esi,%eax
and    $0xfffffff8,%eax
mov    %eax,0x8(%rsp)
mov    %r15,%rax
shl    $0x6,%rax
mov    %rax,0x10(%rsp)
shl    $0x3,%r15
xor    %r13d,%r13d
jmp    117d <rsampleT+0x6d>
xchg   %ax,%ax
add    $0x1,%r13d
cmp    %r12d,%r13d
je     1259 <rsampleT+0x149>
mov    0x20(%rsp),%rdi
mov    0x4(%rsp),%esi
mov    %r13d,%edx
call   1030 <sample@plt>
test   %ebp,%ebp
jle    1170 <rsampleT+0x60>
cltq
mov    0x18(%rsp),%rcx
lea    (%rcx,%rax,8),%rax
cmpl   $0x7,0xc(%rsp)
jb     1231 <rsampleT+0x121>
mov    0x8(%rsp),%edx
nopl   0x0(%rax)
mov    %rax,%rcx
movsd  (%rax),%xmm0
movsd  %xmm0,(%rbx)
add    %r15,%rax
movsd  (%rcx,%r15,1),%xmm0
movsd  %xmm0,0x8(%rbx)
movsd  (%r15,%rax,1),%xmm0
add    %r15,%rax
movsd  %xmm0,0x10(%rbx)
movsd  (%r15,%rax,1),%xmm0
add    %r15,%rax
movsd  %xmm0,0x18(%rbx)
movsd  (%r15,%rax,1),%xmm0
add    %r15,%rax
movsd  %xmm0,0x20(%rbx)
movsd  (%r15,%rax,1),%xmm0
add    %r15,%rax
movsd  %xmm0,0x28(%rbx)
movsd  (%r15,%rax,1),%xmm0
add    %r15,%rax
movsd  %xmm0,0x30(%rbx)
movsd  (%r15,%rax,1),%xmm0
add    %r15,%rax
movsd  %xmm0,0x38(%rbx)
add    $0x40,%rbx
add    %r15,%rax
add    $0xfffffff8,%edx
jne    11b0 <rsampleT+0xa0>
add    0x10(%rsp),%rcx
mov    %rcx,%rax
test   %r14d,%r14d
je     1170 <rsampleT+0x60>
mov    %r14d,%ecx
nopl   (%rax)
movsd  (%rax),%xmm0
movsd  %xmm0,(%rbx)
add    $0x8,%rbx
add    %r15,%rax
add    $0xffffffff,%ecx
jne    1240 <rsampleT+0x130>
jmp    1170 <rsampleT+0x60>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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