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

/* Variables and functions */
int /*<<< orphan*/ is_empty_stack_katcp(struct katcp_stack *);
int /*<<< orphan*/ pop_data_stack_katcp(struct katcp_stack *);
int empty_stack_katcp(struct katcp_stack *s) {
  if (s == NULL)
    return -1;
  while (!is_empty_stack_katcp(s)) {
    pop_data_stack_katcp(s);
  }
  return 0;
}


x86 assembly (clang, -O0):
<empty_stack_katcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1143 <empty_stack_katcp+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    117b <empty_stack_katcp+0x5b>
jmp    1148 <empty_stack_katcp+0x28>
mov    -0x10(%rbp),%rdi
call   1030 <is_empty_stack_katcp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1166 <empty_stack_katcp+0x46>
jmp    1174 <empty_stack_katcp+0x54>
mov    -0x10(%rbp),%rdi
call   1040 <pop_data_stack_katcp@plt>
jmp    1148 <empty_stack_katcp+0x28>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<empty_stack_katcp>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     1156 <empty_stack_katcp+0x36>
mov    %rdi,%rbx
call   1030 <is_empty_stack_katcp@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    115b <empty_stack_katcp+0x3b>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <pop_data_stack_katcp@plt>
mov    %rbx,%rdi
call   1030 <is_empty_stack_katcp@plt>
test   %eax,%eax
je     1140 <empty_stack_katcp+0x20>
jmp    115b <empty_stack_katcp+0x3b>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.katcp_stack = type { i32 }
define i32 @empty_stack_katcp(%struct.katcp_stack* %0) {
%2 = alloca i32
%3 = alloca %struct.katcp_stack*
store %struct.katcp_stack* %0, %struct.katcp_stack** %3
%4 = load %struct.katcp_stack*, %struct.katcp_stack** %3
%5 = icmp eq %struct.katcp_stack* %4, null
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 -1, i32* %2
br label %17
7: ; preds = %1
br label %8
8: ; preds = %13, %7
%9 = load %struct.katcp_stack*, %struct.katcp_stack** %3
%10 = call i32 @is_empty_stack_katcp(%struct.katcp_stack* %9)
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load %struct.katcp_stack*, %struct.katcp_stack** %3
%15 = call i32 @pop_data_stack_katcp(%struct.katcp_stack* %14)
br label %8
16: ; preds = %8
store i32 0, i32* %2
br label %17
17: ; preds = %16, %6
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
%struct.katcp_stack = type { i32 }
define i32 @empty_stack_katcp(%struct.katcp_stack* %0) {
%2 = icmp eq %struct.katcp_stack* %0, null
br i1 %2, label %10, label %3
3: ; preds = %1
%4 = tail call i32 @is_empty_stack_katcp(%struct.katcp_stack* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %3, %6
%7 = tail call i32 @pop_data_stack_katcp(%struct.katcp_stack* %0)
%8 = tail call i32 @is_empty_stack_katcp(%struct.katcp_stack* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %6, label %10
10: ; preds = %6, %3, %1
%11 = phi i32 [ -1, %1 ], [ 0, %3 ], [ 0, %6 ]
ret i32 %11
}