#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 */
int /*<<< orphan*/ M_PI;
int /*<<< orphan*/ assert(int);
double mod2pi_ref(int /*<<< orphan*/, double);
int theta_to_int(double theta, int max) {
  theta = mod2pi_ref(M_PI, theta);
  int v = (int)(theta / 6.2831853071795862319959 * max);
  if (v == max)
    v = 0;
  assert(v >= 0 && v < max);
  return v;
}


x86 assembly (clang, -O0):
<theta_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    0x2eb1(%rip),%rax
mov    (%rax),%edi
movsd  -0x8(%rbp),%xmm0
call   1030 <mod2pi_ref@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xeab(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    117c <theta_to_int+0x5c>
movl   $0x0,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jl     1197 <theta_to_int+0x77>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
setl   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<theta_to_int>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2ebc(%rip),%rax
mov    (%rax),%edi
call   1030 <mod2pi_ref@plt>
divsd  0xec5(%rip),%xmm0
cvtsi2sd %ebx,%xmm1
mulsd  %xmm0,%xmm1
cvttsd2si %xmm1,%eax
xor    %ebp,%ebp
cmp    %ebx,%eax
cmovne %eax,%ebp
test   %ebp,%ebp
setns  %al
cmp    %ebx,%ebp
setl   %cl
and    %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@M_PI = global i32 0
define i32 @theta_to_int(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
store double %0, double* %3
store i32 %1, i32* %4
%6 = load i32, i32* @M_PI
%7 = load double, double* %3
%8 = call double @mod2pi_ref(i32 %6, double %7)
store double %8, double* %3
%9 = load double, double* %3
%10 = fdiv double %9, 0x401921FB54442D18
%11 = load i32, i32* %4
%12 = sitofp i32 %11 to double
%13 = fmul double %10, %12
%14 = fptosi double %13 to i32
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = load i32, i32* %4
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 0, i32* %5
br label %19
19: ; preds = %18, %2
%20 = load i32, i32* %5
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* %5
%24 = load i32, i32* %4
%25 = icmp slt i32 %23, %24
br label %26
26: ; preds = %22, %19
%27 = phi i1 [ false, %19 ], [ %25, %22 ]
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
@M_PI = global i32 0
define i32 @theta_to_int(double %0, i32 %1) {
%3 = load i32, i32* @M_PI
%4 = tail call double @mod2pi_ref(i32 %3, double %0)
%5 = fdiv double %4, 0x401921FB54442D18
%6 = sitofp i32 %1 to double
%7 = fmul double %5, %6
%8 = fptosi double %7 to i32
%9 = icmp eq i32 %8, %1
%10 = select i1 %9, i32 0, i32 %8
%11 = icmp sgt i32 %10, -1
%12 = icmp slt i32 %10, %1
%13 = and i1 %11, %12
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
ret i32 %10
}