#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*/ eset(int);
scalar_t__ sqrt(double);
int Msqrt(int nargs, int *argsv) {
  if (nargs < 1) {
    eset(21);
    return -1;
  }
  double x = (double)argsv[0];
  if (x < 0.0) {
    eset(21);
    return -1;
  }
  return (int)(sqrt(x) + 0.5);
}


x86 assembly (clang, -O0):
<Msqrt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    114f <Msqrt+0x2f>
mov    $0x15,%edi
call   1030 <eset@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a2 <Msqrt+0x82>
mov    -0x10(%rbp),%rax
cvtsi2sdl (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1180 <Msqrt+0x60>
mov    $0x15,%edi
call   1030 <eset@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a2 <Msqrt+0x82>
movsd  -0x18(%rbp),%xmm0
call   1040 <sqrt@plt>
cvtsi2sd %rax,%xmm0
movsd  0xe69(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Msqrt>:
push   %rax
test   %edi,%edi
jle    114a <Msqrt+0x2a>
mov    (%rsi),%eax
test   %eax,%eax
js     114a <Msqrt+0x2a>
cvtsi2sd %eax,%xmm0
call   1040 <sqrt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0xebc(%rip),%xmm0
cvttsd2si %xmm0,%eax
pop    %rcx
ret
mov    $0x15,%edi
call   1030 <eset@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @Msqrt(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca double
store i32 %0, i32* %4
store i32* %1, i32** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @eset(i32 21)
store i32 -1, i32* %3
br label %26
11: ; preds = %2
%12 = load i32*, i32** %5
%13 = getelementptr inbounds i32, i32* %12, i64 0
%14 = load i32, i32* %13
%15 = sitofp i32 %14 to double
store double %15, double* %6
%16 = load double, double* %6
%17 = fcmp olt double %16, 0.000000e+00
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = call i32 @eset(i32 21)
store i32 -1, i32* %3
br label %26
20: ; preds = %11
%21 = load double, double* %6
%22 = call i64 @sqrt(double %21)
%23 = sitofp i64 %22 to double
%24 = fadd double %23, 5.000000e-01
%25 = fptosi double %24 to i32
store i32 %25, i32* %3
br label %26
26: ; preds = %20, %18, %9
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
define i32 @Msqrt(i32 %0, i32* nocapture %1) {
%3 = icmp slt i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @eset(i32 21)
br label %17
6: ; preds = %2
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @eset(i32 21)
br label %17
11: ; preds = %6
%12 = sitofp i32 %7 to double
%13 = tail call i64 @sqrt(double %12)
%14 = sitofp i64 %13 to double
%15 = fadd double %14, 5.000000e-01
%16 = fptosi double %15 to i32
br label %17
17: ; preds = %9, %11, %4
%18 = phi i32 [ -1, %4 ], [ -1, %9 ], [ %16, %11 ]
ret i32 %18
}