#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 */
typedef int /*<<< orphan*/ len;

/* Variables and functions */
int /*<<< orphan*/ memcpy(unsigned char *, unsigned int *, int);
unsigned int zipmapEncodeLength(unsigned char *p, unsigned int len) {
  if (p == NULL) {
    return (((len) < 254) ? 1 : sizeof(unsigned int) + 1);
  } else {
    if (len < 254) {
      p[0] = len;
      return 1;
    } else {
      p[0] = 254;
      memcpy(p + 1, &len, sizeof(len));
      return 1 + sizeof(len);
    }
  }
}


x86 assembly (clang, -O0):
<zipmapEncodeLength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1149 <zipmapEncodeLength+0x39>
mov    -0x14(%rbp),%edx
mov    $0x5,%eax
mov    $0x1,%ecx
cmp    $0xfe,%edx
cmovb  %rcx,%rax
mov    %eax,-0x4(%rbp)
jmp    1191 <zipmapEncodeLength+0x81>
cmpl   $0xfe,-0x14(%rbp)
jae    116d <zipmapEncodeLength+0x5d>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1191 <zipmapEncodeLength+0x81>
mov    -0x10(%rbp),%rax
movb   $0xfe,(%rax)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
movl   $0x5,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zipmapEncodeLength>:
push   %rax
mov    %esi,0x4(%rsp)
test   %rdi,%rdi
je     112c <zipmapEncodeLength+0x1c>
cmp    $0xfd,%esi
ja     1140 <zipmapEncodeLength+0x30>
mov    %sil,(%rdi)
mov    $0x1,%eax
pop    %rcx
ret
xor    %eax,%eax
cmp    $0xfe,%esi
setae  %al
lea    0x1(,%rax,4),%eax
pop    %rcx
ret
movb   $0xfe,(%rdi)
add    $0x1,%rdi
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    $0x5,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
define i32 @zipmapEncodeLength(i8* %0, i32 %1) {
%3 = alloca i32
store i32 %1, i32* %3
%4 = icmp eq i8* %0, null
%5 = icmp ult i32 %1, 254
br i1 %4, label %6, label %8
6: ; preds = %2
%7 = select i1 %5, i32 1, i32 5
br label %14
8: ; preds = %2
br i1 %5, label %9, label %11
9: ; preds = %8
%10 = trunc i32 %1 to i8
store i8 %10, i8* %0
br label %14
11: ; preds = %8
store i8 -2, i8* %0
%12 = getelementptr inbounds i8, i8* %0, i64 1
%13 = call i32 @memcpy(i8* %12, i32* %3, i32 4)
br label %14
14: ; preds = %11, %9, %6
%15 = phi i32 [ %7, %6 ], [ 1, %9 ], [ 5, %11 ]
ret i32 %15
}