#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 */

/* Variables and functions */
char *STACK_POP(char *stack_ptr, char *start_of_stack) {
  if (stack_ptr == start_of_stack) {
    return NULL;
  }
  stack_ptr -= 2;
  while (*stack_ptr && (stack_ptr >= start_of_stack)) {
    stack_ptr--;
  }
  return stack_ptr + 1;
}


x86 assembly (clang, -O0):
<STACK_POP>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    1127 <STACK_POP+0x27>
movq   $0x0,-0x8(%rbp)
jmp    1183 <STACK_POP+0x83>
mov    -0x10(%rbp),%rax
add    $0xfffffffffffffffe,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     1156 <STACK_POP+0x56>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
setae  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1166 <STACK_POP+0x66>
jmp    1177 <STACK_POP+0x77>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1133 <STACK_POP+0x33>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<STACK_POP>:
cmp    %rsi,%rdi
je     1126 <STACK_POP+0x26>
add    $0xfffffffffffffffe,%rdi
nopl   0x0(%rax)
lea    -0x1(%rdi),%rax
cmp    %rsi,%rdi
jb     1121 <STACK_POP+0x21>
cmpb   $0x0,(%rdi)
mov    %rax,%rdi
jne    1110 <STACK_POP+0x10>
add    $0x2,%rax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i8* @STACK_POP(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %4
%7 = load i8*, i8** %5
%8 = icmp eq i8* %6, %7
br i1 %8, label %9, label %10
9: ; preds = %2
store i8* null, i8** %3
br label %30
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 -2
store i8* %12, i8** %4
br label %13
13: ; preds = %24, %10
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = load i8*, i8** %5
%21 = icmp uge i8* %19, %20
br label %22
22: ; preds = %18, %13
%23 = phi i1 [ false, %13 ], [ %21, %18 ]
br i1 %23, label %24, label %27
24: ; preds = %22
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i32 -1
store i8* %26, i8** %4
br label %13
27: ; preds = %22
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8* %29, i8** %3
br label %30
30: ; preds = %27, %9
%31 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
define i8* @STACK_POP(i8* %0, i8* readnone %1) {
%3 = icmp eq i8* %0, %1
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8, i8* %0, i64 -2
br label %6
6: ; preds = %6, %4
%7 = phi i8* [ %5, %4 ], [ %12, %6 ]
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
%10 = icmp uge i8* %7, %1
%11 = and i1 %10, %9
%12 = getelementptr inbounds i8, i8* %7, i64 -1
br i1 %11, label %6, label %13
13: ; preds = %6
%14 = getelementptr inbounds i8, i8* %7, i64 1
br label %15
15: ; preds = %2, %13
%16 = phi i8* [ %14, %13 ], [ null, %2 ]
ret i8* %16
}