#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) {
  if (dim == 0) {
    double dy = get_dp(xp[1], xm[1]);
    return dy;
  } 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)
cmpl   $0x0,-0x1c(%rbp)
jne    1158 <get_dL+0x48>
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm1
call   1030 <get_dp@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1193 <get_dL+0x83>
cmpl   $0x1,-0x1c(%rbp)
jne    117c <get_dL+0x6c>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1193 <get_dL+0x83>
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>:
cmp    $0x1,%edx
je     1128 <get_dL+0x18>
test   %edx,%edx
jne    1131 <get_dL+0x21>
movsd  0x8(%rdi),%xmm0
movsd  0x8(%rsi),%xmm1
jmp    1030 <get_dp@plt>
movsd  (%rdi),%xmm0
subsd  (%rsi),%xmm0
ret
movsd  0x10(%rdi),%xmm0
subsd  0x10(%rsi),%xmm0
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
store double* %0, double** %5
store double* %1, double** %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %3
%12 = load double*, double** %5
%13 = getelementptr inbounds double, double* %12, i64 1
%14 = load double, double* %13
%15 = load double*, double** %6
%16 = getelementptr inbounds double, double* %15, i64 1
%17 = load double, double* %16
%18 = call double @get_dp(double %14, double %17)
store double %18, double* %8
%19 = load double, double* %8
store double %19, double* %4
br label %39
20: ; preds = %3
%21 = load i32, i32* %7
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load double*, double** %5
%25 = getelementptr inbounds double, double* %24, i64 0
%26 = load double, double* %25
%27 = load double*, double** %6
%28 = getelementptr inbounds double, double* %27, i64 0
%29 = load double, double* %28
%30 = fsub double %26, %29
store double %30, double* %4
br label %39
31: ; preds = %20
%32 = load double*, double** %5
%33 = getelementptr inbounds double, double* %32, i64 2
%34 = load double, double* %33
%35 = load double*, double** %6
%36 = getelementptr inbounds double, double* %35, i64 2
%37 = load double, double* %36
%38 = fsub double %34, %37
store double %38, double* %4
br label %39
39: ; preds = %31, %23, %11
%40 = load double, double* %4
ret double %40
}

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