#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 /*<<< orphan*/ memcpy(double *, double *, unsigned int);
void loadSample(double *u, int *samidx, unsigned sample_size,
                unsigned data_size, double *u_out) {
  unsigned i;
  for (i = 0; i < sample_size; ++i) {
    memcpy(u_out + data_size * i, u + data_size * samidx[i],
           data_size * sizeof(double));
  }
}


x86 assembly (clang, -O0):
<loadSample>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1188 <loadSample+0x78>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%eax
imul   -0x24(%rbp),%eax
mov    %eax,%eax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    -0x24(%rbp),%edx
imul   (%rcx,%rdx,4),%eax
mov    %eax,%eax
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x18(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edx
call   1030 <memcpy@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1131 <loadSample+0x21>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadSample>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edx,%edx
je     1181 <loadSample+0x71>
mov    %r8,%r12
mov    %ecx,%ebx
mov    %rsi,%r13
mov    %rdi,%rbp
lea    0x0(,%rbx,8),%eax
mov    %eax,0xc(%rsp)
mov    %edx,%eax
mov    %rax,0x10(%rsp)
xor    %r14d,%r14d
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14d,%eax
lea    (%r12,%rax,8),%rdi
mov    0x0(%r13,%r15,4),%eax
imul   %ebx,%eax
lea    0x0(,%rax,8),%rsi
add    %rbp,%rsi
mov    0xc(%rsp),%edx
call   1030 <memcpy@plt>
add    $0x1,%r15
add    %ebx,%r14d
cmp    %r15,0x10(%rsp)
jne    1150 <loadSample+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @loadSample(double* %0, i32* %1, i32 %2, i32 %3, double* %4) {
%6 = alloca double*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
%11 = alloca i32
store double* %0, double** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store double* %4, double** %10
store i32 0, i32* %11
br label %12
12: ; preds = %38, %5
%13 = load i32, i32* %11
%14 = load i32, i32* %8
%15 = icmp ult i32 %13, %14
br i1 %15, label %16, label %41
16: ; preds = %12
%17 = load double*, double** %10
%18 = load i32, i32* %9
%19 = load i32, i32* %11
%20 = mul i32 %18, %19
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds double, double* %17, i64 %21
%23 = load double*, double** %6
%24 = load i32, i32* %9
%25 = load i32*, i32** %7
%26 = load i32, i32* %11
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = load i32, i32* %28
%30 = mul i32 %24, %29
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds double, double* %23, i64 %31
%33 = load i32, i32* %9
%34 = zext i32 %33 to i64
%35 = mul i64 %34, 8
%36 = trunc i64 %35 to i32
%37 = call i32 @memcpy(double* %22, double* %32, i32 %36)
br label %38
38: ; preds = %16
%39 = load i32, i32* %11
%40 = add i32 %39, 1
store i32 %40, i32* %11
br label %12
41: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @loadSample(double* %0, i32* nocapture %1, i32 %2, i32 %3, double* %4) {
%6 = icmp eq i32 %2, 0
br i1 %6, label %24, label %7
7: ; preds = %5
%8 = shl i32 %3, 3
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %7, %10
%11 = phi i64 [ 0, %7 ], [ %22, %10 ]
%12 = trunc i64 %11 to i32
%13 = mul i32 %12, %3
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds double, double* %4, i64 %14
%16 = getelementptr inbounds i32, i32* %1, i64 %11
%17 = load i32, i32* %16
%18 = mul i32 %17, %3
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds double, double* %0, i64 %19
%21 = tail call i32 @memcpy(double* %15, double* %20, i32 %8)
%22 = add nuw nsw i64 %11, 1
%23 = icmp eq i64 %22, %9
br i1 %23, label %24, label %10
24: ; preds = %10, %5
ret void
}