#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*/ cat3(int /*<<< orphan*/, int /*<<< orphan*/,
                        int /*<<< orphan*/);
int /*<<< orphan*/ int2str(int);
int /*<<< orphan*/ newstr(char *);
int /*<<< orphan*/ runtime_error(int, int /*<<< orphan*/);
scalar_t__ sqrt(double);
int int_sqrt(int line, int value) {
  if (value < 0) {
    runtime_error(line,
                  cat3(newstr("Unable to compute the square root of "),
                       int2str(value), newstr(", since it is negative.")));
  }
  return (int)sqrt((double)value);
}


x86 assembly (clang, -O0):
<int_sqrt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11ab <int_sqrt+0x5b>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    0xe8b(%rip),%rdi
call   1070 <newstr@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <int2str@plt>
mov    %eax,-0x10(%rbp)
lea    0xe97(%rip),%rdi
call   1070 <newstr@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    %eax,%edx
call   1040 <cat3@plt>
mov    -0xc(%rbp),%edi
mov    %eax,%esi
call   1050 <runtime_error@plt>
cvtsi2sdl -0x8(%rbp),%xmm0
call   1060 <sqrt@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_sqrt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
test   %esi,%esi
jns    119a <int_sqrt+0x4a>
mov    %edi,%ebp
lea    0xe9a(%rip),%rdi
call   1070 <newstr@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1030 <int2str@plt>
mov    %eax,%r15d
lea    0xea7(%rip),%rdi
call   1070 <newstr@plt>
mov    %r14d,%edi
mov    %r15d,%esi
mov    %eax,%edx
call   1040 <cat3@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1050 <runtime_error@plt>
cvtsi2sd %ebx,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <sqrt@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"Unable to compute the square root of \00"
@.str.1 = [24 x i8] c", since it is negative.\00"
define i32 @int_sqrt(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %2
%8 = load i32, i32* %3
%9 = call i32 @newstr(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %4
%11 = call i32 @int2str(i32 %10)
%12 = call i32 @newstr(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @cat3(i32 %9, i32 %11, i32 %12)
%14 = call i32 @runtime_error(i32 %8, i32 %13)
br label %15
15: ; preds = %7, %2
%16 = load i32, i32* %4
%17 = sitofp i32 %16 to double
%18 = call i64 @sqrt(double %17)
%19 = trunc i64 %18 to i32
ret i32 %19
}

LLVM IR (-O2):
@.str = [38 x i8] c"Unable to compute the square root of \00"
@.str.1 = [24 x i8] c", since it is negative.\00"
define i32 @int_sqrt(i32 %0, i32 %1) {
%3 = icmp slt i32 %1, 0
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = tail call i32 @newstr(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @int2str(i32 %1)
%7 = tail call i32 @newstr(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @cat3(i32 %5, i32 %6, i32 %7)
%9 = tail call i32 @runtime_error(i32 %0, i32 %8)
br label %10
10: ; preds = %4, %2
%11 = sitofp i32 %1 to double
%12 = tail call i64 @sqrt(double %11)
%13 = trunc i64 %12 to i32
ret i32 %13
}