#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*/ stack_dump(struct Stack *);
int /*<<< orphan*/ stack_ok(struct Stack *);
double stack_pop(struct Stack *);
int /*<<< orphan*/ stack_push(struct Stack *, double);
int stack_div(struct Stack *stk_p) {
  if (!stack_ok(stk_p)) {
    stack_dump(stk_p);
    printf("INVALID STACK IN THE BEGINNING OF stack_div!!!\n");
    assert(NULL);
  }
  double operand1 = -666;
  double operand2 = -666;
  operand1 = stack_pop(stk_p);
  operand2 = stack_pop(stk_p);
  if (operand2 == 0) {
    printf("DIVISION BY ZERO IN stack_div\n");
    assert(NULL);
  }
  stack_push(stk_p, operand1 / operand2);
  if (!stack_ok(stk_p)) {
    stack_dump(stk_p);
    printf("INVALID STACK IN THE END OF stack_div!!!\n");
    assert(NULL);
  }
  return 0;
}


x86 assembly (clang, -O0):
<stack_div>:
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    119c <stack_div+0x3c>
mov    -0x8(%rbp),%rdi
call   1060 <stack_dump@plt>
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <assert@plt>
movsd  0xe5c(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe4f(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <stack_pop@plt>
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <stack_pop@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ff <stack_div+0x9f>
jp     11ff <stack_div+0x9f>
lea    0xe47(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1070 <stack_push@plt>
mov    -0x8(%rbp),%rdi
call   1050 <stack_ok@plt>
cmp    $0x0,%eax
jne    1242 <stack_div+0xe2>
mov    -0x8(%rbp),%rdi
call   1060 <stack_dump@plt>
lea    0xe23(%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_div>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1050 <stack_ok@plt>
test   %eax,%eax
jne    118c <stack_div+0x2c>
mov    %rbx,%rdi
call   1060 <stack_dump@plt>
lea    0xe80(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1080 <stack_pop@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1080 <stack_pop@plt>
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    11cf <stack_div+0x6f>
jp     11cf <stack_div+0x6f>
lea    0xe9f(%rip),%rdi
movsd  %xmm1,(%rsp)
call   1030 <puts@plt>
xor    %edi,%edi
call   1040 <assert@plt>
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm0
mov    %rbx,%rdi
call   1070 <stack_push@plt>
mov    %rbx,%rdi
call   1050 <stack_ok@plt>
test   %eax,%eax
jne    1208 <stack_div+0xa8>
mov    %rbx,%rdi
call   1060 <stack_dump@plt>
lea    0xe33(%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 = [48 x i8] c"INVALID STACK IN THE BEGINNING OF stack_div!!!\0A\00"
@.str.1 = [31 x i8] c"DIVISION BY ZERO IN stack_div\0A\00"
@.str.2 = [42 x i8] c"INVALID STACK IN THE END OF stack_div!!!\0A\00"
define i32 @stack_div(%struct.Stack* %0) {
%2 = alloca %struct.Stack*
%3 = alloca double
%4 = alloca double
store %struct.Stack* %0, %struct.Stack** %2
%5 = load %struct.Stack*, %struct.Stack** %2
%6 = call i32 @stack_ok(%struct.Stack* %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = load %struct.Stack*, %struct.Stack** %2
%10 = call i32 @stack_dump(%struct.Stack* %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @assert(i32* null)
br label %13
13: ; preds = %8, %1
store double -6.660000e+02, double* %3
store double -6.660000e+02, double* %4
%14 = load %struct.Stack*, %struct.Stack** %2
%15 = call double @stack_pop(%struct.Stack* %14)
store double %15, double* %3
%16 = load %struct.Stack*, %struct.Stack** %2
%17 = call double @stack_pop(%struct.Stack* %16)
store double %17, double* %4
%18 = load double, double* %4
%19 = fcmp oeq double %18, 0.000000e+00
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @assert(i32* null)
br label %23
23: ; preds = %20, %13
%24 = load %struct.Stack*, %struct.Stack** %2
%25 = load double, double* %3
%26 = load double, double* %4
%27 = fdiv double %25, %26
%28 = call i32 @stack_push(%struct.Stack* %24, double %27)
%29 = load %struct.Stack*, %struct.Stack** %2
%30 = call i32 @stack_ok(%struct.Stack* %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %37, label %32
32: ; preds = %23
%33 = load %struct.Stack*, %struct.Stack** %2
%34 = call i32 @stack_dump(%struct.Stack* %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @assert(i32* null)
br label %37
37: ; preds = %32, %23
ret i32 0
}

LLVM IR (-O2):
%struct.Stack = type { i32 }
@str = [47 x i8] c"INVALID STACK IN THE BEGINNING OF stack_div!!!\00"
@str.3 = [41 x i8] c"INVALID STACK IN THE END OF stack_div!!!\00"
@str.4 = [30 x i8] c"DIVISION BY ZERO IN stack_div\00"
define i32 @stack_div(%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 ([47 x i8], [47 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 = tail call double @stack_pop(%struct.Stack* %0)
%11 = fcmp oeq double %10, 0.000000e+00
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.4, i64 0, i64 0))
%14 = tail call i32 @assert(i32* null)
br label %15
15: ; preds = %12, %8
%16 = fdiv double %9, %10
%17 = tail call i32 @stack_push(%struct.Stack* %0, double %16)
%18 = tail call i32 @stack_ok(%struct.Stack* %0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = tail call i32 @stack_dump(%struct.Stack* %0)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.3, i64 0, i64 0))
%23 = tail call i32 @assert(i32* null)
br label %24
24: ; preds = %20, %15
ret i32 0
}