int treedir(double *bb, double *x) {
  int d = 0;
  if (x[0] > (bb[0] + bb[3]) / 2.0)
    d += 1;
  if (x[1] > (bb[1] + bb[4]) / 2.0)
    d += 2;
  if (x[2] > (bb[2] + bb[5]) / 2.0)
    d += 4;
  return d;
}


x86 assembly (clang, -O0):
<treedir>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x8(%rbp),%rax
addsd  0x18(%rax),%xmm1
movsd  0xecc(%rip),%xmm2
divsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jbe    114b <treedir+0x4b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x8(%rbp),%rax
addsd  0x20(%rax),%xmm1
movsd  0xe92(%rip),%xmm2
divsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jbe    1185 <treedir+0x85>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm1
mov    -0x8(%rbp),%rax
addsd  0x28(%rax),%xmm1
movsd  0xe58(%rip),%xmm2
divsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jbe    11bf <treedir+0xbf>
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<treedir>:
movsd  (%rdi),%xmm0
addsd  0x18(%rdi),%xmm0
movsd  (%rsi),%xmm1
mulsd  0xeeb(%rip),%xmm0
xor    %eax,%eax
ucomisd %xmm0,%xmm1
seta   %al
lea    0x2(%rax),%ecx
movupd 0x8(%rsi),%xmm0
movupd 0x8(%rdi),%xmm1
movupd 0x20(%rdi),%xmm2
addpd  %xmm1,%xmm2
mulpd  0xed4(%rip),%xmm2
cmpltpd %xmm0,%xmm2
movmskpd %xmm2,%edx
test   $0x1,%dl
cmove  %eax,%ecx
lea    0x4(%rcx),%eax
test   $0x2,%dl
cmove  %ecx,%eax
ret

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

LLVM IR (-O2):
define i32 @treedir(double* nocapture %0, double* nocapture %1) {
%3 = load double, double* %1
%4 = load double, double* %0
%5 = getelementptr inbounds double, double* %0, i64 3
%6 = load double, double* %5
%7 = fadd double %4, %6
%8 = fmul double %7, 5.000000e-01
%9 = fcmp ogt double %3, %8
%10 = zext i1 %9 to i32
%11 = getelementptr inbounds double, double* %1, i64 1
%12 = getelementptr inbounds double, double* %0, i64 1
%13 = getelementptr inbounds double, double* %0, i64 4
%14 = or i32 %10, 2
%15 = bitcast double* %11 to <2 x double>*
%16 = load <2 x double>, <2 x double>* %15
%17 = bitcast double* %12 to <2 x double>*
%18 = load <2 x double>, <2 x double>* %17
%19 = bitcast double* %13 to <2 x double>*
%20 = load <2 x double>, <2 x double>* %19
%21 = fadd <2 x double> %18, %20
%22 = fmul <2 x double> %21, <double 5.000000e-01, double 5.000000e-01>
%23 = fcmp ogt <2 x double> %16, %22
%24 = extractelement <2 x i1> %23, i64 0
%25 = select i1 %24, i32 %14, i32 %10
%26 = or i32 %25, 4
%27 = extractelement <2 x i1> %23, i64 1
%28 = select i1 %27, i32 %26, i32 %25
ret i32 %28
}