#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 */
double get_dp(double const, double const);
double get_dA(const double *xp, const double *xm, int dim) {
  double r = .5 * (xp[0] + xm[0]);
  double dr = xp[0] - xm[0];
  double dphi = get_dp(xp[1], xm[1]);
  double dz = xp[2] - xm[2];
  if (dim == 0)
    return dr * dz;
  else if (dim == 1)
    return r * dphi * dz;
  else
    return r * dr * dphi;
}


x86 assembly (clang, -O0):
<get_dA>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x18(%rbp),%rax
addsd  (%rax),%xmm1
movsd  0xec5(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm1
call   1030 <get_dp@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11aa <get_dA+0x9a>
movsd  -0x30(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e1 <get_dA+0xd1>
cmpl   $0x1,-0x1c(%rbp)
jne    11cd <get_dA+0xbd>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e1 <get_dA+0xd1>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dA>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
movsd  (%rdi),%xmm2
movsd  0x8(%rdi),%xmm0
movsd  (%rsi),%xmm3
movsd  0x8(%rsi),%xmm1
movsd  %xmm2,0x18(%rsp)
movsd  %xmm3,0x10(%rsp)
addsd  %xmm3,%xmm2
mulsd  0xeb5(%rip),%xmm2
movsd  %xmm2,0x8(%rsp)
call   1030 <get_dp@plt>
movsd  0x10(%rbp),%xmm1
subsd  0x10(%rbx),%xmm1
cmp    $0x1,%r14d
je     117d <get_dA+0x6d>
movsd  0x18(%rsp),%xmm2
subsd  0x10(%rsp),%xmm2
test   %r14d,%r14d
jne    118d <get_dA+0x7d>
mulsd  %xmm1,%xmm2
jmp    1197 <get_dA+0x87>
movsd  0x8(%rsp),%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm1,%xmm2
jmp    1197 <get_dA+0x87>
mulsd  0x8(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @get_dA(double* %0, double* %1, i32 %2) {
%4 = alloca double
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store i32 %2, i32* %7
%12 = load double*, double** %5
%13 = getelementptr inbounds double, double* %12, i64 0
%14 = load double, double* %13
%15 = load double*, double** %6
%16 = getelementptr inbounds double, double* %15, i64 0
%17 = load double, double* %16
%18 = fadd double %14, %17
%19 = fmul double 5.000000e-01, %18
store double %19, double* %8
%20 = load double*, double** %5
%21 = getelementptr inbounds double, double* %20, i64 0
%22 = load double, double* %21
%23 = load double*, double** %6
%24 = getelementptr inbounds double, double* %23, i64 0
%25 = load double, double* %24
%26 = fsub double %22, %25
store double %26, double* %9
%27 = load double*, double** %5
%28 = getelementptr inbounds double, double* %27, i64 1
%29 = load double, double* %28
%30 = load double*, double** %6
%31 = getelementptr inbounds double, double* %30, i64 1
%32 = load double, double* %31
%33 = call double @get_dp(double %29, double %32)
store double %33, double* %10
%34 = load double*, double** %5
%35 = getelementptr inbounds double, double* %34, i64 2
%36 = load double, double* %35
%37 = load double*, double** %6
%38 = getelementptr inbounds double, double* %37, i64 2
%39 = load double, double* %38
%40 = fsub double %36, %39
store double %40, double* %11
%41 = load i32, i32* %7
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %3
%44 = load double, double* %9
%45 = load double, double* %11
%46 = fmul double %44, %45
store double %46, double* %4
br label %62
47: ; preds = %3
%48 = load i32, i32* %7
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %56
50: ; preds = %47
%51 = load double, double* %8
%52 = load double, double* %10
%53 = fmul double %51, %52
%54 = load double, double* %11
%55 = fmul double %53, %54
store double %55, double* %4
br label %62
56: ; preds = %47
%57 = load double, double* %8
%58 = load double, double* %9
%59 = fmul double %57, %58
%60 = load double, double* %10
%61 = fmul double %59, %60
store double %61, double* %4
br label %62
62: ; preds = %56, %50, %43
%63 = load double, double* %4
ret double %63
}

LLVM IR (-O2):
define double @get_dA(double* nocapture %0, double* nocapture %1, i32 %2) {
%4 = load double, double* %0
%5 = load double, double* %1
%6 = fadd double %4, %5
%7 = fmul double %6, 5.000000e-01
%8 = fsub double %4, %5
%9 = getelementptr inbounds double, double* %0, i64 1
%10 = load double, double* %9
%11 = getelementptr inbounds double, double* %1, i64 1
%12 = load double, double* %11
%13 = tail call double @get_dp(double %10, double %12)
%14 = getelementptr inbounds double, double* %0, i64 2
%15 = load double, double* %14
%16 = getelementptr inbounds double, double* %1, i64 2
%17 = load double, double* %16
%18 = fsub double %15, %17
switch i32 %2, label %24 [
i32 0, label %19
i32 1, label %21
]
19: ; preds = %3
%20 = fmul double %8, %18
br label %27
21: ; preds = %3
%22 = fmul double %7, %13
%23 = fmul double %22, %18
br label %27
24: ; preds = %3
%25 = fmul double %8, %7
%26 = fmul double %25, %13
br label %27
27: ; preds = %24, %21, %19
%28 = phi double [ %20, %19 ], [ %23, %21 ], [ %26, %24 ]
ret double %28
}