unsigned geom_imax4d(const double v[4]) {
  unsigned i = 0;
  if (v[1] > v[i]) {
    i = 1;
  }
  if (v[2] > v[i]) {
    i = 2;
  }
  if (v[3] > v[i]) {
    i = 3;
  }
  return i;
}


x86 assembly (clang, -O0):
<geom_imax4d>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
ucomisd (%rax,%rcx,8),%xmm0
jbe    1131 <geom_imax4d+0x31>
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
ucomisd (%rax,%rcx,8),%xmm0
jbe    1153 <geom_imax4d+0x53>
movl   $0x2,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
ucomisd (%rax,%rcx,8),%xmm0
jbe    1175 <geom_imax4d+0x75>
movl   $0x3,-0xc(%rbp)
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<geom_imax4d>:
movsd  0x8(%rdi),%xmm0
xor    %eax,%eax
ucomisd (%rdi),%xmm0
seta   %al
movsd  0x10(%rdi),%xmm0
ucomisd (%rdi,%rax,8),%xmm0
mov    $0x2,%ecx
cmovbe %eax,%ecx
movsd  0x18(%rdi),%xmm0
ucomisd (%rdi,%rcx,8),%xmm0
mov    $0x3,%eax
cmovbe %ecx,%eax
ret

LLVM IR (-O0):
define i32 @geom_imax4d(double* %0) {
%2 = alloca double*
%3 = alloca i32
store double* %0, double** %2
store i32 0, i32* %3
%4 = load double*, double** %2
%5 = getelementptr inbounds double, double* %4, i64 1
%6 = load double, double* %5
%7 = load double*, double** %2
%8 = load i32, i32* %3
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds double, double* %7, i64 %9
%11 = load double, double* %10
%12 = fcmp ogt double %6, %11
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 1, i32* %3
br label %14
14: ; preds = %13, %1
%15 = load double*, double** %2
%16 = getelementptr inbounds double, double* %15, i64 2
%17 = load double, double* %16
%18 = load double*, double** %2
%19 = load i32, i32* %3
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
%23 = fcmp ogt double %17, %22
br i1 %23, label %24, label %25
24: ; preds = %14
store i32 2, i32* %3
br label %25
25: ; preds = %24, %14
%26 = load double*, double** %2
%27 = getelementptr inbounds double, double* %26, i64 3
%28 = load double, double* %27
%29 = load double*, double** %2
%30 = load i32, i32* %3
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
%33 = load double, double* %32
%34 = fcmp ogt double %28, %33
br i1 %34, label %35, label %36
35: ; preds = %25
store i32 3, i32* %3
br label %36
36: ; preds = %35, %25
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
define i32 @geom_imax4d(double* nocapture %0) {
%2 = getelementptr inbounds double, double* %0, i64 1
%3 = load double, double* %2
%4 = load double, double* %0
%5 = fcmp ogt double %3, %4
%6 = zext i1 %5 to i32
%7 = getelementptr inbounds double, double* %0, i64 2
%8 = load double, double* %7
%9 = zext i1 %5 to i64
%10 = getelementptr inbounds double, double* %0, i64 %9
%11 = load double, double* %10
%12 = fcmp ogt double %8, %11
%13 = select i1 %12, i32 2, i32 %6
%14 = getelementptr inbounds double, double* %0, i64 3
%15 = load double, double* %14
%16 = zext i32 %13 to i64
%17 = getelementptr inbounds double, double* %0, i64 %16
%18 = load double, double* %17
%19 = fcmp ogt double %15, %18
%20 = select i1 %19, i32 3, i32 %13
ret i32 %20
}