#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*/ assert(int);
double mod2pi_ref(double, double);
int theta_to_int(double theta, int max) {
  theta = mod2pi_ref(3.14159265358979323846, theta);
  int v = (int)(theta / (2 * 3.14159265358979323846) * 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)
movsd  -0x8(%rbp),%xmm1
movsd  0xecb(%rip),%xmm0
call   1030 <mod2pi_ref@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xeac(%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    117b <theta_to_int+0x5b>
movl   $0x0,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jl     1196 <theta_to_int+0x76>
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
movaps %xmm0,%xmm1
movsd  0xed0(%rip),%xmm0
call   1030 <mod2pi_ref@plt>
divsd  0xecb(%rip),%xmm0
xorps  %xmm1,%xmm1
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):
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 double, double* %3
%7 = call double @mod2pi_ref(double 0x400921FB54442D18, double %6)
store double %7, double* %3
%8 = load double, double* %3
%9 = fdiv double %8, 0x401921FB54442D18
%10 = load i32, i32* %4
%11 = sitofp i32 %10 to double
%12 = fmul double %9, %11
%13 = fptosi double %12 to i32
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 0, i32* %5
br label %18
18: ; preds = %17, %2
%19 = load i32, i32* %5
%20 = icmp sge i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i32, i32* %5
%23 = load i32, i32* %4
%24 = icmp slt i32 %22, %23
br label %25
25: ; preds = %21, %18
%26 = phi i1 [ false, %18 ], [ %24, %21 ]
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i32, i32* %5
ret i32 %29
}

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