#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 ind(int, int);
void add_exchange(double *mag, int i, int j, double *beff) {
  int n;
  for (n = 0; n < 3; n++)
    beff[n] += 1. * (mag[n + ind(i - 1, j)] + mag[n + ind(i + 1, j)] +
                     mag[n + ind(i, j - 1)] + mag[n + ind(i, j + 1)]);
}


x86 assembly (clang, -O0):
<add_exchange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    1238 <add_exchange+0x128>
mov    -0x8(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%esi
call   1030 <ind@plt>
mov    -0x74(%rbp),%ecx
mov    %eax,%edx
mov    -0x70(%rbp),%rax
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    -0x10(%rbp),%esi
call   1030 <ind@plt>
mov    -0x64(%rbp),%ecx
movsd  -0x60(%rbp),%xmm0
mov    %eax,%edx
mov    -0x58(%rbp),%rax
add    %edx,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
sub    $0x1,%esi
call   1030 <ind@plt>
mov    -0x4c(%rbp),%ecx
movsd  -0x48(%rbp),%xmm0
mov    %eax,%edx
mov    -0x40(%rbp),%rax
add    %edx,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
add    $0x1,%esi
call   1030 <ind@plt>
mov    -0x34(%rbp),%ecx
movsd  -0x30(%rbp),%xmm0
mov    %eax,%edx
mov    -0x28(%rbp),%rax
add    %edx,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1130 <add_exchange+0x20>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_exchange>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,0x20(%rsp)
mov    %edx,%ebp
mov    %esi,%r15d
mov    %rdi,%rbx
lea    -0x1(%r15),%edi
mov    %edi,0x10(%rsp)
lea    0x1(%r15),%r13d
lea    -0x1(%rbp),%r14d
mov    %r14d,0x14(%rsp)
lea    0x1(%rbp),%r12d
mov    %r12d,0x18(%rsp)
mov    %edx,%esi
call   1030 <ind@plt>
cltq
movsd  (%rbx,%rax,8),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r13d,%edi
mov    %r13d,0x1c(%rsp)
mov    %ebp,%esi
call   1030 <ind@plt>
cltq
movsd  0x8(%rsp),%xmm0
addsd  (%rbx,%rax,8),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r15d,%edi
mov    %r14d,%esi
call   1030 <ind@plt>
cltq
movsd  0x8(%rsp),%xmm0
addsd  (%rbx,%rax,8),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r15d,%edi
mov    %r12d,%esi
call   1030 <ind@plt>
cltq
movsd  0x8(%rsp),%xmm0
addsd  (%rbx,%rax,8),%xmm0
mov    0x20(%rsp),%r14
addsd  (%r14),%xmm0
movsd  %xmm0,(%r14)
mov    0x10(%rsp),%edi
mov    %ebp,%esi
call   1030 <ind@plt>
cltq
movsd  0x8(%rbx,%rax,8),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r13d,%edi
mov    %ebp,%esi
call   1030 <ind@plt>
cltq
movsd  0x8(%rsp),%xmm0
addsd  0x8(%rbx,%rax,8),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r15d,%edi
mov    0x14(%rsp),%r12d
mov    %r12d,%esi
call   1030 <ind@plt>
cltq
movsd  0x8(%rsp),%xmm0
addsd  0x8(%rbx,%rax,8),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r15d,%edi
mov    0x18(%rsp),%r13d
mov    %r13d,%esi
call   1030 <ind@plt>
cltq
movsd  0x8(%rsp),%xmm0
addsd  0x8(%rbx,%rax,8),%xmm0
addsd  0x8(%r14),%xmm0
movsd  %xmm0,0x8(%r14)
mov    0x10(%rsp),%edi
mov    %ebp,%esi
call   1030 <ind@plt>
cltq
movsd  0x10(%rbx,%rax,8),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    0x1c(%rsp),%edi
mov    %ebp,%esi
call   1030 <ind@plt>
cltq
movsd  0x8(%rsp),%xmm0
addsd  0x10(%rbx,%rax,8),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r15d,%edi
mov    %r12d,%esi
call   1030 <ind@plt>
cltq
movsd  0x8(%rsp),%xmm0
addsd  0x10(%rbx,%rax,8),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r15d,%edi
mov    %r13d,%esi
call   1030 <ind@plt>
cltq
movsd  0x8(%rsp),%xmm0
addsd  0x10(%rbx,%rax,8),%xmm0
addsd  0x10(%r14),%xmm0
movsd  %xmm0,0x10(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @add_exchange(double* nocapture %0, i32 %1, i32 %2, double* nocapture %3) {
%5 = add nsw i32 %1, -1
%6 = add nsw i32 %1, 1
%7 = add nsw i32 %2, -1
%8 = add nsw i32 %2, 1
%9 = tail call i32 @ind(i32 %5, i32 %2)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds double, double* %0, i64 %10
%12 = load double, double* %11
%13 = tail call i32 @ind(i32 %6, i32 %2)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds double, double* %0, i64 %14
%16 = load double, double* %15
%17 = fadd double %12, %16
%18 = tail call i32 @ind(i32 %1, i32 %7)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %0, i64 %19
%21 = load double, double* %20
%22 = fadd double %17, %21
%23 = tail call i32 @ind(i32 %1, i32 %8)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %0, i64 %24
%26 = load double, double* %25
%27 = fadd double %22, %26
%28 = load double, double* %3
%29 = fadd double %27, %28
store double %29, double* %3
%30 = tail call i32 @ind(i32 %5, i32 %2)
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %0, i64 %32
%34 = load double, double* %33
%35 = tail call i32 @ind(i32 %6, i32 %2)
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %0, i64 %37
%39 = load double, double* %38
%40 = fadd double %34, %39
%41 = tail call i32 @ind(i32 %1, i32 %7)
%42 = add nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %0, i64 %43
%45 = load double, double* %44
%46 = fadd double %40, %45
%47 = tail call i32 @ind(i32 %1, i32 %8)
%48 = add nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %0, i64 %49
%51 = load double, double* %50
%52 = fadd double %46, %51
%53 = getelementptr inbounds double, double* %3, i64 1
%54 = load double, double* %53
%55 = fadd double %52, %54
store double %55, double* %53
%56 = tail call i32 @ind(i32 %5, i32 %2)
%57 = add nsw i32 %56, 2
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %0, i64 %58
%60 = load double, double* %59
%61 = tail call i32 @ind(i32 %6, i32 %2)
%62 = add nsw i32 %61, 2
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %0, i64 %63
%65 = load double, double* %64
%66 = fadd double %60, %65
%67 = tail call i32 @ind(i32 %1, i32 %7)
%68 = add nsw i32 %67, 2
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds double, double* %0, i64 %69
%71 = load double, double* %70
%72 = fadd double %66, %71
%73 = tail call i32 @ind(i32 %1, i32 %8)
%74 = add nsw i32 %73, 2
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds double, double* %0, i64 %75
%77 = load double, double* %76
%78 = fadd double %72, %77
%79 = getelementptr inbounds double, double* %3, i64 2
%80 = load double, double* %79
%81 = fadd double %78, %80
store double %81, double* %79
ret void
}