#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 */
unsigned int zipmapDecodeLength(unsigned char *);
int /*<<< orphan*/ zipmapRawKeyLength(unsigned char *);
int /*<<< orphan*/ zipmapRawValueLength(unsigned char *);
unsigned char *zipmapXNext(unsigned char *zm, unsigned char **key,
                           unsigned int *klen, unsigned char **value,
                           unsigned int *vlen, unsigned int *timestamp) {
  if (zm[0] == 255)
    return NULL;
  if (key) {
    *key = zm;
    *klen = zipmapDecodeLength(zm);
    *key += (((*klen) < 254) ? 1 : sizeof(unsigned int) + 1);
  }
  zm += zipmapRawKeyLength(zm);
  if (key) {
    *timestamp = *(unsigned int *)zm;
  }
  zm += sizeof(unsigned int);
  if (value) {
    *value = zm + 1;
    *vlen = zipmapDecodeLength(zm);
    *value += (((*vlen) < 254) ? 1 : sizeof(unsigned int) + 1);
  }
  zm += zipmapRawValueLength(zm);
  return zm;
}


x86 assembly (clang, -O0):
<zipmapXNext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xff,%eax
jne    116f <zipmapXNext+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    1266 <zipmapXNext+0x136>
cmpq   $0x0,-0x18(%rbp)
je     11ba <zipmapXNext+0x8a>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
call   1050 <zipmapDecodeLength@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    $0x5,%ecx
mov    $0x1,%eax
cmp    $0xfe,%edx
cmovb  %rax,%rcx
mov    -0x18(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <zipmapRawKeyLength@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ea <zipmapXNext+0xba>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1245 <zipmapXNext+0x115>
mov    -0x10(%rbp),%rcx
add    $0x1,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
call   1050 <zipmapDecodeLength@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
mov    $0x5,%ecx
mov    $0x1,%eax
cmp    $0xfe,%edx
cmovb  %rax,%rcx
mov    -0x28(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <zipmapRawValueLength@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zipmapXNext>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmpb   $0xff,(%rdi)
je     1193 <zipmapXNext+0x63>
mov    %r8,%r14
mov    %rcx,%r15
mov    %rsi,%r13
mov    %rdi,%rbx
test   %rsi,%rsi
je     1197 <zipmapXNext+0x67>
mov    %r9,%r12
mov    %rdx,%rbp
mov    %rbx,0x0(%r13)
mov    %rbx,%rdi
call   1050 <zipmapDecodeLength@plt>
mov    %eax,0x0(%rbp)
xor    %ecx,%ecx
cmp    $0xfe,%eax
setae  %cl
mov    0x0(%r13),%rax
lea    (%rax,%rcx,4),%rax
add    $0x1,%rax
mov    %rax,0x0(%r13)
mov    %rbx,%rdi
call   1040 <zipmapRawKeyLength@plt>
cltq
mov    (%rbx,%rax,1),%ecx
mov    %ecx,(%r12)
jmp    11a1 <zipmapXNext+0x71>
xor    %eax,%eax
jmp    11e4 <zipmapXNext+0xb4>
mov    %rbx,%rdi
call   1040 <zipmapRawKeyLength@plt>
cltq
add    %rax,%rbx
add    $0x4,%rbx
test   %r15,%r15
je     11d7 <zipmapXNext+0xa7>
lea    0x1(%rbx),%rax
mov    %rax,(%r15)
mov    %rbx,%rdi
call   1050 <zipmapDecodeLength@plt>
mov    %eax,(%r14)
xor    %ecx,%ecx
cmp    $0xfe,%eax
setae  %cl
mov    (%r15),%rax
lea    (%rax,%rcx,4),%rax
add    $0x1,%rax
mov    %rax,(%r15)
mov    %rbx,%rdi
call   1030 <zipmapRawValueLength@plt>
cltq
add    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @zipmapXNext(i8* %0, i8** %1, i32* nocapture writeonly %2, i8** %3, i32* nocapture writeonly %4, i32* nocapture writeonly %5) {
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, -1
br i1 %8, label %41, label %9
9: ; preds = %6
%10 = icmp eq i8** %1, null
br i1 %10, label %11, label %14
11: ; preds = %9
%12 = tail call i32 @zipmapRawKeyLength(i8* %0)
%13 = sext i32 %12 to i64
br label %25
14: ; preds = %9
store i8* %0, i8** %1
%15 = tail call i32 @zipmapDecodeLength(i8* %0)
store i32 %15, i32* %2
%16 = icmp ult i32 %15, 254
%17 = select i1 %16, i64 1, i64 5
%18 = load i8*, i8** %1
%19 = getelementptr inbounds i8, i8* %18, i64 %17
store i8* %19, i8** %1
%20 = tail call i32 @zipmapRawKeyLength(i8* %0)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = bitcast i8* %22 to i32*
%24 = load i32, i32* %23
store i32 %24, i32* %5
br label %25
25: ; preds = %11, %14
%26 = phi i64 [ %13, %11 ], [ %21, %14 ]
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = getelementptr inbounds i8, i8* %27, i64 4
%29 = icmp eq i8** %3, null
br i1 %29, label %37, label %30
30: ; preds = %25
%31 = getelementptr inbounds i8, i8* %28, i64 1
store i8* %31, i8** %3
%32 = tail call i32 @zipmapDecodeLength(i8* %28)
store i32 %32, i32* %4
%33 = icmp ult i32 %32, 254
%34 = select i1 %33, i64 1, i64 5
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i64 %34
store i8* %36, i8** %3
br label %37
37: ; preds = %30, %25
%38 = tail call i32 @zipmapRawValueLength(i8* %28)
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %28, i64 %39
br label %41
41: ; preds = %6, %37
%42 = phi i8* [ %40, %37 ], [ null, %6 ]
ret i8* %42
}