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


x86 assembly (clang, -O0):
<zipmapGet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <zipmapLookupRaw@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1179 <zipmapGet+0x49>
movl   $0x0,-0x4(%rbp)
jmp    11d6 <zipmapGet+0xa6>
mov    -0x38(%rbp),%rdi
call   1030 <zipmapRawKeyLength@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <zipmapDecodeLength@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%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)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zipmapGet>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %r8,%r15
mov    %rcx,%r14
xor    %r12d,%r12d
xor    %ecx,%ecx
call   1040 <zipmapLookupRaw@plt>
test   %rax,%rax
je     1184 <zipmapGet+0x54>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <zipmapRawKeyLength@plt>
movslq %eax,%r12
add    %rbx,%r12
mov    %r12,%rdi
call   1050 <zipmapDecodeLength@plt>
mov    %eax,(%r15)
xor    %ecx,%ecx
cmp    $0xfe,%eax
setae  %cl
lea    (%r12,%rcx,4),%rax
add    $0x2,%rax
mov    %rax,(%r14)
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @zipmapGet(i8* %0, i8* %1, i32 %2, i8** %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8**
%11 = alloca i32*
%12 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8** %3, i8*** %10
store i32* %4, i32** %11
%13 = load i8*, i8** %7
%14 = load i8*, i8** %8
%15 = load i32, i32* %9
%16 = call i8* @zipmapLookupRaw(i8* %13, i8* %14, i32 %15, i32* null)
store i8* %16, i8** %12
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %5
store i32 0, i32* %6
br label %37
19: ; preds = %5
%20 = load i8*, i8** %12
%21 = call i32 @zipmapRawKeyLength(i8* %20)
%22 = load i8*, i8** %12
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds i8, i8* %22, i64 %23
store i8* %24, i8** %12
%25 = load i8*, i8** %12
%26 = call i32 @zipmapDecodeLength(i8* %25)
%27 = load i32*, i32** %11
store i32 %26, i32* %27
%28 = load i8*, i8** %12
%29 = load i32*, i32** %11
%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 = getelementptr inbounds i8, i8* %28, i64 %33
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8**, i8*** %10
store i8* %35, i8** %36
store i32 1, i32* %6
br label %37
37: ; preds = %19, %18
%38 = load i32, i32* %6
ret i32 %38
}

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