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


x86 assembly (clang, -O0):
<zipmapXLen>:
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 <zipmapXLen+0x34>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0xc(%rbp)
jmp    11b4 <zipmapXLen+0x94>
mov    -0x8(%rbp),%rdi
call   1030 <zipmapXRewind@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%rsi
mov    %r9,%rdx
mov    %r9,%rcx
mov    %r9,%r8
call   1040 <zipmapXNext@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1197 <zipmapXLen+0x77>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1161 <zipmapXLen+0x41>
cmpl   $0xfe,-0xc(%rbp)
jae    11af <zipmapXLen+0x8f>
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
jmp    11b4 <zipmapXLen+0x94>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define i32 @zipmapXLen(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* @zipmapXRewind(i8* %16)
store i8* %17, i8** %4
br label %18
18: ; preds = %22, %15
%19 = load i8*, i8** %4
%20 = call i8* @zipmapXNext(i8* %19, i32* null, 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 @zipmapXLen(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* @zipmapXRewind(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* @zipmapXNext(i8* %10, i32* null, 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
}