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


x86 assembly (clang, -O0):
<get_dL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm1
call   1030 <get_dp@plt>
movsd  %xmm0,-0x30(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    117e <get_dL+0x6e>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b9 <get_dL+0xa9>
cmpl   $0x1,-0x1c(%rbp)
jne    11a2 <get_dL+0x92>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b9 <get_dL+0xa9>
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dL>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
movsd  (%rdi),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rdi),%xmm0
movsd  (%rsi),%xmm1
movsd  %xmm1,(%rsp)
movsd  0x8(%rsi),%xmm1
call   1030 <get_dp@plt>
cmp    $0x1,%ebp
je     1164 <get_dL+0x54>
test   %ebp,%ebp
jne    116f <get_dL+0x5f>
movsd  0x8(%rsp),%xmm1
addsd  (%rsp),%xmm1
mulsd  0xea2(%rip),%xmm1
mulsd  %xmm0,%xmm1
jmp    117a <get_dL+0x6a>
movsd  (%rbx),%xmm1
subsd  (%r14),%xmm1
jmp    117a <get_dL+0x6a>
movsd  0x10(%rbx),%xmm1
subsd  0x10(%r14),%xmm1
movapd %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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