#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, double *);
double sqrt(double);
int main() {
  double n, result;
  printf("Calculate square root of a number\n");
  while (1) {
    printf("> ");
    scanf("%lf", &n);
    result = sqrt(n);
    if (result > 0)
      printf("  sqrt(%f) = %f\n\n", n, result);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec4(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movsd  -0x10(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11a4 <main+0x74>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
lea    0xe8d(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
jmp    114d <main+0x1d>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xed2(%rip),%rdi
call   1030 <puts@plt>
lea    0xead(%rip),%r14
lea    0xea9(%rip),%r15
mov    %rsp,%rbx
lea    0xea3(%rip),%r12
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
movsd  (%rsp),%xmm0
ucomisd 0xe6e(%rip),%xmm0
xorpd  %xmm2,%xmm2
jb     11b0 <main+0x70>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
ucomisd %xmm2,%xmm1
jbe    1170 <main+0x30>
jmp    11c3 <main+0x83>
nopw   0x0(%rax,%rax,1)
call   1060 <sqrt@plt>
xorpd  %xmm2,%xmm2
movapd %xmm0,%xmm1
ucomisd %xmm2,%xmm1
jbe    1170 <main+0x30>
movsd  (%rsp),%xmm0
mov    %r12,%rdi
mov    $0x2,%al
call   1040 <printf@plt>
jmp    1170 <main+0x30>

LLVM IR (-O0):
@.str = [35 x i8] c"Calculate square root of a number\0A\00"
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [4 x i8] c"%lf\00"
@.str.3 = [18 x i8] c" sqrt(%f) = %f\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %0, %16
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %2)
%8 = load double, double* %2
%9 = call double @sqrt(double %8)
store double %9, double* %3
%10 = load double, double* %3
%11 = fcmp ogt double %10, 0.000000e+00
br i1 %11, label %12, label %16
12: ; preds = %5
%13 = load double, double* %2
%14 = load double, double* %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), double %13, double %14)
br label %16
16: ; preds = %12, %5
br label %5
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [4 x i8] c"%lf\00"
@.str.3 = [18 x i8] c" sqrt(%f) = %f\0A\0A\00"
@str = [34 x i8] c"Calculate square root of a number\00"
define i32 @main() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %4
4: ; preds = %13, %0
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %1)
%7 = load double, double* %1
%8 = call double @sqrt(double %7)
%9 = fcmp ogt double %8, 0.000000e+00
br i1 %9, label %10, label %13
10: ; preds = %4
%11 = load double, double* %1
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), double %11, double %8)
br label %13
13: ; preds = %10, %4
br label %4
}