#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*/ uint8_t;
typedef int uint64_t;
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int _ProtoBufFixed(int /*<<< orphan*/ const *, size_t, size_t *, int);
int /*<<< orphan*/ *_ProtoBufLenDelim(int /*<<< orphan*/ const *, size_t *,
                                      size_t *);
int _ProtoBufVarInt(int /*<<< orphan*/ const *, size_t, size_t *);
uint64_t _ProtoBufField(uint64_t *i, const uint8_t **data, const uint8_t *buf,
                        size_t *len, size_t *off) {
  uint64_t varInt = 0, fixedInt = 0, key = _ProtoBufVarInt(buf, *len, off);
  const uint8_t *lenDelim = NULL;
  switch (key & 0x07) {
  case 0:
    varInt = _ProtoBufVarInt(buf, *len, off);
    if (i)
      *i = varInt;
    break;
  case 1:
    fixedInt = _ProtoBufFixed(buf, *len, off, sizeof(uint64_t));
    if (i)
      *i = fixedInt;
    break;
  case 2:
    lenDelim = _ProtoBufLenDelim(buf, len, off);
    if (data)
      *data = lenDelim;
    break;
  case 5:
    fixedInt = _ProtoBufFixed(buf, *len, off, sizeof(uint32_t));
    if (i)
      *i = fixedInt;
    break;
  default:
    break;
  }
  return key;
}


