int treedir(double *bb, double *x) {
  int d = 0;
  if (x[0] > (bb[0] + bb[2]) / 2.0)
    d += 1;
  if (x[1] > (bb[1] + bb[3]) / 2.0)
    d += 2;
  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  0x10(%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  0x18(%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    -0x14(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<treedir>:
movupd (%rdi),%xmm0
movupd 0x10(%rdi),%xmm1
addpd  %xmm0,%xmm1
mulpd  0xeeb(%rip),%xmm1
movupd (%rsi),%xmm0
cmpltpd %xmm0,%xmm1
movmskpd %xmm1,%ecx
mov    %ecx,%edx
and    $0x1,%edx
lea    0x2(%rdx),%eax
test   $0x2,%cl
cmove  %edx,%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 2
%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 3
%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 i32, i32* %5
ret i32 %38
}

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