#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 fabs(double);
double sqrt(double);
int sharp_get_mlim(int lmax, int spin, double sth, double cth) {
  double ofs = lmax * 0.01;
  if (ofs < 100.)
    ofs = 100.;
  double b = -2 * spin * fabs(cth);
  double t1 = lmax * sth + ofs;
  double c = (double)spin * spin - t1 * t1;
  double discr = b * b - 4 * c;
  if (discr <= 0)
    return lmax;
  double res = (-b + sqrt(discr)) / 2.;
  if (res > lmax)
    res = lmax;
  return (int)(res + 0.5);
}


x86 assembly (clang, -O0):
<sharp_get_mlim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xec3(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xeaa(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    116e <sharp_get_mlim+0x4e>
movsd  0xe97(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
imul   $0xfffffffe,-0xc(%rbp),%eax
mov    %eax,-0x54(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  0xe17(%rip),%xmm1
mulsd  -0x40(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jb     123b <sharp_get_mlim+0x11b>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12b5 <sharp_get_mlim+0x195>
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  0xd9e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    12a1 <sharp_get_mlim+0x181>
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xd77(%rip),%xmm0
addsd  -0x50(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sharp_get_mlim>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movsd  %xmm0,(%rsp)
mov    %esi,%ebp
mov    %edi,%ebx
cvtsi2sd %edi,%xmm2
movsd  %xmm2,0x8(%rsp)
movsd  0xebf(%rip),%xmm0
mulsd  %xmm2,%xmm0
movsd  0xebb(%rip),%xmm2
maxsd  %xmm0,%xmm2
movsd  %xmm2,0x10(%rsp)
movaps %xmm1,%xmm0
call   1030 <fabs@plt>
imul   %ebp,%eax
add    %eax,%eax
neg    %eax
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
movsd  (%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
subsd  %xmm0,%xmm1
mulsd  0xe77(%rip),%xmm1
movapd %xmm2,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    11ec <sharp_get_mlim+0xcc>
ucomisd %xmm1,%xmm0
jb     11bb <sharp_get_mlim+0x9b>
sqrtsd %xmm0,%xmm0
jmp    11ca <sharp_get_mlim+0xaa>
movsd  %xmm2,(%rsp)
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm2
subsd  %xmm2,%xmm0
movsd  0xe42(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0x8(%rsp),%xmm2
minsd  %xmm0,%xmm2
addsd  %xmm1,%xmm2
cvttsd2si %xmm2,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sharp_get_mlim(i32 %0, i32 %1, double %2, double %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
store i32 %0, i32* %6
store i32 %1, i32* %7
store double %2, double* %8
store double %3, double* %9
%16 = load i32, i32* %6
%17 = sitofp i32 %16 to double
%18 = fmul double %17, 1.000000e-02
store double %18, double* %10
%19 = load double, double* %10
%20 = fcmp olt double %19, 1.000000e+02
br i1 %20, label %21, label %22
21: ; preds = %4
store double 1.000000e+02, double* %10
br label %22
22: ; preds = %21, %4
%23 = load i32, i32* %7
%24 = mul nsw i32 -2, %23
%25 = load double, double* %9
%26 = call i32 @fabs(double %25)
%27 = mul nsw i32 %24, %26
%28 = sitofp i32 %27 to double
store double %28, double* %11
%29 = load i32, i32* %6
%30 = sitofp i32 %29 to double
%31 = load double, double* %8
%32 = load double, double* %10
%33 = call double @llvm.fmuladd.f64(double %30, double %31, double %32)
store double %33, double* %12
%34 = load i32, i32* %7
%35 = sitofp i32 %34 to double
%36 = load i32, i32* %7
%37 = sitofp i32 %36 to double
%38 = load double, double* %12
%39 = load double, double* %12
%40 = fmul double %38, %39
%41 = fneg double %40
%42 = call double @llvm.fmuladd.f64(double %35, double %37, double %41)
store double %42, double* %13
%43 = load double, double* %11
%44 = load double, double* %11
%45 = load double, double* %13
%46 = fmul double 4.000000e+00, %45
%47 = fneg double %46
%48 = call double @llvm.fmuladd.f64(double %43, double %44, double %47)
store double %48, double* %14
%49 = load double, double* %14
%50 = fcmp ole double %49, 0.000000e+00
br i1 %50, label %51, label %53
51: ; preds = %22
%52 = load i32, i32* %6
store i32 %52, i32* %5
br label %71
53: ; preds = %22
%54 = load double, double* %11
%55 = fneg double %54
%56 = load double, double* %14
%57 = call double @sqrt(double %56)
%58 = fadd double %55, %57
%59 = fdiv double %58, 2.000000e+00
store double %59, double* %15
%60 = load double, double* %15
%61 = load i32, i32* %6
%62 = sitofp i32 %61 to double
%63 = fcmp ogt double %60, %62
br i1 %63, label %64, label %67
64: ; preds = %53
%65 = load i32, i32* %6
%66 = sitofp i32 %65 to double
store double %66, double* %15
br label %67
67: ; preds = %64, %53
%68 = load double, double* %15
%69 = fadd double %68, 5.000000e-01
%70 = fptosi double %69 to i32
store i32 %70, i32* %5
br label %71
71: ; preds = %67, %51
%72 = load i32, i32* %5
ret i32 %72
}

LLVM IR (-O2):
define i32 @sharp_get_mlim(i32 %0, i32 %1, double %2, double %3) {
%5 = sitofp i32 %0 to double
%6 = fmul double %5, 1.000000e-02
%7 = fcmp olt double %6, 1.000000e+02
%8 = select i1 %7, double 1.000000e+02, double %6
%9 = mul nsw i32 %1, -2
%10 = tail call i32 @fabs(double %3)
%11 = mul nsw i32 %9, %10
%12 = sitofp i32 %11 to double
%13 = tail call double @llvm.fmuladd.f64(double %5, double %2, double %8)
%14 = sitofp i32 %1 to double
%15 = fneg double %13
%16 = fmul double %13, %15
%17 = tail call double @llvm.fmuladd.f64(double %14, double %14, double %16)
%18 = fmul double %17, -4.000000e+00
%19 = tail call double @llvm.fmuladd.f64(double %12, double %12, double %18)
%20 = fcmp ugt double %19, 0.000000e+00
br i1 %20, label %21, label %29
21: ; preds = %4
%22 = tail call double @sqrt(double %19)
%23 = fsub double %22, %12
%24 = fmul double %23, 5.000000e-01
%25 = fcmp ogt double %24, %5
%26 = select i1 %25, double %5, double %24
%27 = fadd double %26, 5.000000e-01
%28 = fptosi double %27 to i32
br label %29
29: ; preds = %4, %21
%30 = phi i32 [ %28, %21 ], [ %0, %4 ]
ret i32 %30
}