#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 uint8_t;
typedef int int8_t;
typedef int int64_t;
typedef int int32_t;
typedef int int16_t;
typedef int /*<<< orphan*/ i64;
typedef int /*<<< orphan*/ i32;
typedef int /*<<< orphan*/ i16;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(int *, unsigned char *, int);
int64_t zipLoadInteger(unsigned char *p, unsigned char encoding) {
  int16_t i16;
  int32_t i32;
  int64_t i64, ret = 0;
  if (encoding == 0xfe) {
    ret = ((int8_t *)p)[0];
  } else if (encoding == (0xc0 | 0 << 4)) {
    memcpy(&i16, p, sizeof(i16));
    ;
    ret = i16;
  } else if (encoding == (0xc0 | 1 << 4)) {
    memcpy(&i32, p, sizeof(i32));
    ;
    ret = i32;
  } else if (encoding == (0xc0 | 3 << 4)) {
    i32 = 0;
    memcpy(((uint8_t *)&i32) + 1, p, sizeof(i32) - sizeof(uint8_t));
    ;
    ret = i32 >> 8;
  } else if (encoding == (0xc0 | 2 << 4)) {
    memcpy(&i64, p, sizeof(i64));
    ;
    ret = i64;
  } else if (encoding >= 0xf1 && encoding <= 0xfd) {
    ret = (encoding & 0x0f) - 1;
  } else {
    assert(NULL);
  }
  return ret;
}


