#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 */
typedef size_t int8_t;

/* Variables and functions */
double get_cube_offset_double(int8_t dim, double *point_coord, double *bbox) {
  double dim_coord = point_coord[dim];
  if (dim_coord < bbox[2 * dim]) {
    return dim_coord - bbox[2 * dim];
  } else if (dim_coord > bbox[2 * dim + 1]) {
    return dim_coord - bbox[2 * dim + 1];
  } else {
    return 0.;
  }
}


x86 assembly (clang, -O0):
<get_cube_offset_double>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
shl    $0x1,%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    1162 <get_cube_offset_double+0x62>
movsd  -0x28(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
shl    $0x1,%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11a8 <get_cube_offset_double+0xa8>
movsd  -0x28(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
shl    $0x1,%rcx
ucomisd 0x8(%rax,%rcx,8),%xmm0
jbe    11a0 <get_cube_offset_double+0xa0>
movsd  -0x28(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
shl    $0x1,%rcx
subsd  0x8(%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11a8 <get_cube_offset_double+0xa8>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cube_offset_double>:
movsd  (%rsi,%rdi,8),%xmm1
mov    %rdi,%rax
shl    $0x4,%rax
movsd  (%rdx,%rax,1),%xmm0
ucomisd %xmm1,%xmm0
jbe    111d <get_cube_offset_double+0x1d>
subsd  %xmm0,%xmm1
jmp    113b <get_cube_offset_double+0x3b>
add    %rdi,%rdi
shl    $0x3,%rdi
or     $0x8,%rdi
movsd  (%rdx,%rdi,1),%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm1
jbe    113f <get_cube_offset_double+0x3f>
subsd  %xmm2,%xmm1
movapd %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @get_cube_offset_double(i64 %0, double* %1, double* %2) {
%4 = alloca double
%5 = alloca i64
%6 = alloca double*
%7 = alloca double*
%8 = alloca double
store i64 %0, i64* %5
store double* %1, double** %6
store double* %2, double** %7
%9 = load double*, double** %6
%10 = load i64, i64* %5
%11 = getelementptr inbounds double, double* %9, i64 %10
%12 = load double, double* %11
store double %12, double* %8
%13 = load double, double* %8
%14 = load double*, double** %7
%15 = load i64, i64* %5
%16 = mul i64 2, %15
%17 = getelementptr inbounds double, double* %14, i64 %16
%18 = load double, double* %17
%19 = fcmp olt double %13, %18
br i1 %19, label %20, label %28
20: ; preds = %3
%21 = load double, double* %8
%22 = load double*, double** %7
%23 = load i64, i64* %5
%24 = mul i64 2, %23
%25 = getelementptr inbounds double, double* %22, i64 %24
%26 = load double, double* %25
%27 = fsub double %21, %26
store double %27, double* %4
br label %47
28: ; preds = %3
%29 = load double, double* %8
%30 = load double*, double** %7
%31 = load i64, i64* %5
%32 = mul i64 2, %31
%33 = add i64 %32, 1
%34 = getelementptr inbounds double, double* %30, i64 %33
%35 = load double, double* %34
%36 = fcmp ogt double %29, %35
br i1 %36, label %37, label %46
37: ; preds = %28
%38 = load double, double* %8
%39 = load double*, double** %7
%40 = load i64, i64* %5
%41 = mul i64 2, %40
%42 = add i64 %41, 1
%43 = getelementptr inbounds double, double* %39, i64 %42
%44 = load double, double* %43
%45 = fsub double %38, %44
store double %45, double* %4
br label %47
46: ; preds = %28
store double 0.000000e+00, double* %4
br label %47
47: ; preds = %46, %37, %20
%48 = load double, double* %4
ret double %48
}

LLVM IR (-O2):
define double @get_cube_offset_double(i64 %0, double* nocapture %1, double* nocapture %2) {
%4 = getelementptr inbounds double, double* %1, i64 %0
%5 = load double, double* %4
%6 = shl i64 %0, 1
%7 = getelementptr inbounds double, double* %2, i64 %6
%8 = load double, double* %7
%9 = fcmp olt double %5, %8
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = fsub double %5, %8
br label %19
12: ; preds = %3
%13 = or i64 %6, 1
%14 = getelementptr inbounds double, double* %2, i64 %13
%15 = load double, double* %14
%16 = fcmp ogt double %5, %15
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = fsub double %5, %15
br label %19
19: ; preds = %12, %17, %10
%20 = phi double [ %11, %10 ], [ %18, %17 ], [ 0.000000e+00, %12 ]
ret double %20
}