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


x86 assembly (clang, -O0):
<bot_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 <bot_mod2pi_ref@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%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    1184 <bot_theta_to_int+0x64>
movl   $0x0,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jl     119f <bot_theta_to_int+0x7f>
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):
<bot_theta_to_int>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2ebc(%rip),%rbp
mov    0x0(%rbp),%edi
call   1030 <bot_mod2pi_ref@plt>
mov    0x0(%rbp),%eax
add    %eax,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%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):
@M_PI = global i32 0
define i32 @bot_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 @bot_mod2pi_ref(i32 %6, double %7)
store double %8, double* %3
%9 = load double, double* %3
%10 = load i32, i32* @M_PI
%11 = mul nsw i32 2, %10
%12 = sitofp i32 %11 to double
%13 = fdiv double %9, %12
%14 = load i32, i32* %4
%15 = sitofp i32 %14 to double
%16 = fmul double %13, %15
%17 = fptosi double %16 to i32
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %2
store i32 0, i32* %5
br label %22
22: ; preds = %21, %2
%23 = load i32, i32* %5
%24 = icmp sge i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* %5
%27 = load i32, i32* %4
%28 = icmp slt i32 %26, %27
br label %29
29: ; preds = %25, %22
%30 = phi i1 [ false, %22 ], [ %28, %25 ]
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = load i32, i32* %5
ret i32 %33
}

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