#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 */
double atof(char *);
int /*<<< orphan*/ bingham_F_lookup_3d(double *);
int /*<<< orphan*/ exit(int);
double get_time_ms();
int /*<<< orphan*/ printf(char *, ...);
void test_bingham_F_lookup_3d(int argc, char *argv[]) {
  if (argc < 4) {
    printf("usage: %s <z1> <z2> <z3>\n", argv[0]);
    exit(1);
  }
  double z1 = atof(argv[1]);
  double z2 = atof(argv[2]);
  double z3 = atof(argv[3]);
  double Z[3] = {z1, z2, z3};
  double t0 = get_time_ms();
  int i, n = 1000000;
  for (i = 0; i < n; i++)
    bingham_F_lookup_3d(Z);
  double t1 = get_time_ms();
  printf("Performed %d same F-lookups in %.0f ms\n", n, t1 - t0);
  t0 = get_time_ms();
  int j, k, m = 200;
  n = 0;
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= i; j++) {
      for (k = 1; k <= j; k++) {
        Z[0] = -i;
        Z[1] = -j;
        Z[2] = -k;
        bingham_F_lookup_3d(Z);
        n++;
      }
    }
  }
  t1 = get_time_ms();
  printf("Performed %d unique F-lookups in %.0f ms\n", n, t1 - t0);
}


