#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 */
struct cept {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ add_function(struct cept *, char *);
int /*<<< orphan*/ add_message(struct cept *, char *);
int /*<<< orphan*/ add_source(struct cept *, char *);
struct cept *new_cept(int, int, int);
double quad_angle(double *, double *, double *, double *);
int first_and_third(double v1[3], double v2[3], double v3[3], double v4[3]) {
  double min_ang;
  double angles[4];
  int i, min_v;
  struct cept *ex;
  angles[0] = quad_angle(v1, v2, v3, v4);
  angles[1] = quad_angle(v2, v3, v4, v1);
  angles[2] = quad_angle(v3, v4, v1, v2);
  angles[3] = quad_angle(v4, v1, v2, v3);
  min_ang = 3.14159265358979323846;
  min_v = -1;
  for (i = 0; i < 4; i++)
    if (angles[i] < min_ang) {
      min_ang = angles[i];
      min_v = i;
    }
  if (min_v < 0) {
    ex = new_cept(7, 15, 1);
    add_function(ex, "first_and_third");
    add_source(ex, "msbisect.c");
    add_message(ex, "no minimum angle");
    return (0);
  }
  return ((min_v % 2) == 0);
}


x86 assembly (clang, -O0):
<first_and_third>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1030 <quad_angle@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rcx
call   1030 <quad_angle@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1030 <quad_angle@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <quad_angle@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  0xe28(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0xffffffff,-0x58(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0x4,-0x54(%rbp)
jge    1236 <first_and_third+0xe6>
movslq -0x54(%rbp),%rax
movsd  -0x50(%rbp,%rax,8),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1223 <first_and_third+0xd3>
movslq -0x54(%rbp),%rax
movsd  -0x50(%rbp,%rax,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x58(%rbp)
jmp    1228 <first_and_third+0xd8>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11eb <first_and_third+0x9b>
cmpl   $0x0,-0x58(%rbp)
jge    1294 <first_and_third+0x144>
mov    $0x7,%edi
mov    $0xf,%esi
mov    $0x1,%edx
call   1040 <new_cept@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rdi
lea    0xda5(%rip),%rsi
call   1060 <add_function@plt>
mov    -0x60(%rbp),%rdi
lea    0xda5(%rip),%rsi
call   1050 <add_source@plt>
mov    -0x60(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   1070 <add_message@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ad <first_and_third+0x15d>
mov    -0x58(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<first_and_third>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1030 <quad_angle@plt>
movsd  %xmm0,0x10(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1030 <quad_angle@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1030 <quad_angle@plt>
movsd  %xmm0,(%rsp)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <quad_angle@plt>
movsd  0xe48(%rip),%xmm1
xor    %eax,%eax
movsd  0x10(%rsp),%xmm2
ucomisd %xmm2,%xmm1
setbe  %al
minsd  %xmm1,%xmm2
neg    %eax
movsd  0x8(%rsp),%xmm1
ucomisd %xmm1,%xmm2
mov    $0x1,%ecx
cmovbe %eax,%ecx
minsd  %xmm2,%xmm1
movsd  (%rsp),%xmm2
ucomisd %xmm2,%xmm1
mov    $0x2,%edx
cmovbe %ecx,%edx
minsd  %xmm1,%xmm2
ucomisd %xmm0,%xmm2
mov    $0x3,%eax
cmovbe %edx,%eax
test   %eax,%eax
js     120f <first_and_third+0xbf>
not    %eax
and    $0x1,%eax
jmp    1255 <first_and_third+0x105>
mov    $0x7,%edi
mov    $0xf,%esi
mov    $0x1,%edx
call   1040 <new_cept@plt>
mov    %rax,%rbx
lea    0xddb(%rip),%rsi
mov    %rax,%rdi
call   1060 <add_function@plt>
lea    0xddc(%rip),%rsi
mov    %rbx,%rdi
call   1050 <add_source@plt>
lea    0xdd8(%rip),%rsi
mov    %rbx,%rdi
call   1070 <add_message@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.cept = type { i32 }
@.str = [16 x i8] c"first_and_third\00"
@.str.1 = [11 x i8] c"msbisect.c\00"
@.str.2 = [17 x i8] c"no minimum angle\00"
define i32 @first_and_third(double* %0, double* %1, double* %2, double* %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca double
%11 = alloca [4 x double]
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.cept*
store double* %0, double** %6
store double* %1, double** %7
store double* %2, double** %8
store double* %3, double** %9
%15 = load double*, double** %6
%16 = load double*, double** %7
%17 = load double*, double** %8
%18 = load double*, double** %9
%19 = call double @quad_angle(double* %15, double* %16, double* %17, double* %18)
%20 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 0
store double %19, double* %20
%21 = load double*, double** %7
%22 = load double*, double** %8
%23 = load double*, double** %9
%24 = load double*, double** %6
%25 = call double @quad_angle(double* %21, double* %22, double* %23, double* %24)
%26 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 1
store double %25, double* %26
%27 = load double*, double** %8
%28 = load double*, double** %9
%29 = load double*, double** %6
%30 = load double*, double** %7
%31 = call double @quad_angle(double* %27, double* %28, double* %29, double* %30)
%32 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 2
store double %31, double* %32
%33 = load double*, double** %9
%34 = load double*, double** %6
%35 = load double*, double** %7
%36 = load double*, double** %8
%37 = call double @quad_angle(double* %33, double* %34, double* %35, double* %36)
%38 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 3
store double %37, double* %38
store double 0x400921FB54442D18, double* %10
store i32 -1, i32* %13
store i32 0, i32* %12
br label %39
39: ; preds = %56, %4
%40 = load i32, i32* %12
%41 = icmp slt i32 %40, 4
br i1 %41, label %42, label %59
42: ; preds = %39
%43 = load i32, i32* %12
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 %44
%46 = load double, double* %45
%47 = load double, double* %10
%48 = fcmp olt double %46, %47
br i1 %48, label %49, label %55
49: ; preds = %42
%50 = load i32, i32* %12
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 %51
%53 = load double, double* %52
store double %53, double* %10
%54 = load i32, i32* %12
store i32 %54, i32* %13
br label %55
55: ; preds = %49, %42
br label %56
56: ; preds = %55
%57 = load i32, i32* %12
%58 = add nsw i32 %57, 1
store i32 %58, i32* %12
br label %39
59: ; preds = %39
%60 = load i32, i32* %13
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %70
62: ; preds = %59
%63 = call %struct.cept* @new_cept(i32 7, i32 15, i32 1)
store %struct.cept* %63, %struct.cept** %14
%64 = load %struct.cept*, %struct.cept** %14
%65 = call i32 @add_function(%struct.cept* %64, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%66 = load %struct.cept*, %struct.cept** %14
%67 = call i32 @add_source(%struct.cept* %66, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%68 = load %struct.cept*, %struct.cept** %14
%69 = call i32 @add_message(%struct.cept* %68, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %5
br label %75
70: ; preds = %59
%71 = load i32, i32* %13
%72 = srem i32 %71, 2
%73 = icmp eq i32 %72, 0
%74 = zext i1 %73 to i32
store i32 %74, i32* %5
br label %75
75: ; preds = %70, %62
%76 = load i32, i32* %5
ret i32 %76
}

LLVM IR (-O2):
%struct.cept = type { i32 }
@.str = [16 x i8] c"first_and_third\00"
@.str.1 = [11 x i8] c"msbisect.c\00"
@.str.2 = [17 x i8] c"no minimum angle\00"
define i32 @first_and_third(double* %0, double* %1, double* %2, double* %3) {
%5 = tail call double @quad_angle(double* %0, double* %1, double* %2, double* %3)
%6 = tail call double @quad_angle(double* %1, double* %2, double* %3, double* %0)
%7 = tail call double @quad_angle(double* %2, double* %3, double* %0, double* %1)
%8 = tail call double @quad_angle(double* %3, double* %0, double* %1, double* %2)
%9 = fcmp olt double %5, 0x400921FB54442D18
%10 = select i1 %9, double %5, double 0x400921FB54442D18
%11 = xor i1 %9, true
%12 = sext i1 %11 to i32
%13 = fcmp olt double %6, %10
%14 = select i1 %13, double %6, double %10
%15 = select i1 %13, i32 1, i32 %12
%16 = fcmp olt double %7, %14
%17 = select i1 %16, double %7, double %14
%18 = select i1 %16, i32 2, i32 %15
%19 = fcmp olt double %8, %17
%20 = select i1 %19, i32 3, i32 %18
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %4
%23 = tail call %struct.cept* @new_cept(i32 7, i32 15, i32 1)
%24 = tail call i32 @add_function(%struct.cept* %23, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%25 = tail call i32 @add_source(%struct.cept* %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%26 = tail call i32 @add_message(%struct.cept* %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %30
27: ; preds = %4
%28 = and i32 %20, 1
%29 = xor i32 %28, 1
br label %30
30: ; preds = %27, %22
%31 = phi i32 [ 0, %22 ], [ %29, %27 ]
ret i32 %31
}