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


x86 assembly (clang, -O0):
<get_dL>:
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  0xeb5(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11c5 <get_dL+0xa5>
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm1
mov    -0x18(%rbp),%rax
addsd  0x10(%rax),%xmm1
movsd  0xe88(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm1
call   1040 <get_dp@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1209 <get_dL+0xe9>
cmpl   $0x1,-0x1c(%rbp)
jne    11e9 <get_dL+0xc9>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1209 <get_dL+0xe9>
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm1
mov    -0x18(%rbp),%rax
subsd  0x10(%rax),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dL>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movsd  (%rdi),%xmm1
movsd  (%rsi),%xmm0
cmp    $0x1,%edx
je     118c <get_dL+0x6c>
mov    %rsi,%r14
mov    %rdi,%rbx
addsd  %xmm0,%xmm1
mulsd  0xeba(%rip),%xmm1
test   %edx,%edx
jne    1192 <get_dL+0x72>
movsd  0x10(%rbx),%xmm0
addsd  0x10(%r14),%xmm0
mulsd  0xea3(%rip),%xmm0
movsd  %xmm1,0x10(%rsp)
call   1030 <sin@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rbx),%xmm0
movsd  0x8(%r14),%xmm1
call   1040 <get_dp@plt>
movsd  0x10(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm1
jmp    119d <get_dL+0x7d>
subsd  %xmm0,%xmm1
jmp    11a1 <get_dL+0x81>
movsd  0x10(%rbx),%xmm0
subsd  0x10(%r14),%xmm0
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
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
%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 i32, i32* %7
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %45
22: ; preds = %3
%23 = load double*, double** %5
%24 = getelementptr inbounds double, double* %23, i64 2
%25 = load double, double* %24
%26 = load double*, double** %6
%27 = getelementptr inbounds double, double* %26, i64 2
%28 = load double, double* %27
%29 = fadd double %25, %28
%30 = fmul double 5.000000e-01, %29
store double %30, double* %9
%31 = load double, double* %9
%32 = call double @sin(double %31)
store double %32, double* %10
%33 = load double*, double** %5
%34 = getelementptr inbounds double, double* %33, i64 1
%35 = load double, double* %34
%36 = load double*, double** %6
%37 = getelementptr inbounds double, double* %36, i64 1
%38 = load double, double* %37
%39 = call double @get_dp(double %35, double %38)
store double %39, double* %11
%40 = load double, double* %8
%41 = load double, double* %10
%42 = fmul double %40, %41
%43 = load double, double* %11
%44 = fmul double %42, %43
store double %44, double* %4
br label %66
45: ; preds = %3
%46 = load i32, i32* %7
%47 = icmp eq i32 %46, 1
br i1 %47, label %48, label %56
48: ; preds = %45
%49 = load double*, double** %5
%50 = getelementptr inbounds double, double* %49, i64 0
%51 = load double, double* %50
%52 = load double*, double** %6
%53 = getelementptr inbounds double, double* %52, i64 0
%54 = load double, double* %53
%55 = fsub double %51, %54
store double %55, double* %4
br label %66
56: ; preds = %45
%57 = load double, double* %8
%58 = load double*, double** %5
%59 = getelementptr inbounds double, double* %58, i64 2
%60 = load double, double* %59
%61 = load double*, double** %6
%62 = getelementptr inbounds double, double* %61, i64 2
%63 = load double, double* %62
%64 = fsub double %60, %63
%65 = fmul double %57, %64
store double %65, double* %4
br label %66
66: ; preds = %56, %48, %22
%67 = load double, double* %4
ret double %67
}

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 = fadd double %4, %5
%7 = fmul double %6, 5.000000e-01
switch i32 %2, label %25 [
i32 0, label %8
i32 1, label %23
]
8: ; preds = %3
%9 = getelementptr inbounds double, double* %0, i64 2
%10 = load double, double* %9
%11 = getelementptr inbounds double, double* %1, i64 2
%12 = load double, double* %11
%13 = fadd double %10, %12
%14 = fmul double %13, 5.000000e-01
%15 = tail call double @sin(double %14)
%16 = getelementptr inbounds double, double* %0, i64 1
%17 = load double, double* %16
%18 = getelementptr inbounds double, double* %1, i64 1
%19 = load double, double* %18
%20 = tail call double @get_dp(double %17, double %19)
%21 = fmul double %7, %15
%22 = fmul double %21, %20
br label %32
23: ; preds = %3
%24 = fsub double %4, %5
br label %32
25: ; preds = %3
%26 = getelementptr inbounds double, double* %0, i64 2
%27 = load double, double* %26
%28 = getelementptr inbounds double, double* %1, i64 2
%29 = load double, double* %28
%30 = fsub double %27, %29
%31 = fmul double %7, %30
br label %32
32: ; preds = %25, %23, %8
%33 = phi double [ %22, %8 ], [ %24, %23 ], [ %31, %25 ]
ret double %33
}