#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 char *zipmapNext(unsigned char *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *);
unsigned char *zipmapRewind(unsigned char *);
unsigned int zipmapLen(unsigned char *zm) {
  unsigned int len = 0;
  if (zm[0] < 254) {
    len = zm[0];
  } else {
    unsigned char *p = zipmapRewind(zm);
    while ((p = zipmapNext(p, NULL, NULL, NULL, NULL)) != NULL)
      len++;
    if (len < 254)
      zm[0] = len;
  }
  return len;
}


x86 assembly (clang, -O0):
<zipmapLen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xfe,%eax
jge    1154 <zipmapLen+0x34>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0xc(%rbp)
jmp    11b1 <zipmapLen+0x91>
mov    -0x8(%rbp),%rdi
call   1030 <zipmapRewind@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rsi
mov    %r8,%rdx
mov    %r8,%rcx
call   1040 <zipmapNext@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1194 <zipmapLen+0x74>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1161 <zipmapLen+0x41>
cmpl   $0xfe,-0xc(%rbp)
jae    11ac <zipmapLen+0x8c>
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
jmp    11b1 <zipmapLen+0x91>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zipmapLen>:
push   %rbp
push   %rbx
push   %rax
movzbl (%rdi),%ebp
cmp    $0xfd,%ebp
jbe    1164 <zipmapLen+0x44>
mov    %rdi,%rbx
call   1030 <zipmapRewind@plt>
mov    $0xffffffff,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <zipmapNext@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    1140 <zipmapLen+0x20>
cmp    $0xfd,%ebp
ja     1164 <zipmapLen+0x44>
mov    %bpl,(%rbx)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @zipmapLen(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = zext i8 %7 to i32
%9 = icmp slt i32 %8, 254
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
store i32 %14, i32* %3
br label %34
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = call i8* @zipmapRewind(i8* %16)
store i8* %17, i8** %4
br label %18
18: ; preds = %22, %15
%19 = load i8*, i8** %4
%20 = call i8* @zipmapNext(i8* %19, i32* null, i32* null, i32* null, i32* null)
store i8* %20, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* %3
%24 = add i32 %23, 1
store i32 %24, i32* %3
br label %18
25: ; preds = %18
%26 = load i32, i32* %3
%27 = icmp ult i32 %26, 254
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i32, i32* %3
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** %2
%32 = getelementptr inbounds i8, i8* %31, i64 0
store i8 %30, i8* %32
br label %33
33: ; preds = %28, %25
br label %34
34: ; preds = %33, %10
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
define i32 @zipmapLen(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp ult i8 %2, -2
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = zext i8 %2 to i32
br label %18
6: ; preds = %1
%7 = tail call i8* @zipmapRewind(i8* %0)
br label %8
8: ; preds = %8, %6
%9 = phi i32 [ 0, %6 ], [ %13, %8 ]
%10 = phi i8* [ %7, %6 ], [ %11, %8 ]
%11 = tail call i8* @zipmapNext(i8* %10, i32* null, i32* null, i32* null, i32* null)
%12 = icmp eq i8* %11, null
%13 = add i32 %9, 1
br i1 %12, label %14, label %8
14: ; preds = %8
%15 = icmp ult i32 %9, 254
br i1 %15, label %16, label %18
16: ; preds = %14
%17 = trunc i32 %9 to i8
store i8 %17, i8* %0
br label %18
18: ; preds = %14, %16, %4
%19 = phi i32 [ %5, %4 ], [ %9, %16 ], [ %9, %14 ]
ret i32 %19
}