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


x86 assembly (clang, -O0):
<stack_cos>:
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_cos+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)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1070 <cos@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%esi
call   1080 <stack_push@plt>
mov    -0x8(%rbp),%rdi
call   1050 <stack_ok@plt>
cmp    $0x0,%eax
jne    1214 <stack_cos+0xa4>
mov    -0x8(%rbp),%rdi
call   1060 <stack_dump@plt>
lea    0xe32(%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_cos>:
push   %rbx
mov    %rdi,%rbx
call   1050 <stack_ok@plt>
test   %eax,%eax
jne    1198 <stack_cos+0x28>
mov    %rbx,%rdi
call   1060 <stack_dump@plt>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1090 <stack_pop@plt>
call   1070 <cos@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1080 <stack_push@plt>
mov    %rbx,%rdi
call   1050 <stack_ok@plt>
test   %eax,%eax
jne    11d6 <stack_cos+0x66>
mov    %rbx,%rdi
call   1060 <stack_dump@plt>
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1040 <assert@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.Stack = type { i32 }
@.str = [48 x i8] c"INVALID STACK IN THE BEGINNING OF stack_cos!!!\0A\00"
@.str.1 = [42 x i8] c"INVALID STACK IN THE END OF stack_cos!!!\0A\00"
define i32 @stack_cos(%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 ([48 x i8], [48 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 %struct.Stack*, %struct.Stack** %2
%16 = load double, double* %3
%17 = call i32 @cos(double %16)
%18 = call i32 @stack_push(%struct.Stack* %15, i32 %17)
%19 = load %struct.Stack*, %struct.Stack** %2
%20 = call i32 @stack_ok(%struct.Stack* %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %12
%23 = load %struct.Stack*, %struct.Stack** %2
%24 = call i32 @stack_dump(%struct.Stack* %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @assert(i32* null)
br label %27
27: ; preds = %22, %12
ret i32 0
}

LLVM IR (-O2):
%struct.Stack = type { i32 }
@str = [47 x i8] c"INVALID STACK IN THE BEGINNING OF stack_cos!!!\00"
@str.2 = [41 x i8] c"INVALID STACK IN THE END OF stack_cos!!!\00"
define i32 @stack_cos(%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 i32 @cos(double %9)
%11 = tail call i32 @stack_push(%struct.Stack* %0, i32 %10)
%12 = tail call i32 @stack_ok(%struct.Stack* %0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %8
%15 = tail call i32 @stack_dump(%struct.Stack* %0)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.2, i64 0, i64 0))
%17 = tail call i32 @assert(i32* null)
br label %18
18: ; preds = %14, %8
ret i32 0
}