#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 */
float acosf(float);
int /*<<< orphan*/ printf(char *);
void add_histogram(float px, float py, float pz, float qx, float qy, float qz,
                   long int *histogram, const float pi,
                   const float costotaldegrees) {
  float theta;
  float degreefactor = 180.0 / pi * 4;
  int bin;
  theta = px * qx + py * qy + pz * qz;
  if (theta >= costotaldegrees) {
    if (theta > 1.0)
      theta = 1.0;
    bin = (int)(acosf(theta) * degreefactor);
    if (bin == 256)
      printf("Debug: bin = 256\n");
    histogram[bin]++;
  }
}


x86 assembly (clang, -O0):
<add_histogram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
movss  %xmm4,-0x14(%rbp)
movss  %xmm5,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
movss  %xmm6,-0x24(%rbp)
movss  %xmm7,-0x28(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xea3(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  0xe8f(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x4(%rbp),%xmm1
movss  -0x10(%rbp),%xmm2
movss  -0x8(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
movss  -0xc(%rbp),%xmm0
movss  -0x18(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
ucomiss -0x28(%rbp),%xmm0
jb     122b <add_histogram+0x10b>
movss  -0x2c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe3f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11e8 <add_histogram+0xc8>
movss  0xe35(%rip),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
call   1040 <acosf@plt>
mulss  -0x30(%rbp),%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x100,-0x34(%rbp)
jne    1217 <add_histogram+0xf7>
lea    0xe0a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
add    $0x1,%rdx
mov    %rdx,(%rax,%rcx,8)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_histogram>:
mulss  %xmm4,%xmm1
mulss  %xmm3,%xmm0
addss  %xmm1,%xmm0
mulss  %xmm5,%xmm2
addss  %xmm0,%xmm2
ucomiss %xmm7,%xmm2
jb     11a4 <add_histogram+0x84>
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
cvtss2sd %xmm6,%xmm0
movsd  0xeb2(%rip),%xmm1
divsd  %xmm0,%xmm1
mulsd  0xeae(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  %xmm0,0x4(%rsp)
movss  0xea1(%rip),%xmm0
minss  %xmm2,%xmm0
call   1040 <acosf@plt>
mulss  0x4(%rsp),%xmm0
cvttss2si %xmm0,%ebp
cmp    $0x100,%ebp
jne    1196 <add_histogram+0x76>
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
movslq %ebp,%rax
addq   $0x1,(%rbx,%rax,8)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Debug: bin = 256\0A\00"
define void @add_histogram(float %0, float %1, float %2, float %3, float %4, float %5, i64* %6, float %7, float %8) {
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca float
%14 = alloca float
%15 = alloca float
%16 = alloca i64*
%17 = alloca float
%18 = alloca float
%19 = alloca float
%20 = alloca float
%21 = alloca i32
store float %0, float* %10
store float %1, float* %11
store float %2, float* %12
store float %3, float* %13
store float %4, float* %14
store float %5, float* %15
store i64* %6, i64** %16
store float %7, float* %17
store float %8, float* %18
%22 = load float, float* %17
%23 = fpext float %22 to double
%24 = fdiv double 1.800000e+02, %23
%25 = fmul double %24, 4.000000e+00
%26 = fptrunc double %25 to float
store float %26, float* %20
%27 = load float, float* %10
%28 = load float, float* %13
%29 = load float, float* %11
%30 = load float, float* %14
%31 = fmul float %29, %30
%32 = call float @llvm.fmuladd.f32(float %27, float %28, float %31)
%33 = load float, float* %12
%34 = load float, float* %15
%35 = call float @llvm.fmuladd.f32(float %33, float %34, float %32)
store float %35, float* %19
%36 = load float, float* %19
%37 = load float, float* %18
%38 = fcmp oge float %36, %37
br i1 %38, label %39, label %61
39: ; preds = %9
%40 = load float, float* %19
%41 = fpext float %40 to double
%42 = fcmp ogt double %41, 1.000000e+00
br i1 %42, label %43, label %44
43: ; preds = %39
store float 1.000000e+00, float* %19
br label %44
44: ; preds = %43, %39
%45 = load float, float* %19
%46 = call float @acosf(float %45)
%47 = load float, float* %20
%48 = fmul float %46, %47
%49 = fptosi float %48 to i32
store i32 %49, i32* %21
%50 = load i32, i32* %21
%51 = icmp eq i32 %50, 256
br i1 %51, label %52, label %54
52: ; preds = %44
%53 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %54
54: ; preds = %52, %44
%55 = load i64*, i64** %16
%56 = load i32, i32* %21
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i64, i64* %55, i64 %57
%59 = load i64, i64* %58
%60 = add nsw i64 %59, 1
store i64 %60, i64* %58
br label %61
61: ; preds = %54, %9
ret void
}

LLVM IR (-O2):
@str = [17 x i8] c"Debug: bin = 256\00"
define void @add_histogram(float %0, float %1, float %2, float %3, float %4, float %5, i64* nocapture %6, float %7, float %8) {
%10 = fmul float %1, %4
%11 = tail call float @llvm.fmuladd.f32(float %0, float %3, float %10)
%12 = tail call float @llvm.fmuladd.f32(float %2, float %5, float %11)
%13 = fcmp ult float %12, %8
br i1 %13, label %32, label %14
14: ; preds = %9
%15 = fpext float %7 to double
%16 = fdiv double 1.800000e+02, %15
%17 = fmul double %16, 4.000000e+00
%18 = fptrunc double %17 to float
%19 = fcmp ogt float %12, 1.000000e+00
%20 = select i1 %19, float 1.000000e+00, float %12
%21 = tail call float @acosf(float %20)
%22 = fmul float %21, %18
%23 = fptosi float %22 to i32
%24 = icmp eq i32 %23, 256
br i1 %24, label %25, label %27
25: ; preds = %14
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %27
27: ; preds = %25, %14
%28 = sext i32 %23 to i64
%29 = getelementptr inbounds i64, i64* %6, i64 %28
%30 = load i64, i64* %29
%31 = add nsw i64 %30, 1
store i64 %31, i64* %29
br label %32
32: ; preds = %27, %9
ret void
}