#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 */
typedef size_t uint32_t;

/* Variables and functions */
void scatter_body(double *A, double *B, uint32_t *index, uint32_t n,
                  uint32_t *stack_array) {
  uint32_t i;
  for (i = 0; i < n; i++) {
    A[index[i]] = B[i];
    stack_array[i % 0x1000] = i;
  }
}


x86 assembly (clang, -O0):
<scatter_body>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1178 <scatter_body+0x78>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x30(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
and    $0xfff,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1120 <scatter_body+0x20>
pop    %rbp
ret

x86 assembly (clang, -O2):
<scatter_body>:
test   %rcx,%rcx
je     11a0 <scatter_body+0xa0>
cmp    $0x1,%rcx
jne    111c <scatter_body+0x1c>
xor    %r10d,%r10d
test   $0x1,%cl
jne    1185 <scatter_body+0x85>
jmp    11a0 <scatter_body+0xa0>
mov    %rcx,%r9
and    $0xfffffffffffffffe,%r9
mov    $0x1,%r10d
nopl   0x0(%rax)
mov    %r10,%r11
add    $0xffffffffffffffff,%r10
movsd  -0x8(%rsi,%r11,8),%xmm0
mov    -0x8(%rdx,%r11,8),%rax
movsd  %xmm0,(%rdi,%rax,8)
mov    %r10d,%eax
and    $0xffe,%eax
mov    %r10,(%r8,%rax,8)
movsd  (%rsi,%r11,8),%xmm0
mov    (%rdx,%r11,8),%rax
movsd  %xmm0,(%rdi,%rax,8)
mov    %r11d,%eax
and    $0xfff,%eax
mov    %r11,(%r8,%rax,8)
lea    0x2(%r11),%r10
add    $0x1,%r11
cmp    %r9,%r11
jne    1130 <scatter_body+0x30>
add    $0xffffffffffffffff,%r10
test   $0x1,%cl
je     11a0 <scatter_body+0xa0>
movsd  (%rsi,%r10,8),%xmm0
mov    (%rdx,%r10,8),%rax
movsd  %xmm0,(%rdi,%rax,8)
mov    %r10d,%eax
and    $0xfff,%eax
mov    %r10,(%r8,%rax,8)
ret

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

LLVM IR (-O2):
define void @scatter_body(double* nocapture writeonly %0, double* nocapture %1, i64* nocapture %2, i64 %3, i64* nocapture writeonly %4) {
%6 = icmp eq i64 %3, 0
br i1 %6, label %44, label %7
7: ; preds = %5
%8 = and i64 %3, 1
%9 = icmp eq i64 %3, 1
br i1 %9, label %33, label %10
10: ; preds = %7
%11 = and i64 %3, -2
br label %12
12: ; preds = %12, %10
%13 = phi i64 [ 0, %10 ], [ %30, %12 ]
%14 = phi i64 [ 0, %10 ], [ %31, %12 ]
%15 = getelementptr inbounds double, double* %1, i64 %13
%16 = load double, double* %15
%17 = getelementptr inbounds i64, i64* %2, i64 %13
%18 = load i64, i64* %17
%19 = getelementptr inbounds double, double* %0, i64 %18
store double %16, double* %19
%20 = and i64 %13, 4094
%21 = getelementptr inbounds i64, i64* %4, i64 %20
store i64 %13, i64* %21
%22 = or i64 %13, 1
%23 = getelementptr inbounds double, double* %1, i64 %22
%24 = load double, double* %23
%25 = getelementptr inbounds i64, i64* %2, i64 %22
%26 = load i64, i64* %25
%27 = getelementptr inbounds double, double* %0, i64 %26
store double %24, double* %27
%28 = and i64 %22, 4095
%29 = getelementptr inbounds i64, i64* %4, i64 %28
store i64 %22, i64* %29
%30 = add nuw i64 %13, 2
%31 = add i64 %14, 2
%32 = icmp eq i64 %31, %11
br i1 %32, label %33, label %12
33: ; preds = %12, %7
%34 = phi i64 [ 0, %7 ], [ %30, %12 ]
%35 = icmp eq i64 %8, 0
br i1 %35, label %44, label %36
36: ; preds = %33
%37 = getelementptr inbounds double, double* %1, i64 %34
%38 = load double, double* %37
%39 = getelementptr inbounds i64, i64* %2, i64 %34
%40 = load i64, i64* %39
%41 = getelementptr inbounds double, double* %0, i64 %40
store double %38, double* %41
%42 = and i64 %34, 4095
%43 = getelementptr inbounds i64, i64* %4, i64 %42
store i64 %34, i64* %43
br label %44
44: ; preds = %36, %33, %5
ret void
}