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


x86 assembly (clang, -O0):
<zipmapXGet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rcx
call   1040 <zipmapXLookupRaw@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1184 <zipmapXGet+0x54>
movl   $0x0,-0x4(%rbp)
jmp    1223 <zipmapXGet+0xf3>
mov    -0x40(%rbp),%rdi
call   1030 <zipmapRawKeyLength@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <zipmapDecodeLength@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
mov    $0x5,%eax
mov    $0x1,%edx
cmp    $0xfe,%esi
cmovb  %rdx,%rax
add    %rax,%rcx
add    $0x1,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x44(%rbp),%eax
cmp    -0x34(%rbp),%eax
jae    121c <zipmapXGet+0xec>
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1223 <zipmapXGet+0xf3>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zipmapXGet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r15d
mov    %r8,%r14
mov    %rcx,%r12
mov    (%rdi),%rdi
xor    %ebp,%ebp
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <zipmapXLookupRaw@plt>
test   %rax,%rax
je     11b1 <zipmapXGet+0x81>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <zipmapRawKeyLength@plt>
cltq
lea    (%rbx,%rax,1),%rbp
mov    (%rbx,%rax,1),%r13d
lea    (%rbx,%rax,1),%rdi
add    $0x4,%rdi
call   1050 <zipmapDecodeLength@plt>
mov    %eax,(%r14)
xor    %ecx,%ecx
cmp    $0xfe,%eax
setae  %cl
lea    0x6(,%rcx,4),%rax
add    %rbp,%rax
mov    %rax,(%r12)
mov    $0x1,%ebp
cmp    %r15d,%r13d
jae    11b1 <zipmapXGet+0x81>
movl   $0x0,(%r14)
movq   $0x0,(%r12)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @zipmapXGet(i8** %0, i8* %1, i32 %2, i8** %3, i32* %4, i32 %5) {
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8**
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i8*
%15 = 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
%16 = load i8**, i8*** %8
%17 = load i8*, i8** %16
%18 = load i8*, i8** %9
%19 = load i32, i32* %10
%20 = call i8* @zipmapXLookupRaw(i8* %17, i8* %18, i32 %19, i32* null, i32* null)
store i8* %20, i8** %14
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %6
store i32 0, i32* %7
br label %53
23: ; preds = %6
%24 = load i8*, i8** %14
%25 = call i32 @zipmapRawKeyLength(i8* %24)
%26 = load i8*, i8** %14
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds i8, i8* %26, i64 %27
store i8* %28, i8** %14
%29 = load i8*, i8** %14
%30 = bitcast i8* %29 to i32*
%31 = load i32, i32* %30
store i32 %31, i32* %15
%32 = load i8*, i8** %14
%33 = getelementptr inbounds i8, i8* %32, i64 4
store i8* %33, i8** %14
%34 = load i8*, i8** %14
%35 = call i32 @zipmapDecodeLength(i8* %34)
%36 = load i32*, i32** %12
store i32 %35, i32* %36
%37 = load i8*, i8** %14
%38 = load i32*, i32** %12
%39 = load i32, i32* %38
%40 = icmp ult i32 %39, 254
%41 = zext i1 %40 to i64
%42 = select i1 %40, i64 1, i64 5
%43 = getelementptr inbounds i8, i8* %37, i64 %42
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = load i8**, i8*** %11
store i8* %44, i8** %45
%46 = load i32, i32* %15
%47 = load i32, i32* %13
%48 = icmp ult i32 %46, %47
br i1 %48, label %49, label %52
49: ; preds = %23
%50 = load i32*, i32** %12
store i32 0, i32* %50
%51 = load i8**, i8*** %11
store i8* null, i8** %51
store i32 0, i32* %7
br label %53
52: ; preds = %23
store i32 1, i32* %7
br label %53
53: ; preds = %52, %49, %22
%54 = load i32, i32* %7
ret i32 %54
}

LLVM IR (-O2):
define i32 @zipmapXGet(i8** nocapture %0, i8* %1, i32 %2, i8** nocapture writeonly %3, i32* nocapture writeonly %4, i32 %5) {
%7 = load i8*, i8** %0
%8 = tail call i8* @zipmapXLookupRaw(i8* %7, i8* %1, i32 %2, i32* null, i32* null)
%9 = icmp eq i8* %8, null
br i1 %9, label %24, label %10
10: ; preds = %6
%11 = tail call i32 @zipmapRawKeyLength(i8* %8)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %8, i64 %12
%14 = bitcast i8* %13 to i32*
%15 = load i32, i32* %14
%16 = getelementptr inbounds i8, i8* %13, i64 4
%17 = tail call i32 @zipmapDecodeLength(i8* %16)
store i32 %17, i32* %4
%18 = icmp ult i32 %17, 254
%19 = select i1 %18, i64 1, i64 5
%20 = getelementptr inbounds i8, i8* %16, i64 %19
%21 = getelementptr inbounds i8, i8* %20, i64 1
store i8* %21, i8** %3
%22 = icmp ult i32 %15, %5
br i1 %22, label %23, label %24
23: ; preds = %10
store i32 0, i32* %4
store i8* null, i8** %3
br label %24
24: ; preds = %23, %10, %6
%25 = phi i32 [ 0, %6 ], [ 0, %23 ], [ 1, %10 ]
ret i32 %25
}