#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 */
typedef unsigned char *zl;
typedef scalar_t__ uint32_t;
typedef int /*<<< orphan*/ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ memcpy(unsigned int *, char *, int);
unsigned char *ziplistPrev(unsigned char *zl, unsigned char *p) {
  unsigned int prevlensize, prevlen = 0;
  if (p[0] == 255) {
    p = ((zl) + ((*((uint32_t *)((zl) + sizeof(uint32_t))))));
    return (p[0] == 255) ? NULL : p;
  } else if (p == ((zl) + (sizeof(uint32_t) * 2 + sizeof(uint16_t)))) {
    return NULL;
  } else {
    do {
      do {
        if ((p)[0] < 254) {
          (prevlensize) = 1;
        } else {
          (prevlensize) = 5;
        }
      } while (0);
      ;
      if ((prevlensize) == 1) {
        (prevlen) = (p)[0];
      } else if ((prevlensize) == 5) {
        assert(sizeof((prevlensize)) == 4);
        memcpy(&(prevlen), ((char *)(p)) + 1, 4);
      }
    } while (0);
    ;
    assert(prevlen > 0);
    return p - prevlen;
  }
}


x86 assembly (clang, -O0):
<ziplistPrev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xff,%eax
jne    118b <ziplistPrev+0x6b>
mov    -0x10(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    0x8(%rcx),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xff,%eax
jne    1176 <ziplistPrev+0x56>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    117e <ziplistPrev+0x5e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1254 <ziplistPrev+0x134>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    $0x14,%rcx
cmp    %rcx,%rax
jne    11ad <ziplistPrev+0x8d>
movq   $0x0,-0x8(%rbp)
jmp    1254 <ziplistPrev+0x134>
jmp    11b2 <ziplistPrev+0x92>
jmp    11b7 <ziplistPrev+0x97>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xfe,%eax
jge    11d5 <ziplistPrev+0xb5>
movl   $0x1,-0x1c(%rbp)
jmp    11dc <ziplistPrev+0xbc>
movl   $0x5,-0x1c(%rbp)
jmp    11e1 <ziplistPrev+0xc1>
cmpl   $0x1,-0x1c(%rbp)
jne    11fa <ziplistPrev+0xda>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    1229 <ziplistPrev+0x109>
cmpl   $0x5,-0x1c(%rbp)
jne    1224 <ziplistPrev+0x104>
mov    $0x1,%edi
call   1030 <assert@plt>
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
lea    -0x20(%rbp),%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
jmp    1229 <ziplistPrev+0x109>
jmp    122e <ziplistPrev+0x10e>
cmpl   $0x0,-0x20(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%edx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ziplistPrev>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
movzbl (%rsi),%eax
cmp    $0xff,%eax
je     114d <ziplistPrev+0x2d>
mov    %rsi,%rbx
add    $0x14,%rdi
cmp    %rsi,%rdi
je     1161 <ziplistPrev+0x41>
cmp    $0xfd,%al
ja     1165 <ziplistPrev+0x45>
mov    %eax,0xc(%rsp)
jmp    1186 <ziplistPrev+0x66>
mov    0x8(%rdi),%rax
lea    (%rdi,%rax,1),%rcx
xor    %ebx,%ebx
cmpb   $0xff,(%rdi,%rax,1)
cmovne %rcx,%rbx
jmp    119a <ziplistPrev+0x7a>
xor    %ebx,%ebx
jmp    119a <ziplistPrev+0x7a>
mov    $0x1,%edi
call   1030 <assert@plt>
lea    0x1(%rbx),%rsi
lea    0xc(%rsp),%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    0xc(%rsp),%eax
xor    %edi,%edi
test   %eax,%eax
setne  %dil
call   1030 <assert@plt>
mov    0xc(%rsp),%eax
sub    %rax,%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i8* @ziplistPrev(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %7
%8 = load i8*, i8** %5
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = icmp eq i32 %11, 255
br i1 %12, label %13, label %30
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 8
%17 = bitcast i8* %16 to i64*
%18 = load i64, i64* %17
%19 = getelementptr inbounds i8, i8* %14, i64 %18
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = icmp eq i32 %23, 255
br i1 %24, label %25, label %26
25: ; preds = %13
br label %28
26: ; preds = %13
%27 = load i8*, i8** %5
br label %28
28: ; preds = %26, %25
%29 = phi i8* [ null, %25 ], [ %27, %26 ]
store i8* %29, i8** %3
br label %75
30: ; preds = %2
%31 = load i8*, i8** %5
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 20
%34 = icmp eq i8* %31, %33
br i1 %34, label %35, label %36
35: ; preds = %30
store i8* null, i8** %3
br label %75
36: ; preds = %30
br label %37
37: ; preds = %36
br label %38
38: ; preds = %37
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i64 0
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = icmp slt i32 %42, 254
br i1 %43, label %44, label %45
44: ; preds = %38
store i32 1, i32* %6
br label %46
45: ; preds = %38
store i32 5, i32* %6
br label %46
46: ; preds = %45, %44
br label %47
47: ; preds = %46
%48 = load i32, i32* %6
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %55
50: ; preds = %47
%51 = load i8*, i8** %5
%52 = getelementptr inbounds i8, i8* %51, i64 0
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
store i32 %54, i32* %7
br label %64
55: ; preds = %47
%56 = load i32, i32* %6
%57 = icmp eq i32 %56, 5
br i1 %57, label %58, label %63
58: ; preds = %55
%59 = call i32 @assert(i32 1)
%60 = load i8*, i8** %5
%61 = getelementptr inbounds i8, i8* %60, i64 1
%62 = call i32 @memcpy(i32* %7, i8* %61, i32 4)
br label %63
63: ; preds = %58, %55
br label %64
64: ; preds = %63, %50
br label %65
65: ; preds = %64
%66 = load i32, i32* %7
%67 = icmp ugt i32 %66, 0
%68 = zext i1 %67 to i32
%69 = call i32 @assert(i32 %68)
%70 = load i8*, i8** %5
%71 = load i32, i32* %7
%72 = zext i32 %71 to i64
%73 = sub i64 0, %72
%74 = getelementptr inbounds i8, i8* %70, i64 %73
store i8* %74, i8** %3
br label %75
75: ; preds = %65, %35, %28
%76 = load i8*, i8** %3
ret i8* %76
}

LLVM IR (-O2):
define i8* @ziplistPrev(i8* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, -1
br i1 %6, label %7, label %15
7: ; preds = %2
%8 = getelementptr inbounds i8, i8* %0, i64 8
%9 = bitcast i8* %8 to i64*
%10 = load i64, i64* %9
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, -1
%14 = select i1 %13, i8* null, i8* %11
br label %36
15: ; preds = %2
%16 = getelementptr inbounds i8, i8* %0, i64 20
%17 = icmp eq i8* %16, %1
br i1 %17, label %36, label %18
18: ; preds = %15
%19 = icmp ult i8 %5, -2
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = zext i8 %5 to i32
store i32 %21, i32* %3
br label %27
22: ; preds = %18
%23 = tail call i32 @assert(i32 1)
%24 = getelementptr inbounds i8, i8* %1, i64 1
%25 = call i32 @memcpy(i32* %3, i8* %24, i32 4)
%26 = load i32, i32* %3
br label %27
27: ; preds = %22, %20
%28 = phi i32 [ %26, %22 ], [ %21, %20 ]
%29 = icmp ne i32 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load i32, i32* %3
%33 = zext i32 %32 to i64
%34 = sub nsw i64 0, %33
%35 = getelementptr inbounds i8, i8* %1, i64 %34
br label %36
36: ; preds = %15, %27, %7
%37 = phi i8* [ %14, %7 ], [ %35, %27 ], [ null, %15 ]
ret i8* %37
}