x86 assembly (clang, -O0):
<zipLoadInteger>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x0,-0x1c(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0xfe,%eax
jne    1156 <zipLoadInteger+0x36>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1263 <zipLoadInteger+0x143>
movzbl -0x9(%rbp),%eax
cmp    $0xc0,%eax
jne    1182 <zipLoadInteger+0x62>
mov    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    125e <zipLoadInteger+0x13e>
movzbl -0x9(%rbp),%eax
cmp    $0xd0,%eax
jne    11ae <zipLoadInteger+0x8e>
mov    -0x8(%rbp),%rsi
lea    -0x14(%rbp),%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1259 <zipLoadInteger+0x139>
movzbl -0x9(%rbp),%eax
cmp    $0xf0,%eax
jne    11e5 <zipLoadInteger+0xc5>
movl   $0x0,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
add    $0x4,%rdi
mov    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1040 <memcpy@plt>
mov    -0x14(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x1c(%rbp)
jmp    1254 <zipLoadInteger+0x134>
movzbl -0x9(%rbp),%eax
cmp    $0xe0,%eax
jne    1211 <zipLoadInteger+0xf1>
mov    -0x8(%rbp),%rsi
lea    -0x18(%rbp),%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    124f <zipLoadInteger+0x12f>
movzbl -0x9(%rbp),%eax
cmp    $0xf1,%eax
jl     1241 <zipLoadInteger+0x121>
movzbl -0x9(%rbp),%eax
cmp    $0xfd,%eax
jg     1241 <zipLoadInteger+0x121>
movzbl -0x9(%rbp),%eax
and    $0xf,%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    124a <zipLoadInteger+0x12a>
xor    %eax,%eax
mov    %eax,%edi
call   1030 <assert@plt>
jmp    124f <zipLoadInteger+0x12f>
jmp    1254 <zipLoadInteger+0x134>
jmp    1259 <zipLoadInteger+0x139>
jmp    125e <zipLoadInteger+0x13e>
jmp    1263 <zipLoadInteger+0x143>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zipLoadInteger>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rax
cmp    $0xdf,%sil
jle    1147 <zipLoadInteger+0x27>
cmp    $0xe0,%sil
je     116b <zipLoadInteger+0x4b>
cmp    $0xf0,%sil
je     1183 <zipLoadInteger+0x63>
cmp    $0xfe,%sil
jne    11bb <zipLoadInteger+0x9b>
mov    (%rax),%ebx
jmp    11d8 <zipLoadInteger+0xb8>
cmp    $0xc0,%sil
je     11a3 <zipLoadInteger+0x83>
cmp    $0xd0,%sil
jne    11bb <zipLoadInteger+0x9b>
lea    0x4(%rsp),%rdi
mov    %rax,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    0x4(%rsp),%ebx
jmp    11d8 <zipLoadInteger+0xb8>
lea    0x8(%rsp),%rdi
mov    %rax,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    0x8(%rsp),%ebx
jmp    11d8 <zipLoadInteger+0xb8>
movl   $0x0,0x4(%rsp)
lea    0x8(%rsp),%rdi
mov    %rax,%rsi
xor    %edx,%edx
call   1040 <memcpy@plt>
mov    0x4(%rsp),%ebx
sar    $0x8,%ebx
jmp    11d8 <zipLoadInteger+0xb8>
lea    0xc(%rsp),%rdi
mov    %rax,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    0xc(%rsp),%ebx
jmp    11d8 <zipLoadInteger+0xb8>
lea    0xf(%rsi),%eax
cmp    $0xc,%al
ja     11cf <zipLoadInteger+0xaf>
and    $0xf,%sil
movzbl %sil,%ebx
add    $0xffffffff,%ebx
jmp    11d8 <zipLoadInteger+0xb8>
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <assert@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @zipLoadInteger(i8* %0, i8 zeroext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8 %1, i8* %4
store i32 0, i32* %8
%9 = load i8, i8* %4
%10 = zext i8 %9 to i32
%11 = icmp eq i32 %10, 254
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = bitcast i8* %13 to i32*
%15 = getelementptr inbounds i32, i32* %14, i64 0
%16 = load i32, i32* %15
store i32 %16, i32* %8
br label %71
17: ; preds = %2
%18 = load i8, i8* %4
%19 = zext i8 %18 to i32
%20 = icmp eq i32 %19, 192
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = call i32 @memcpy(i32* %5, i8* %22, i32 4)
%24 = load i32, i32* %5
store i32 %24, i32* %8
br label %70
25: ; preds = %17
%26 = load i8, i8* %4
%27 = zext i8 %26 to i32
%28 = icmp eq i32 %27, 208
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i8*, i8** %3
%31 = call i32 @memcpy(i32* %6, i8* %30, i32 4)
%32 = load i32, i32* %6
store i32 %32, i32* %8
br label %69
33: ; preds = %25
%34 = load i8, i8* %4
%35 = zext i8 %34 to i32
%36 = icmp eq i32 %35, 240
br i1 %36, label %37, label %43
37: ; preds = %33
store i32 0, i32* %6
%38 = getelementptr inbounds i32, i32* %6, i64 1
%39 = load i8*, i8** %3
%40 = call i32 @memcpy(i32* %38, i8* %39, i32 0)
%41 = load i32, i32* %6
%42 = ashr i32 %41, 8
store i32 %42, i32* %8
br label %68
43: ; preds = %33
%44 = load i8, i8* %4
%45 = zext i8 %44 to i32
%46 = icmp eq i32 %45, 224
br i1 %46, label %47, label %51
47: ; preds = %43
%48 = load i8*, i8** %3
%49 = call i32 @memcpy(i32* %7, i8* %48, i32 4)
%50 = load i32, i32* %7
store i32 %50, i32* %8
br label %67
51: ; preds = %43
%52 = load i8, i8* %4
%53 = zext i8 %52 to i32
%54 = icmp sge i32 %53, 241
br i1 %54, label %55, label %64
55: ; preds = %51
%56 = load i8, i8* %4
%57 = zext i8 %56 to i32
%58 = icmp sle i32 %57, 253
br i1 %58, label %59, label %64
59: ; preds = %55
%60 = load i8, i8* %4
%61 = zext i8 %60 to i32
%62 = and i32 %61, 15
%63 = sub nsw i32 %62, 1
store i32 %63, i32* %8
br label %66
64: ; preds = %55, %51
%65 = call i32 @assert(i32* null)
br label %66
66: ; preds = %64, %59
br label %67
67: ; preds = %66, %47
br label %68
68: ; preds = %67, %37
br label %69
69: ; preds = %68, %29
br label %70
70: ; preds = %69, %21
br label %71
71: ; preds = %70, %12
%72 = load i32, i32* %8
ret i32 %72
}

LLVM IR (-O2):
define i32 @zipLoadInteger(i8* %0, i8 zeroext %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
switch i8 %1, label %26 [
i8 -2, label %9
i8 -64, label %12
i8 -48, label %15
i8 -16, label %18
i8 -32, label %23
]
9: ; preds = %2
%10 = bitcast i8* %0 to i32*
%11 = load i32, i32* %10
br label %35
12: ; preds = %2
%13 = call i32 @memcpy(i32* %3, i8* %0, i32 4)
%14 = load i32, i32* %3
br label %35
15: ; preds = %2
%16 = call i32 @memcpy(i32* %4, i8* %0, i32 4)
%17 = load i32, i32* %4
br label %35
18: ; preds = %2
store i32 0, i32* %4
%19 = getelementptr inbounds i32, i32* %4, i64 1
%20 = call i32 @memcpy(i32* %19, i8* %0, i32 0)
%21 = load i32, i32* %4
%22 = ashr i32 %21, 8
br label %35
23: ; preds = %2
%24 = call i32 @memcpy(i32* %5, i8* %0, i32 4)
%25 = load i32, i32* %5
br label %35
26: ; preds = %2
%27 = add i8 %1, 15
%28 = icmp ult i8 %27, 13
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = and i8 %1, 15
%31 = zext i8 %30 to i32
%32 = add nsw i32 %31, -1
br label %35
33: ; preds = %26
%34 = tail call i32 @assert(i32* null)
br label %35
35: ; preds = %12, %18, %29, %33, %23, %15, %9
%36 = phi i32 [ %11, %9 ], [ %14, %12 ], [ %17, %15 ], [ %22, %18 ], [ %25, %23 ], [ %32, %29 ], [ 0, %33 ]
ret i32 %36
}