x86 assembly (clang, -O0):
<_ProtoBufField>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <_ProtoBufVarInt@plt>
mov    %eax,-0x34(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x34(%rbp),%eax
and    $0x7,%eax
mov    %rax,-0x48(%rbp)
sub    $0x5,%eax
ja     126a <_ProtoBufField+0x13a>
mov    -0x48(%rbp),%rax
lea    0xe69(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <_ProtoBufVarInt@plt>
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11cb <_ProtoBufField+0x9b>
mov    -0x2c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    126f <_ProtoBufField+0x13f>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    -0x28(%rbp),%rdx
mov    $0x4,%ecx
call   1030 <_ProtoBufFixed@plt>
mov    %eax,-0x30(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1200 <_ProtoBufField+0xd0>
mov    -0x30(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    126f <_ProtoBufField+0x13f>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <_ProtoBufLenDelim@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1230 <_ProtoBufField+0x100>
mov    -0x40(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    126f <_ProtoBufField+0x13f>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    -0x28(%rbp),%rdx
mov    $0x4,%ecx
call   1030 <_ProtoBufFixed@plt>
mov    %eax,-0x30(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1265 <_ProtoBufField+0x135>
mov    -0x30(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    126f <_ProtoBufField+0x13f>
jmp    126f <_ProtoBufField+0x13f>
mov    -0x34(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ProtoBufField>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r13
mov    %rcx,%rbx
mov    %rdx,%rbp
mov    %rsi,%r12
mov    %rdi,%r14
mov    (%rcx),%rsi
mov    %rdx,%rdi
mov    %r8,%rdx
call   1050 <_ProtoBufVarInt@plt>
mov    %eax,%r15d
and    $0x7,%eax
cmp    $0x5,%eax
ja     11bc <_ProtoBufField+0x8c>
lea    0xe96(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    (%rbx),%rsi
mov    %rbp,%rdi
mov    %r13,%rdx
mov    $0x4,%ecx
call   1030 <_ProtoBufFixed@plt>
test   %r14,%r14
jne    11a0 <_ProtoBufField+0x70>
jmp    11bc <_ProtoBufField+0x8c>
mov    (%rbx),%rsi
mov    %rbp,%rdi
mov    %r13,%rdx
call   1050 <_ProtoBufVarInt@plt>
test   %r14,%r14
je     11bc <_ProtoBufField+0x8c>
mov    %eax,(%r14)
jmp    11bc <_ProtoBufField+0x8c>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1040 <_ProtoBufLenDelim@plt>
test   %r12,%r12
je     11bc <_ProtoBufField+0x8c>
mov    %rax,(%r12)
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_ProtoBufField(i32* %0, i32** %1, i32* %2, i64* %3, i64* %4) {
%6 = alloca i32*
%7 = alloca i32**
%8 = alloca i32*
%9 = alloca i64*
%10 = alloca i64*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
store i32* %0, i32** %6
store i32** %1, i32*** %7
store i32* %2, i32** %8
store i64* %3, i64** %9
store i64* %4, i64** %10
store i32 0, i32* %11
store i32 0, i32* %12
%15 = load i32*, i32** %8
%16 = load i64*, i64** %9
%17 = load i64, i64* %16
%18 = load i64*, i64** %10
%19 = call i32 @_ProtoBufVarInt(i32* %15, i64 %17, i64* %18)
store i32 %19, i32* %13
store i32* null, i32** %14
%20 = load i32, i32* %13
%21 = and i32 %20, 7
switch i32 %21, label %69 [
i32 0, label %22
i32 1, label %34
i32 2, label %46
i32 5, label %57
]
22: ; preds = %5
%23 = load i32*, i32** %8
%24 = load i64*, i64** %9
%25 = load i64, i64* %24
%26 = load i64*, i64** %10
%27 = call i32 @_ProtoBufVarInt(i32* %23, i64 %25, i64* %26)
store i32 %27, i32* %11
%28 = load i32*, i32** %6
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %33
30: ; preds = %22
%31 = load i32, i32* %11
%32 = load i32*, i32** %6
store i32 %31, i32* %32
br label %33
33: ; preds = %30, %22
br label %70
34: ; preds = %5
%35 = load i32*, i32** %8
%36 = load i64*, i64** %9
%37 = load i64, i64* %36
%38 = load i64*, i64** %10
%39 = call i32 @_ProtoBufFixed(i32* %35, i64 %37, i64* %38, i32 4)
store i32 %39, i32* %12
%40 = load i32*, i32** %6
%41 = icmp ne i32* %40, null
br i1 %41, label %42, label %45
42: ; preds = %34
%43 = load i32, i32* %12
%44 = load i32*, i32** %6
store i32 %43, i32* %44
br label %45
45: ; preds = %42, %34
br label %70
46: ; preds = %5
%47 = load i32*, i32** %8
%48 = load i64*, i64** %9
%49 = load i64*, i64** %10
%50 = call i32* @_ProtoBufLenDelim(i32* %47, i64* %48, i64* %49)
store i32* %50, i32** %14
%51 = load i32**, i32*** %7
%52 = icmp ne i32** %51, null
br i1 %52, label %53, label %56
53: ; preds = %46
%54 = load i32*, i32** %14
%55 = load i32**, i32*** %7
store i32* %54, i32** %55
br label %56
56: ; preds = %53, %46
br label %70
57: ; preds = %5
%58 = load i32*, i32** %8
%59 = load i64*, i64** %9
%60 = load i64, i64* %59
%61 = load i64*, i64** %10
%62 = call i32 @_ProtoBufFixed(i32* %58, i64 %60, i64* %61, i32 4)
store i32 %62, i32* %12
%63 = load i32*, i32** %6
%64 = icmp ne i32* %63, null
br i1 %64, label %65, label %68
65: ; preds = %57
%66 = load i32, i32* %12
%67 = load i32*, i32** %6
store i32 %66, i32* %67
br label %68
68: ; preds = %65, %57
br label %70
69: ; preds = %5
br label %70
70: ; preds = %69, %68, %56, %45, %33
%71 = load i32, i32* %13
ret i32 %71
}

LLVM IR (-O2):
define i32 @_ProtoBufField(i32* writeonly %0, i32** writeonly %1, i32* %2, i64* %3, i64* %4) {
%6 = load i64, i64* %3
%7 = tail call i32 @_ProtoBufVarInt(i32* %2, i64 %6, i64* %4)
%8 = and i32 %7, 7
switch i32 %8, label %28 [
i32 0, label %9
i32 1, label %14
i32 2, label %19
i32 5, label %23
]
9: ; preds = %5
%10 = load i64, i64* %3
%11 = tail call i32 @_ProtoBufVarInt(i32* %2, i64 %10, i64* %4)
%12 = icmp eq i32* %0, null
br i1 %12, label %28, label %13
13: ; preds = %9
store i32 %11, i32* %0
br label %28
14: ; preds = %5
%15 = load i64, i64* %3
%16 = tail call i32 @_ProtoBufFixed(i32* %2, i64 %15, i64* %4, i32 4)
%17 = icmp eq i32* %0, null
br i1 %17, label %28, label %18
18: ; preds = %14
store i32 %16, i32* %0
br label %28
19: ; preds = %5
%20 = tail call i32* @_ProtoBufLenDelim(i32* %2, i64* %3, i64* %4)
%21 = icmp eq i32** %1, null
br i1 %21, label %28, label %22
22: ; preds = %19
store i32* %20, i32** %1
br label %28
23: ; preds = %5
%24 = load i64, i64* %3
%25 = tail call i32 @_ProtoBufFixed(i32* %2, i64 %24, i64* %4, i32 4)
%26 = icmp eq i32* %0, null
br i1 %26, label %28, label %27
27: ; preds = %23
store i32 %25, i32* %0
br label %28
28: ; preds = %5, %23, %27, %19, %22, %14, %18, %9, %13
ret i32 %7
}