#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 */
struct DynArr {
  int dummy;
};

/* Variables and functions */
scalar_t__ isEmptyDynArr(struct DynArr *);
int /*<<< orphan*/ popDynArr(struct DynArr *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ pushDynArr(struct DynArr *, double);
double sqrt(double);
double topDynArr(struct DynArr *);
void squareroot(struct DynArr *stack) {
  double a, c = 0;
  if (isEmptyDynArr(stack))
    return;
  a = topDynArr(stack);
  popDynArr(stack);
  if (a < 0) {
    printf("Squareroot Error: negative number. Automatically ignore sqrt "
           "operator. May cause wrong result. Please check your input.\n");
    pushDynArr(stack, a);
  } else {
    c = sqrt(a);
    pushDynArr(stack, c);
  }
}


x86 assembly (clang, -O0):
<squareroot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <isEmptyDynArr@plt>
cmp    $0x0,%rax
je     118c <squareroot+0x2c>
jmp    11ed <squareroot+0x8d>
mov    -0x8(%rbp),%rdi
call   1030 <topDynArr@plt>
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <popDynArr@plt>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11d0 <squareroot+0x70>
lea    0xe48(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
call   1080 <pushDynArr@plt>
jmp    11ed <squareroot+0x8d>
movsd  -0x10(%rbp),%xmm0
call   1070 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
call   1080 <pushDynArr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<squareroot>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1060 <isEmptyDynArr@plt>
test   %rax,%rax
je     1178 <squareroot+0x18>
add    $0x10,%rsp
pop    %rbx
ret
mov    %rbx,%rdi
call   1030 <topDynArr@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1050 <popDynArr@plt>
xorpd  %xmm0,%xmm0
ucomisd 0x8(%rsp),%xmm0
jbe    11ae <squareroot+0x4e>
lea    0xe5f(%rip),%rdi
call   1040 <puts@plt>
movsd  0x8(%rsp),%xmm0
jmp    11c9 <squareroot+0x69>
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
movapd %xmm1,%xmm0
jb     11c4 <squareroot+0x64>
sqrtsd %xmm0,%xmm0
jmp    11c9 <squareroot+0x69>
call   1070 <sqrt@plt>
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1080 <pushDynArr@plt>

LLVM IR (-O0):
%struct.DynArr = type { i32 }
@.str = [121 x i8] c"Squareroot Error: negative number. Automatically ignore sqrt operator. May cause wrong result. Please check your input.\0A\00"
define void @squareroot(%struct.DynArr* %0) {
%2 = alloca %struct.DynArr*
%3 = alloca double
%4 = alloca double
store %struct.DynArr* %0, %struct.DynArr** %2
store double 0.000000e+00, double* %4
%5 = load %struct.DynArr*, %struct.DynArr** %2
%6 = call i64 @isEmptyDynArr(%struct.DynArr* %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
br label %27
9: ; preds = %1
%10 = load %struct.DynArr*, %struct.DynArr** %2
%11 = call double @topDynArr(%struct.DynArr* %10)
store double %11, double* %3
%12 = load %struct.DynArr*, %struct.DynArr** %2
%13 = call i32 @popDynArr(%struct.DynArr* %12)
%14 = load double, double* %3
%15 = fcmp olt double %14, 0.000000e+00
br i1 %15, label %16, label %21
16: ; preds = %9
%17 = call i32 @printf(i8* getelementptr inbounds ([121 x i8], [121 x i8]* @.str, i64 0, i64 0))
%18 = load %struct.DynArr*, %struct.DynArr** %2
%19 = load double, double* %3
%20 = call i32 @pushDynArr(%struct.DynArr* %18, double %19)
br label %27
21: ; preds = %9
%22 = load double, double* %3
%23 = call double @sqrt(double %22)
store double %23, double* %4
%24 = load %struct.DynArr*, %struct.DynArr** %2
%25 = load double, double* %4
%26 = call i32 @pushDynArr(%struct.DynArr* %24, double %25)
br label %27
27: ; preds = %8, %21, %16
ret void
}

LLVM IR (-O2):
%struct.DynArr = type { i32 }
@str = [120 x i8] c"Squareroot Error: negative number. Automatically ignore sqrt operator. May cause wrong result. Please check your input.\00"
define void @squareroot(%struct.DynArr* %0) {
%2 = tail call i64 @isEmptyDynArr(%struct.DynArr* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %15
4: ; preds = %1
%5 = tail call double @topDynArr(%struct.DynArr* %0)
%6 = tail call i32 @popDynArr(%struct.DynArr* %0)
%7 = fcmp olt double %5, 0.000000e+00
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([120 x i8], [120 x i8]* @str, i64 0, i64 0))
br label %12
10: ; preds = %4
%11 = tail call double @sqrt(double %5)
br label %12
12: ; preds = %10, %8
%13 = phi double [ %5, %8 ], [ %11, %10 ]
%14 = tail call i32 @pushDynArr(%struct.DynArr* %0, double %13)
br label %15
15: ; preds = %12, %1
ret void
}