#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 Stack {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sqrt(double);
int /*<<< orphan*/ stack_dump(struct Stack *);
int /*<<< orphan*/ stack_ok(struct Stack *);
double stack_pop(struct Stack *);
int /*<<< orphan*/ stack_push(struct Stack *, int /*<<< orphan*/);
int stack_sqrt(struct Stack *stk_p) {
  if (!stack_ok(stk_p)) {
    stack_dump(stk_p);
    printf("INVALID STACK IN THE BEGINNING OF stack_sqrt!!!\n");
    assert(NULL);
  }
  double operand1 = -666;
  operand1 = stack_pop(stk_p);
  if (operand1 < 0) {
    printf("TRYING OF TAKING ROOT OF NEGATIVE NUMBER\n");
    assert(NULL);
  }
  stack_push(stk_p, sqrt(operand1));
  if (!stack_ok(stk_p)) {
    stack_dump(stk_p);
    printf("INVALID STACK IN THE END OF stack_sqrt!!!\n");
    assert(NULL);
  }
  return 0;
}


x86 assembly (clang, -O0):
<stack_sqrt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <stack_ok@plt>
cmp    $0x0,%eax
jne    11ac <stack_sqrt+0x3c>
mov    -0x8(%rbp),%rdi
call   1060 <stack_dump@plt>
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <assert@plt>
movsd  0xe4c(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <stack_pop@plt>
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11ea <stack_sqrt+0x7a>
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1080 <sqrt@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%esi
call   1070 <stack_push@plt>
mov    -0x8(%rbp),%rdi
call   1050 <stack_ok@plt>
cmp    $0x0,%eax
jne    1237 <stack_sqrt+0xc7>
mov    -0x8(%rbp),%rdi
call   1060 <stack_dump@plt>
lea    0xe3a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stack_sqrt>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1050 <stack_ok@plt>
test   %eax,%eax
jne    119c <stack_sqrt+0x2c>
mov    %rbx,%rdi
call   1060 <stack_dump@plt>
lea    0xe70(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1090 <stack_pop@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    11cd <stack_sqrt+0x5d>
lea    0xea5(%rip),%rdi
movsd  %xmm0,0x8(%rsp)
call   1030 <puts@plt>
xor    %edi,%edi
call   1040 <assert@plt>
movsd  0x8(%rsp),%xmm0
call   1080 <sqrt@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <stack_push@plt>
mov    %rbx,%rdi
call   1050 <stack_ok@plt>
test   %eax,%eax
jne    1203 <stack_sqrt+0x93>
mov    %rbx,%rdi
call   1060 <stack_dump@plt>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.Stack = type { i32 }
@.str = [49 x i8] c"INVALID STACK IN THE BEGINNING OF stack_sqrt!!!\0A\00"
@.str.1 = [42 x i8] c"TRYING OF TAKING ROOT OF NEGATIVE NUMBER\0A\00"
@.str.2 = [43 x i8] c"INVALID STACK IN THE END OF stack_sqrt!!!\0A\00"
define i32 @stack_sqrt(%struct.Stack* %0) {
%2 = alloca %struct.Stack*
%3 = alloca double
store %struct.Stack* %0, %struct.Stack** %2
%4 = load %struct.Stack*, %struct.Stack** %2
%5 = call i32 @stack_ok(%struct.Stack* %4)
%6 = icmp ne i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = load %struct.Stack*, %struct.Stack** %2
%9 = call i32 @stack_dump(%struct.Stack* %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @assert(i32* null)
br label %12
12: ; preds = %7, %1
store double -6.660000e+02, double* %3
%13 = load %struct.Stack*, %struct.Stack** %2
%14 = call double @stack_pop(%struct.Stack* %13)
store double %14, double* %3
%15 = load double, double* %3
%16 = fcmp olt double %15, 0.000000e+00
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @assert(i32* null)
br label %20
20: ; preds = %17, %12
%21 = load %struct.Stack*, %struct.Stack** %2
%22 = load double, double* %3
%23 = call i32 @sqrt(double %22)
%24 = call i32 @stack_push(%struct.Stack* %21, i32 %23)
%25 = load %struct.Stack*, %struct.Stack** %2
%26 = call i32 @stack_ok(%struct.Stack* %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %20
%29 = load %struct.Stack*, %struct.Stack** %2
%30 = call i32 @stack_dump(%struct.Stack* %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @assert(i32* null)
br label %33
33: ; preds = %28, %20
ret i32 0
}

LLVM IR (-O2):
%struct.Stack = type { i32 }
@str = [48 x i8] c"INVALID STACK IN THE BEGINNING OF stack_sqrt!!!\00"
@str.3 = [42 x i8] c"INVALID STACK IN THE END OF stack_sqrt!!!\00"
@str.4 = [41 x i8] c"TRYING OF TAKING ROOT OF NEGATIVE NUMBER\00"
define i32 @stack_sqrt(%struct.Stack* %0) {
%2 = tail call i32 @stack_ok(%struct.Stack* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @stack_dump(%struct.Stack* %0)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @assert(i32* null)
br label %8
8: ; preds = %4, %1
%9 = tail call double @stack_pop(%struct.Stack* %0)
%10 = fcmp olt double %9, 0.000000e+00
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.4, i64 0, i64 0))
%13 = tail call i32 @assert(i32* null)
br label %14
14: ; preds = %11, %8
%15 = tail call i32 @sqrt(double %9)
%16 = tail call i32 @stack_push(%struct.Stack* %0, i32 %15)
%17 = tail call i32 @stack_ok(%struct.Stack* %0)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = tail call i32 @stack_dump(%struct.Stack* %0)
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.3, i64 0, i64 0))
%22 = tail call i32 @assert(i32* null)
br label %23
23: ; preds = %19, %14
ret i32 0
}