#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 */
double fabs(double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
double sqrt(int);
void buscarPrimoCercano(void) {
  int input, resultado;
  double square, delta;
  printf("Introduce un numero positivo: ");
  scanf("%d", &input);
  square = sqrt(input);
  delta = fabs(square - (int)square);
  if (delta >= 0.5)
    resultado = (int)square + 1;
  else
    resultado = (int)square;
  resultado *= resultado;
  printf("El cuadrado mas cercano es: %d\n", resultado);
}


x86 assembly (clang, -O0):
<buscarPrimoCercano>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef2(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x4(%rbp),%edi
call   1050 <sqrt@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
cvttsd2si -0x10(%rbp),%eax
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
movaps 0xe94(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe6e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11ac <buscarPrimoCercano+0x7c>
cvttsd2si -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b4 <buscarPrimoCercano+0x84>
cvttsd2si -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
imul   -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buscarPrimoCercano>:
push   %rax
lea    0xee0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xef1(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%edi
call   1050 <sqrt@plt>
cvttsd2si %xmm0,%esi
cvttpd2dq %xmm0,%xmm1
cvtdq2pd %xmm1,%xmm1
subsd  %xmm1,%xmm0
andpd  0xe8f(%rip),%xmm0
ucomisd 0xe97(%rip),%xmm0
sbb    $0xffffffff,%esi
imul   %esi,%esi
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Introduce un numero positivo: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [32 x i8] c"El cuadrado mas cercano es: %d\0A\00"
define void @buscarPrimoCercano() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = call double @sqrt(i32 %7)
store double %8, double* %3
%9 = load double, double* %3
%10 = load double, double* %3
%11 = fptosi double %10 to i32
%12 = sitofp i32 %11 to double
%13 = fsub double %9, %12
%14 = call double @llvm.fabs.f64(double %13)
store double %14, double* %4
%15 = load double, double* %4
%16 = fcmp oge double %15, 5.000000e-01
br i1 %16, label %17, label %21
17: ; preds = %0
%18 = load double, double* %3
%19 = fptosi double %18 to i32
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %24
21: ; preds = %0
%22 = load double, double* %3
%23 = fptosi double %22 to i32
store i32 %23, i32* %2
br label %24
24: ; preds = %21, %17
%25 = load i32, i32* %2
%26 = load i32, i32* %2
%27 = mul nsw i32 %26, %25
store i32 %27, i32* %2
%28 = load i32, i32* %2
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %28)
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"Introduce un numero positivo: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [32 x i8] c"El cuadrado mas cercano es: %d\0A\00"
define void @buscarPrimoCercano() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = call double @sqrt(i32 %5)
%7 = fptosi double %6 to i32
%8 = sitofp i32 %7 to double
%9 = fsub double %6, %8
%10 = call double @llvm.fabs.f64(double %9)
%11 = fcmp oge double %10, 5.000000e-01
%12 = zext i1 %11 to i32
%13 = add nsw i32 %12, %7
%14 = mul nsw i32 %13, %13
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %14)
ret void
}