x86 assembly (clang, -O0):
<test_bingham_F_lookup_3d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x4(%rbp)
jge    1188 <test_bingham_F_lookup_3d+0x38>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1060 <get_time_ms@plt>
movsd  %xmm0,-0x48(%rbp)
movl   $0xf4240,-0x50(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x50(%rbp),%eax
jge    1219 <test_bingham_F_lookup_3d+0xc9>
lea    -0x40(%rbp),%rdi
call   1050 <bingham_F_lookup_3d@plt>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11f6 <test_bingham_F_lookup_3d+0xa6>
mov    $0x0,%al
call   1060 <get_time_ms@plt>
movsd  %xmm0,-0x58(%rbp)
mov    -0x50(%rbp),%esi
movsd  -0x58(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
lea    0xde1(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <get_time_ms@plt>
movsd  %xmm0,-0x48(%rbp)
movl   $0xc8,-0x64(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x64(%rbp),%eax
jg     1303 <test_bingham_F_lookup_3d+0x1b3>
movl   $0x1,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jg     12f0 <test_bingham_F_lookup_3d+0x1a0>
movl   $0x1,-0x60(%rbp)
mov    -0x60(%rbp),%eax
cmp    -0x5c(%rbp),%eax
jg     12dd <test_bingham_F_lookup_3d+0x18d>
xor    %eax,%eax
sub    -0x4c(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x40(%rbp)
xor    %eax,%eax
sub    -0x5c(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x38(%rbp)
xor    %eax,%eax
sub    -0x60(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
lea    -0x40(%rbp),%rdi
call   1050 <bingham_F_lookup_3d@plt>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    1287 <test_bingham_F_lookup_3d+0x137>
jmp    12e2 <test_bingham_F_lookup_3d+0x192>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1274 <test_bingham_F_lookup_3d+0x124>
jmp    12f5 <test_bingham_F_lookup_3d+0x1a5>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1261 <test_bingham_F_lookup_3d+0x111>
mov    $0x0,%al
call   1060 <get_time_ms@plt>
movsd  %xmm0,-0x58(%rbp)
mov    -0x50(%rbp),%esi
movsd  -0x58(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
lea    0xd1f(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_bingham_F_lookup_3d>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jle    12f7 <test_bingham_F_lookup_3d+0x1a7>
mov    0x8(%rbx),%rdi
call   1030 <atof@plt>
movsd  %xmm0,0x8(%rsp)
mov    0x10(%rbx),%rdi
call   1030 <atof@plt>
movsd  %xmm0,0x10(%rsp)
mov    0x18(%rbx),%rdi
call   1030 <atof@plt>
movsd  0x8(%rsp),%xmm1
movsd  %xmm1,0x20(%rsp)
movsd  0x10(%rsp),%xmm1
movsd  %xmm1,0x28(%rsp)
movsd  %xmm0,0x30(%rsp)
xor    %eax,%eax
call   1060 <get_time_ms@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0xf4240,%ebp
lea    0x20(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <bingham_F_lookup_3d@plt>
add    $0xffffffff,%ebp
jne    11d0 <test_bingham_F_lookup_3d+0x80>
xor    %r12d,%r12d
xor    %eax,%eax
call   1060 <get_time_ms@plt>
subsd  0x8(%rsp),%xmm0
lea    0xe26(%rip),%rdi
mov    $0xf4240,%esi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <get_time_ms@plt>
movsd  %xmm0,0x40(%rsp)
mov    $0x1,%eax
mov    $0x3,%r15d
lea    0x20(%rsp),%rbx
nopl   (%rax)
mov    %eax,0x1c(%rsp)
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mov    $0x2,%r13d
mov    $0x1,%ebp
movsd  %xmm0,0x10(%rsp)
xchg   %ax,%ax
mov    %ebp,%eax
neg    %eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    $0xffffffff,%r14d
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x28(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
movsd  %xmm0,0x30(%rsp)
mov    %rbx,%rdi
call   1050 <bingham_F_lookup_3d@plt>
movsd  0x10(%rsp),%xmm0
lea    (%r14,%rbp,1),%eax
add    $0xffffffff,%eax
mov    %r14d,%ecx
add    $0xffffffff,%ecx
mov    %ecx,%r14d
cmp    $0xffffffff,%eax
jne    1260 <test_bingham_F_lookup_3d+0x110>
add    %ebp,%r12d
add    $0x1,%ebp
add    $0x1,%r13d
cmp    %r15d,%r13d
jne    1240 <test_bingham_F_lookup_3d+0xf0>
mov    0x1c(%rsp),%eax
add    $0x1,%eax
add    $0x1,%r15d
cmp    $0xcb,%r15d
jne    1220 <test_bingham_F_lookup_3d+0xd0>
xor    %eax,%eax
call   1060 <get_time_ms@plt>
subsd  0x40(%rsp),%xmm0
lea    0xd64(%rip),%rdi
mov    %r12d,%esi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xcff(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"usage: %s <z1> <z2> <z3>\0A\00"
@.str.1 = [40 x i8] c"Performed %d same F-lookups in %.0f ms\0A\00"
@.str.2 = [42 x i8] c"Performed %d unique F-lookups in %.0f ms\0A\00"
define void @test_bingham_F_lookup_3d(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca [3 x double]
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 4
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i8**, i8*** %4
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
%25 = load i8**, i8*** %4
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call double @atof(i8* %27)
store double %28, double* %5
%29 = load i8**, i8*** %4
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call double @atof(i8* %31)
store double %32, double* %6
%33 = load i8**, i8*** %4
%34 = getelementptr inbounds i8*, i8** %33, i64 3
%35 = load i8*, i8** %34
%36 = call double @atof(i8* %35)
store double %36, double* %7
%37 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%38 = load double, double* %5
store double %38, double* %37
%39 = getelementptr inbounds double, double* %37, i64 1
%40 = load double, double* %6
store double %40, double* %39
%41 = getelementptr inbounds double, double* %39, i64 1
%42 = load double, double* %7
store double %42, double* %41
%43 = call double (...) @get_time_ms()
store double %43, double* %9
store i32 1000000, i32* %11
store i32 0, i32* %10
br label %44
44: ; preds = %51, %24
%45 = load i32, i32* %10
%46 = load i32, i32* %11
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %54
48: ; preds = %44
%49 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%50 = call i32 @bingham_F_lookup_3d(double* %49)
br label %51
51: ; preds = %48
%52 = load i32, i32* %10
%53 = add nsw i32 %52, 1
store i32 %53, i32* %10
br label %44
54: ; preds = %44
%55 = call double (...) @get_time_ms()
store double %55, double* %12
%56 = load i32, i32* %11
%57 = load double, double* %12
%58 = load double, double* %9
%59 = fsub double %57, %58
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %56, double %59)
%61 = call double (...) @get_time_ms()
store double %61, double* %9
store i32 200, i32* %15
store i32 0, i32* %11
store i32 1, i32* %10
br label %62
62: ; preds = %101, %54
%63 = load i32, i32* %10
%64 = load i32, i32* %15
%65 = icmp sle i32 %63, %64
br i1 %65, label %66, label %104
66: ; preds = %62
store i32 1, i32* %13
br label %67
67: ; preds = %97, %66
%68 = load i32, i32* %13
%69 = load i32, i32* %10
%70 = icmp sle i32 %68, %69
br i1 %70, label %71, label %100
71: ; preds = %67
store i32 1, i32* %14
br label %72
72: ; preds = %93, %71
%73 = load i32, i32* %14
%74 = load i32, i32* %13
%75 = icmp sle i32 %73, %74
br i1 %75, label %76, label %96
76: ; preds = %72
%77 = load i32, i32* %10
%78 = sub nsw i32 0, %77
%79 = sitofp i32 %78 to double
%80 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
store double %79, double* %80
%81 = load i32, i32* %13
%82 = sub nsw i32 0, %81
%83 = sitofp i32 %82 to double
%84 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 1
store double %83, double* %84
%85 = load i32, i32* %14
%86 = sub nsw i32 0, %85
%87 = sitofp i32 %86 to double
%88 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 2
store double %87, double* %88
%89 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%90 = call i32 @bingham_F_lookup_3d(double* %89)
%91 = load i32, i32* %11
%92 = add nsw i32 %91, 1
store i32 %92, i32* %11
br label %93
93: ; preds = %76
%94 = load i32, i32* %14
%95 = add nsw i32 %94, 1
store i32 %95, i32* %14
br label %72
96: ; preds = %72
br label %97
97: ; preds = %96
%98 = load i32, i32* %13
%99 = add nsw i32 %98, 1
store i32 %99, i32* %13
br label %67
100: ; preds = %67
br label %101
101: ; preds = %100
%102 = load i32, i32* %10
%103 = add nsw i32 %102, 1
store i32 %103, i32* %10
br label %62
104: ; preds = %62
%105 = call double (...) @get_time_ms()
store double %105, double* %12
%106 = load i32, i32* %11
%107 = load double, double* %12
%108 = load double, double* %9
%109 = fsub double %107, %108
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %106, double %109)
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"usage: %s <z1> <z2> <z3>\0A\00"
@.str.1 = [40 x i8] c"Performed %d same F-lookups in %.0f ms\0A\00"
@.str.2 = [42 x i8] c"Performed %d unique F-lookups in %.0f ms\0A\00"
define void @test_bingham_F_lookup_3d(i32 %0, i8** nocapture %1) {
%3 = alloca [3 x double]
%4 = icmp slt i32 %0, 4
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call double @atof(i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call double @atof(i8* %14)
%16 = getelementptr inbounds i8*, i8** %1, i64 3
%17 = load i8*, i8** %16
%18 = tail call double @atof(i8* %17)
%19 = bitcast [3 x double]* %3 to i8*
%20 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 0
store double %12, double* %20
%21 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 1
store double %15, double* %21
%22 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 2
store double %18, double* %22
%23 = tail call double (...) @get_time_ms()
br label %24
24: ; preds = %9, %24
%25 = phi i32 [ 0, %9 ], [ %27, %24 ]
%26 = call i32 @bingham_F_lookup_3d(double* %20)
%27 = add nuw nsw i32 %25, 1
%28 = icmp eq i32 %27, 1000000
br i1 %28, label %29, label %24
29: ; preds = %24
%30 = call double (...) @get_time_ms()
%31 = fsub double %30, %23
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 1000000, double %31)
%33 = call double (...) @get_time_ms()
br label %34
34: ; preds = %29, %58
%35 = phi i32 [ 3, %29 ], [ %60, %58 ]
%36 = phi i32 [ 0, %29 ], [ %54, %58 ]
%37 = phi i32 [ 1, %29 ], [ %59, %58 ]
%38 = sub nsw i32 0, %37
%39 = sitofp i32 %38 to double
br label %40
40: ; preds = %34, %53
%41 = phi i32 [ 2, %34 ], [ %56, %53 ]
%42 = phi i32 [ 1, %34 ], [ %55, %53 ]
%43 = phi i32 [ %36, %34 ], [ %54, %53 ]
%44 = sub nsw i32 0, %42
%45 = sitofp i32 %44 to double
br label %46
46: ; preds = %40, %46
%47 = phi i32 [ 1, %40 ], [ %51, %46 ]
store double %39, double* %20
store double %45, double* %21
%48 = sub nsw i32 0, %47
%49 = sitofp i32 %48 to double
store double %49, double* %22
%50 = call i32 @bingham_F_lookup_3d(double* %20)
%51 = add nuw nsw i32 %47, 1
%52 = icmp eq i32 %51, %41
br i1 %52, label %53, label %46
53: ; preds = %46
%54 = add i32 %43, %42
%55 = add nuw nsw i32 %42, 1
%56 = add nuw nsw i32 %41, 1
%57 = icmp eq i32 %56, %35
br i1 %57, label %58, label %40
58: ; preds = %53
%59 = add nuw nsw i32 %37, 1
%60 = add nuw nsw i32 %35, 1
%61 = icmp eq i32 %60, 203
br i1 %61, label %62, label %34
62: ; preds = %58
%63 = call double (...) @get_time_ms()
%64 = fsub double %63, %33
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %54, double %64)
ret void
}