#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 */
int /*<<< orphan*/ fwrite(unsigned char *, unsigned int, int,
                          int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
unsigned int zipmapDecodeLength(unsigned char *);
int /*<<< orphan*/ zipmapEncodeLength(int /*<<< orphan*/ *, unsigned int);
void zipmapRepr(unsigned char *p) {
  unsigned int l;
  printf("{status %u}", *p++);
  while (1) {
    if (p[0] == 255) {
      printf("{end}");
      break;
    } else {
      unsigned char e;
      l = zipmapDecodeLength(p);
      printf("{key %u}", l);
      p += zipmapEncodeLength(NULL, l);
      fwrite(p, l, 1, stdout);
      p += l;
      l = zipmapDecodeLength(p);
      printf("{value %u}", l);
      p += zipmapEncodeLength(NULL, l);
      e = *p++;
      fwrite(p, l, 1, stdout);
      p += l + e;
      if (e) {
        printf("[");
        while (e--)
          printf(".");
        printf("]");
      }
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<zipmapRepr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movzbl (%rax),%esi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xff,%eax
jne    1191 <zipmapRepr+0x51>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12c7 <zipmapRepr+0x187>
mov    -0x8(%rbp),%rdi
call   1040 <zipmapDecodeLength@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edi
call   1050 <zipmapEncodeLength@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2e08(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <zipmapDecodeLength@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edi
call   1050 <zipmapEncodeLength@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0xd(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2d91(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0xc(%rbp),%ecx
movzbl -0xd(%rbp),%eax
add    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
cmpb   $0x0,-0xd(%rbp)
je     12bd <zipmapRepr+0x17d>
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xd(%rbp),%al
mov    %al,%cl
add    $0xff,%cl
mov    %cl,-0xd(%rbp)
cmp    $0x0,%al
je     12af <zipmapRepr+0x16f>
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1289 <zipmapRepr+0x149>
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12c2 <zipmapRepr+0x182>
jmp    116c <zipmapRepr+0x2c>
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zipmapRepr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
movzbl (%rdi),%esi
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpb   $0xff,0x1(%r12)
je     126f <zipmapRepr+0x11f>
add    $0x1,%r12
lea    0xe8c(%rip),%r14
mov    0x2e53(%rip),%r13
lea    0xe87(%rip),%r15
jmp    11b2 <zipmapRepr+0x62>
cs nopw 0x0(%rax,%rax,1)
add    %rbx,%r12
add    $0x1,%r12
cmpb   $0xff,(%r12)
je     126f <zipmapRepr+0x11f>
mov    %r12,%rdi
call   1050 <zipmapDecodeLength@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
mov    %ebp,%esi
call   1060 <zipmapEncodeLength@plt>
movslq %eax,%rbx
add    %r12,%rbx
mov    0x0(%r13),%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    %ebp,%ebp
add    %rbx,%rbp
mov    %rbp,%rdi
call   1050 <zipmapDecodeLength@plt>
mov    %eax,%ebx
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
mov    %ebx,%esi
call   1060 <zipmapEncodeLength@plt>
cltq
lea    (%rax,%rbp,1),%r12
lea    (%rax,%rbp,1),%rdi
add    $0x1,%rdi
movzbl (%rax,%rbp,1),%ebp
mov    0x0(%r13),%ecx
mov    %ebx,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
add    %ebp,%ebx
test   %ebp,%ebp
je     11a0 <zipmapRepr+0x50>
mov    $0x5b,%edi
call   1030 <putchar@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x2e,%edi
call   1030 <putchar@plt>
add    $0xff,%bpl
jne    1250 <zipmapRepr+0x100>
mov    $0x5d,%edi
call   1030 <putchar@plt>
jmp    11a0 <zipmapRepr+0x50>
lea    0xd96(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"{status %u}\00"
@.str.1 = [6 x i8] c"{end}\00"
@.str.2 = [9 x i8] c"{key %u}\00"
@stdout = global i32 0
@.str.3 = [11 x i8] c"{value %u}\00"
@.str.4 = [2 x i8] c"[\00"
@.str.5 = [2 x i8] c".\00"
@.str.6 = [2 x i8] c"]\00"
@.str.7 = [2 x i8] c"\0A\00"
define void @zipmapRepr(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i32 1
store i8* %6, i8** %2
%7 = load i8, i8* %5
%8 = zext i8 %7 to i32
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %1, %72
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = icmp eq i32 %14, 255
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %73
18: ; preds = %10
%19 = load i8*, i8** %2
%20 = call i32 @zipmapDecodeLength(i8* %19)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %3
%24 = call i32 @zipmapEncodeLength(i32* null, i32 %23)
%25 = load i8*, i8** %2
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8* %27, i8** %2
%28 = load i8*, i8** %2
%29 = load i32, i32* %3
%30 = load i32, i32* @stdout
%31 = call i32 @fwrite(i8* %28, i32 %29, i32 1, i32 %30)
%32 = load i32, i32* %3
%33 = load i8*, i8** %2
%34 = zext i32 %32 to i64
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8* %35, i8** %2
%36 = load i8*, i8** %2
%37 = call i32 @zipmapDecodeLength(i8* %36)
store i32 %37, i32* %3
%38 = load i32, i32* %3
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %3
%41 = call i32 @zipmapEncodeLength(i32* null, i32 %40)
%42 = load i8*, i8** %2
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds i8, i8* %42, i64 %43
store i8* %44, i8** %2
%45 = load i8*, i8** %2
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %2
%47 = load i8, i8* %45
store i8 %47, i8* %4
%48 = load i8*, i8** %2
%49 = load i32, i32* %3
%50 = load i32, i32* @stdout
%51 = call i32 @fwrite(i8* %48, i32 %49, i32 1, i32 %50)
%52 = load i32, i32* %3
%53 = load i8, i8* %4
%54 = zext i8 %53 to i32
%55 = add i32 %52, %54
%56 = load i8*, i8** %2
%57 = zext i32 %55 to i64
%58 = getelementptr inbounds i8, i8* %56, i64 %57
store i8* %58, i8** %2
%59 = load i8, i8* %4
%60 = icmp ne i8 %59, 0
br i1 %60, label %61, label %71
61: ; preds = %18
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %63
63: ; preds = %67, %61
%64 = load i8, i8* %4
%65 = add i8 %64, -1
store i8 %65, i8* %4
%66 = icmp ne i8 %64, 0
br i1 %66, label %67, label %69
67: ; preds = %63
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %63
69: ; preds = %63
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %71
71: ; preds = %69, %18
br label %72
72: ; preds = %71
br label %10
73: ; preds = %16
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"{status %u}\00"
@.str.1 = [6 x i8] c"{end}\00"
@.str.2 = [9 x i8] c"{key %u}\00"
@stdout = global i32 0
@.str.3 = [11 x i8] c"{value %u}\00"
define void @zipmapRepr(i8* %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = load i8, i8* %0
%4 = zext i8 %3 to i32
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i8, i8* %2
%7 = icmp eq i8 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %45, %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @putchar(i32 10)
ret void
11: ; preds = %1, %45
%12 = phi i8* [ %34, %45 ], [ %2, %1 ]
%13 = tail call i32 @zipmapDecodeLength(i8* %12)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = tail call i32 @zipmapEncodeLength(i32* null, i32 %13)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %12, i64 %16
%18 = load i32, i32* @stdout
%19 = tail call i32 @fwrite(i8* %17, i32 %13, i32 1, i32 %18)
%20 = zext i32 %13 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = tail call i32 @zipmapDecodeLength(i8* %21)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = tail call i32 @zipmapEncodeLength(i32* null, i32 %22)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %21, i64 %25
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %26
%29 = load i32, i32* @stdout
%30 = tail call i32 @fwrite(i8* %27, i32 %22, i32 1, i32 %29)
%31 = zext i8 %28 to i32
%32 = add i32 %22, %31
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %27, i64 %33
%35 = icmp eq i8 %28, 0
br i1 %35, label %45, label %36
36: ; preds = %11
%37 = tail call i32 @putchar(i32 91)
br label %38
38: ; preds = %36, %38
%39 = phi i8 [ %28, %36 ], [ %40, %38 ]
%40 = add i8 %39, -1
%41 = tail call i32 @putchar(i32 46)
%42 = icmp eq i8 %40, 0
br i1 %42, label %43, label %38
43: ; preds = %38
%44 = tail call i32 @putchar(i32 93)
br label %45
45: ; preds = %43, %11
%46 = load i8, i8* %34
%47 = icmp eq i8 %46, -1
br i1 %47, label %8, label %11
}