#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 compnlon(int /*<<< orphan*/);
scalar_t__ lround(scalar_t__);
int /*<<< orphan*/ ntr2nlat_linear(int);
scalar_t__ sqrt(double);
int ngp2ntr(int ngp) {
  int ntr = (int)lround(sqrt(0.25 + ngp) - 1.5);
  int nlonl = compnlon(ntr2nlat_linear(ntr));
  int nlatl = nlonl / 2;
  ntr = (2 * nlatl - 1) / 2;
  return (ntr);
}


x86 assembly (clang, -O0):
<ngp2ntr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm1
movsd  0xeb0(%rip),%xmm0
addsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
cvtsi2sd %rax,%xmm0
movsd  0xe92(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1030 <lround@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <ntr2nlat_linear@plt>
mov    %eax,%edi
call   1060 <compnlon@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ngp2ntr>:
push   %rax
cvtsi2sd %edi,%xmm0
addsd  0xeb3(%rip),%xmm0
call   1050 <sqrt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0xea6(%rip),%xmm0
cvttsd2si %xmm0,%rdi
call   1030 <lround@plt>
mov    %eax,%edi
call   1040 <ntr2nlat_linear@plt>
mov    %eax,%edi
call   1060 <compnlon@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0xfffffffe,%ecx
mov    %ecx,%eax
add    $0xffffffff,%eax
shr    $0x1f,%eax
add    %ecx,%eax
add    $0xffffffff,%eax
sar    %eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @ngp2ntr(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = sitofp i32 %6 to double
%8 = fadd double 2.500000e-01, %7
%9 = call i64 @sqrt(double %8)
%10 = sitofp i64 %9 to double
%11 = fsub double %10, 1.500000e+00
%12 = fptosi double %11 to i64
%13 = call i64 @lround(i64 %12)
%14 = trunc i64 %13 to i32
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = call i32 @ntr2nlat_linear(i32 %15)
%17 = call i32 @compnlon(i32 %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = sdiv i32 %18, 2
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = mul nsw i32 2, %20
%22 = sub nsw i32 %21, 1
%23 = sdiv i32 %22, 2
store i32 %23, i32* %3
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
define i32 @ngp2ntr(i32 %0) {
%2 = sitofp i32 %0 to double
%3 = fadd double %2, 2.500000e-01
%4 = tail call i64 @sqrt(double %3)
%5 = sitofp i64 %4 to double
%6 = fadd double %5, -1.500000e+00
%7 = fptosi double %6 to i64
%8 = tail call i64 @lround(i64 %7)
%9 = trunc i64 %8 to i32
%10 = tail call i32 @ntr2nlat_linear(i32 %9)
%11 = tail call i32 @compnlon(i32 %10)
%12 = sdiv i32 %11, 2
%13 = shl nsw i32 %12, 1
%14 = add nsw i32 %13, -1
%15 = sdiv i32 %14, 2
ret i32 %15
}