#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 */
scalar_t__ fabs(double);
int find_min_proj(double z[3]) {
  int i_min = 0;
  for (int i = 1; i < 3; i++) {
    if (fabs(z[i]) < fabs(z[i_min])) {
      i_min = i;
    }
  }
  return i_min;
}


x86 assembly (clang, -O0):
<find_min_proj>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
cmpl   $0x3,-0x10(%rbp)
jge    1185 <find_min_proj+0x75>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <fabs@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <fabs@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
cmp    %rcx,%rax
jge    1172 <find_min_proj+0x62>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1177 <find_min_proj+0x67>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112a <find_min_proj+0x1a>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_min_proj>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
movsd  0x8(%rdi),%xmm0
call   1030 <fabs@plt>
mov    %rax,%r14
movsd  (%r15),%xmm0
call   1030 <fabs@plt>
xor    %ebx,%ebx
cmp    %rax,%r14
setl   %bl
movsd  0x10(%r15),%xmm0
call   1030 <fabs@plt>
mov    %rax,%r14
movsd  (%r15,%rbx,8),%xmm0
call   1030 <fabs@plt>
cmp    %rax,%r14
mov    $0x2,%eax
cmovge %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @find_min_proj(double* %0) {
%2 = alloca double*
%3 = alloca i32
%4 = alloca i32
store double* %0, double** %2
store i32 0, i32* %3
store i32 1, i32* %4
br label %5
5: ; preds = %25, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 3
br i1 %7, label %8, label %28
8: ; preds = %5
%9 = load double*, double** %2
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds double, double* %9, i64 %11
%13 = load double, double* %12
%14 = call i64 @fabs(double %13)
%15 = load double*, double** %2
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %15, i64 %17
%19 = load double, double* %18
%20 = call i64 @fabs(double %19)
%21 = icmp slt i64 %14, %20
br i1 %21, label %22, label %24
22: ; preds = %8
%23 = load i32, i32* %4
store i32 %23, i32* %3
br label %24
24: ; preds = %22, %8
br label %25
25: ; preds = %24
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %5
28: ; preds = %5
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @find_min_proj(double* nocapture %0) {
%2 = getelementptr inbounds double, double* %0, i64 1
%3 = load double, double* %2
%4 = tail call i64 @fabs(double %3)
%5 = load double, double* %0
%6 = tail call i64 @fabs(double %5)
%7 = icmp slt i64 %4, %6
%8 = zext i1 %7 to i32
%9 = getelementptr inbounds double, double* %0, i64 2
%10 = load double, double* %9
%11 = tail call i64 @fabs(double %10)
%12 = zext i1 %7 to i64
%13 = getelementptr inbounds double, double* %0, i64 %12
%14 = load double, double* %13
%15 = tail call i64 @fabs(double %14)
%16 = icmp slt i64 %11, %15
%17 = select i1 %16, i32 2, i32 %8
ret i32 %17
}