#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 */
scalar_t__ fwrite(unsigned char *, unsigned int, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
unsigned int zipmapDecodeLength(unsigned char *);
int /*<<< orphan*/ zipmapEncodeLength(int /*<<< orphan*/ *, unsigned int);
void zipmapXRepr(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);
      if (l != 0 && fwrite(p, l, 1, stdout) == 0)
        perror("fwrite");
      p += l;
      l = zipmapDecodeLength(p);
      printf("{value %u}", l);
      p += zipmapEncodeLength(NULL, l);
      e = *p++;
      if (l != 0 && fwrite(p, l, 1, stdout) == 0)
        perror("fwrite");
      p += l + e;
      if (e) {
        printf("[");
        while (e--)
          printf(".");
        printf("]");
      }
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<zipmapXRepr>:
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    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xff,%eax
jne    11a1 <zipmapXRepr+0x51>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1317 <zipmapXRepr+0x1c7>
mov    -0x8(%rbp),%rdi
call   1040 <zipmapDecodeLength@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <zipmapEncodeLength@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1214 <zipmapXRepr+0xc4>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2dee(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   1070 <fwrite@plt>
cmp    $0x0,%rax
jne    1214 <zipmapXRepr+0xc4>
lea    0xe0c(%rip),%rdi
call   1050 <perror@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    0xde8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <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)
cmpl   $0x0,-0xc(%rbp)
je     12ab <zipmapXRepr+0x15b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2d57(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   1070 <fwrite@plt>
cmp    $0x0,%rax
jne    12ab <zipmapXRepr+0x15b>
lea    0xd75(%rip),%rdi
call   1050 <perror@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     130d <zipmapXRepr+0x1bd>
lea    0xd5b(%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     12ff <zipmapXRepr+0x1af>
lea    0xd3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d9 <zipmapXRepr+0x189>
lea    0xd2b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1312 <zipmapXRepr+0x1c2>
jmp    117c <zipmapXRepr+0x2c>
lea    0xd15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zipmapXRepr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
movzbl (%rdi),%esi
lea    0xe88(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpb   $0xff,0x1(%r13)
je     12ad <zipmapXRepr+0x14d>
add    $0x1,%r13
lea    0xe7d(%rip),%r14
lea    0xe86(%rip),%r12
mov    0x2e3d(%rip),%r15
jmp    11bb <zipmapXRepr+0x5b>
cs nopw 0x0(%rax,%rax,1)
nop
cmpb   $0xff,0x0(%r13)
je     12ad <zipmapXRepr+0x14d>
mov    %r13,%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   1070 <zipmapEncodeLength@plt>
movslq %eax,%rbx
add    %r13,%rbx
test   %ebp,%ebp
je     11ff <zipmapXRepr+0x9f>
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
test   %rax,%rax
je     128e <zipmapXRepr+0x12e>
mov    %ebp,%eax
add    %rax,%rbx
mov    %rbx,%rdi
call   1050 <zipmapDecodeLength@plt>
mov    %eax,%ebp
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
mov    %ebp,%esi
call   1070 <zipmapEncodeLength@plt>
cltq
lea    (%rax,%rbx,1),%r13
add    $0x1,%r13
mov    (%rax,%rbx,1),%bl
test   %ebp,%ebp
je     124b <zipmapXRepr+0xeb>
mov    (%r15),%ecx
mov    %r13,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
test   %rax,%rax
je     129f <zipmapXRepr+0x13f>
movzbl %bl,%eax
add    %eax,%ebp
add    %rbp,%r13
test   %al,%al
je     11b0 <zipmapXRepr+0x50>
mov    $0x5b,%edi
call   1030 <putchar@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x2e,%edi
call   1030 <putchar@plt>
add    $0xff,%bl
jne    1270 <zipmapXRepr+0x110>
mov    $0x5d,%edi
call   1030 <putchar@plt>
jmp    11b0 <zipmapXRepr+0x50>
lea    0xd86(%rip),%rdi
call   1060 <perror@plt>
jmp    11ff <zipmapXRepr+0x9f>
lea    0xd75(%rip),%rdi
call   1060 <perror@plt>
jmp    124b <zipmapXRepr+0xeb>
lea    0xd58(%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 = [7 x i8] c"fwrite\00"
@.str.4 = [11 x i8] c"{value %u}\00"
@.str.5 = [2 x i8] c"[\00"
@.str.6 = [2 x i8] c".\00"
@.str.7 = [2 x i8] c"]\00"
@.str.8 = [2 x i8] c"\0A\00"
define void @zipmapXRepr(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, %86
%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 %87
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 i32, i32* %3
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %18
%31 = load i8*, i8** %2
%32 = load i32, i32* %3
%33 = load i32, i32* @stdout
%34 = call i64 @fwrite(i8* %31, i32 %32, i32 1, i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %36, %30, %18
%39 = load i32, i32* %3
%40 = load i8*, i8** %2
%41 = zext i32 %39 to i64
%42 = getelementptr inbounds i8, i8* %40, i64 %41
store i8* %42, i8** %2
%43 = load i8*, i8** %2
%44 = call i32 @zipmapDecodeLength(i8* %43)
store i32 %44, i32* %3
%45 = load i32, i32* %3
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %3
%48 = call i32 @zipmapEncodeLength(i32* null, i32 %47)
%49 = load i8*, i8** %2
%50 = sext i32 %48 to i64
%51 = getelementptr inbounds i8, i8* %49, i64 %50
store i8* %51, i8** %2
%52 = load i8*, i8** %2
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %2
%54 = load i8, i8* %52
store i8 %54, i8* %4
%55 = load i32, i32* %3
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %65
57: ; preds = %38
%58 = load i8*, i8** %2
%59 = load i32, i32* %3
%60 = load i32, i32* @stdout
%61 = call i64 @fwrite(i8* %58, i32 %59, i32 1, i32 %60)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %57
%64 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %65
65: ; preds = %63, %57, %38
%66 = load i32, i32* %3
%67 = load i8, i8* %4
%68 = zext i8 %67 to i32
%69 = add i32 %66, %68
%70 = load i8*, i8** %2
%71 = zext i32 %69 to i64
%72 = getelementptr inbounds i8, i8* %70, i64 %71
store i8* %72, i8** %2
%73 = load i8, i8* %4
%74 = icmp ne i8 %73, 0
br i1 %74, label %75, label %85
75: ; preds = %65
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %77
77: ; preds = %81, %75
%78 = load i8, i8* %4
%79 = add i8 %78, -1
store i8 %79, i8* %4
%80 = icmp ne i8 %78, 0
br i1 %80, label %81, label %83
81: ; preds = %77
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %77
83: ; preds = %77
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %85
85: ; preds = %83, %65
br label %86
86: ; preds = %85
br label %10
87: ; preds = %16
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, 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 = [7 x i8] c"fwrite\00"
@.str.4 = [11 x i8] c"{value %u}\00"
define void @zipmapXRepr(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 = %57, %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, %57
%12 = phi i8* [ %46, %57 ], [ %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 = icmp eq i32 %13, 0
br i1 %18, label %25, label %19
19: ; preds = %11
%20 = load i32, i32* @stdout
%21 = tail call i64 @fwrite(i8* %17, i32 %13, i32 1, i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %19, %11
%26 = zext i32 %13 to i64
%27 = getelementptr inbounds i8, i8* %17, i64 %26
%28 = tail call i32 @zipmapDecodeLength(i8* %27)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = tail call i32 @zipmapEncodeLength(i32* null, i32 %28)
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %27, i64 %31
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = load i8, i8* %32
%35 = icmp eq i32 %28, 0
br i1 %35, label %42, label %36
36: ; preds = %25
%37 = load i32, i32* @stdout
%38 = tail call i64 @fwrite(i8* %33, i32 %28, i32 1, i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %36, %25
%43 = zext i8 %34 to i32
%44 = add i32 %28, %43
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %33, i64 %45
%47 = icmp eq i8 %34, 0
br i1 %47, label %57, label %48
48: ; preds = %42
%49 = tail call i32 @putchar(i32 91)
br label %50
50: ; preds = %48, %50
%51 = phi i8 [ %34, %48 ], [ %52, %50 ]
%52 = add i8 %51, -1
%53 = tail call i32 @putchar(i32 46)
%54 = icmp eq i8 %52, 0
br i1 %54, label %55, label %50
55: ; preds = %50
%56 = tail call i32 @putchar(i32 93)
br label %57
57: ; preds = %55, %42
%58 = load i8, i8* %46
%59 = icmp eq i8 %58, -1
br i1 %59, label %8, label %11
}