#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 */
long long pow(long long, int);
long long findNb(long long m) {
  long long n = 1;
  while (pow((n * (n + 1) / 2.0), 2) < m)
    n++;
  return pow((n * (n + 1) / 2.0), 2) == m ? n : -1;
}


x86 assembly (clang, -O0):
<findNb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    $0x1,%rcx
imul   %rcx,%rax
cvtsi2sd %rax,%xmm0
movsd  0xebf(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
mov    $0x2,%esi
call   1030 <pow@plt>
cmp    -0x8(%rbp),%rax
jge    116f <findNb+0x5f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1124 <findNb+0x14>
mov    -0x10(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    $0x1,%rcx
imul   %rcx,%rax
cvtsi2sd %rax,%xmm0
movsd  0xe74(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
mov    $0x2,%esi
call   1030 <pow@plt>
cmp    -0x8(%rbp),%rax
jne    11b6 <findNb+0xa6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11c6 <findNb+0xb6>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    11c6 <findNb+0xb6>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findNb>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
mov    %r15,%rax
add    $0x1,%r15
add    $0x2,%rax
imul   %r15,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mulsd  0xec1(%rip),%xmm0
cvttsd2si %xmm0,%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <pow@plt>
cmp    %r14,%rax
jl     1120 <findNb+0x10>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <pow@plt>
cmp    %r14,%rax
mov    $0xffffffffffffffff,%rax
cmove  %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @findNb(i64 %0) {
%2 = alloca i64
%3 = alloca i64
store i64 %0, i64* %2
store i64 1, i64* %3
br label %4
4: ; preds = %15, %1
%5 = load i64, i64* %3
%6 = load i64, i64* %3
%7 = add nsw i64 %6, 1
%8 = mul nsw i64 %5, %7
%9 = sitofp i64 %8 to double
%10 = fdiv double %9, 2.000000e+00
%11 = fptosi double %10 to i64
%12 = call i64 @pow(i64 %11, i32 2)
%13 = load i64, i64* %2
%14 = icmp slt i64 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = load i64, i64* %3
%17 = add nsw i64 %16, 1
store i64 %17, i64* %3
br label %4
18: ; preds = %4
%19 = load i64, i64* %3
%20 = load i64, i64* %3
%21 = add nsw i64 %20, 1
%22 = mul nsw i64 %19, %21
%23 = sitofp i64 %22 to double
%24 = fdiv double %23, 2.000000e+00
%25 = fptosi double %24 to i64
%26 = call i64 @pow(i64 %25, i32 2)
%27 = load i64, i64* %2
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %18
%30 = load i64, i64* %3
br label %32
31: ; preds = %18
br label %32
32: ; preds = %31, %29
%33 = phi i64 [ %30, %29 ], [ -1, %31 ]
ret i64 %33
}

LLVM IR (-O2):
define i64 @findNb(i64 %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ 1, %1 ], [ %4, %2 ]
%4 = add nuw nsw i64 %3, 1
%5 = mul nsw i64 %4, %3
%6 = sitofp i64 %5 to double
%7 = fmul double %6, 5.000000e-01
%8 = fptosi double %7 to i64
%9 = tail call i64 @pow(i64 %8, i32 2)
%10 = icmp slt i64 %9, %0
br i1 %10, label %2, label %11
11: ; preds = %2
%12 = tail call i64 @pow(i64 %8, i32 2)
%13 = icmp eq i64 %12, %0
%14 = select i1 %13, i64 %3, i64 -1
ret i64 %14
}