#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;

/* Variables and functions */
int *skip_bytes(int const *, int const *);
int *skip_fixed32(int const *, int const *);
int *skip_fixed64(int const *, int const *);
int *skip_varint(int const *, int const *);
const uint8_t *skip_field(const uint8_t *buffer, const uint8_t *buffer_end) {
  uint8_t type = (*buffer) & 0x7;
  if ((buffer = skip_varint(buffer, buffer_end)) == NULL)
    return NULL;
  switch (type) {
  case 0:
    if ((buffer = skip_varint(buffer, buffer_end)) == NULL)
      return NULL;
    break;
  case 1:
    if ((buffer = skip_fixed64(buffer, buffer_end)) == NULL)
      return NULL;
    break;
  case 2:
    if ((buffer = skip_bytes(buffer, buffer_end)) == NULL)
      return NULL;
    break;
  case 5:
    if ((buffer = skip_fixed32(buffer, buffer_end)) == NULL)
      return NULL;
    break;
  default:
    return NULL;
    break;
  }
  return buffer;
}


x86 assembly (clang, -O0):
<skip_field>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    $0x7,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <skip_varint@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1184 <skip_field+0x44>
movq   $0x0,-0x8(%rbp)
jmp    1272 <skip_field+0x132>
mov    -0x1c(%rbp),%eax
mov    %rax,-0x28(%rbp)
sub    $0x5,%rax
ja     125d <skip_field+0x11d>
mov    -0x28(%rbp),%rax
lea    0xe60(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <skip_varint@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11d1 <skip_field+0x91>
movq   $0x0,-0x8(%rbp)
jmp    1272 <skip_field+0x132>
jmp    126a <skip_field+0x12a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <skip_fixed64@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11fe <skip_field+0xbe>
movq   $0x0,-0x8(%rbp)
jmp    1272 <skip_field+0x132>
jmp    126a <skip_field+0x12a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <skip_bytes@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    122b <skip_field+0xeb>
movq   $0x0,-0x8(%rbp)
jmp    1272 <skip_field+0x132>
jmp    126a <skip_field+0x12a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <skip_fixed32@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1258 <skip_field+0x118>
movq   $0x0,-0x8(%rbp)
jmp    1272 <skip_field+0x132>
jmp    126a <skip_field+0x12a>
movq   $0x0,-0x8(%rbp)
jmp    1272 <skip_field+0x132>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skip_field>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    (%rdi),%ebx
call   1060 <skip_varint@plt>
test   %rax,%rax
je     11aa <skip_field+0x6a>
mov    %rax,%rdi
and    $0x7,%ebx
xor    %eax,%eax
cmp    $0x5,%ebx
ja     11ac <skip_field+0x6c>
lea    0xe99(%rip),%rcx
movslq (%rcx,%rbx,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
mov    %r14,%rsi
call   1060 <skip_varint@plt>
test   %rax,%rax
jne    11ac <skip_field+0x6c>
jmp    11aa <skip_field+0x6a>
mov    %r14,%rsi
call   1030 <skip_fixed64@plt>
test   %rax,%rax
jne    11ac <skip_field+0x6c>
jmp    11aa <skip_field+0x6a>
mov    %r14,%rsi
call   1040 <skip_bytes@plt>
test   %rax,%rax
jne    11ac <skip_field+0x6c>
jmp    11aa <skip_field+0x6a>
mov    %r14,%rsi
call   1050 <skip_fixed32@plt>
test   %rax,%rax
jne    11ac <skip_field+0x6c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32* @skip_field(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%7 = load i32*, i32** %4
%8 = load i32, i32* %7
%9 = and i32 %8, 7
store i32 %9, i32* %6
%10 = load i32*, i32** %4
%11 = load i32*, i32** %5
%12 = call i32* @skip_varint(i32* %10, i32* %11)
store i32* %12, i32** %4
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %2
store i32* null, i32** %3
br label %48
15: ; preds = %2
%16 = load i32, i32* %6
switch i32 %16, label %45 [
i32 0, label %17
i32 1, label %24
i32 2, label %31
i32 5, label %38
]
17: ; preds = %15
%18 = load i32*, i32** %4
%19 = load i32*, i32** %5
%20 = call i32* @skip_varint(i32* %18, i32* %19)
store i32* %20, i32** %4
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %23
22: ; preds = %17
store i32* null, i32** %3
br label %48
23: ; preds = %17
br label %46
24: ; preds = %15
%25 = load i32*, i32** %4
%26 = load i32*, i32** %5
%27 = call i32* @skip_fixed64(i32* %25, i32* %26)
store i32* %27, i32** %4
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %30
29: ; preds = %24
store i32* null, i32** %3
br label %48
30: ; preds = %24
br label %46
31: ; preds = %15
%32 = load i32*, i32** %4
%33 = load i32*, i32** %5
%34 = call i32* @skip_bytes(i32* %32, i32* %33)
store i32* %34, i32** %4
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %37
36: ; preds = %31
store i32* null, i32** %3
br label %48
37: ; preds = %31
br label %46
38: ; preds = %15
%39 = load i32*, i32** %4
%40 = load i32*, i32** %5
%41 = call i32* @skip_fixed32(i32* %39, i32* %40)
store i32* %41, i32** %4
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %44
43: ; preds = %38
store i32* null, i32** %3
br label %48
44: ; preds = %38
br label %46
45: ; preds = %15
store i32* null, i32** %3
br label %48
46: ; preds = %44, %37, %30, %23
%47 = load i32*, i32** %4
store i32* %47, i32** %3
br label %48
48: ; preds = %46, %45, %43, %36, %29, %22, %14
%49 = load i32*, i32** %3
ret i32* %49
}

LLVM IR (-O2):
define i32* @skip_field(i32* %0, i32* %1) {
%3 = load i32, i32* %0
%4 = tail call i32* @skip_varint(i32* %0, i32* %1)
%5 = icmp eq i32* %4, null
br i1 %5, label %22, label %6
6: ; preds = %2
%7 = and i32 %3, 7
switch i32 %7, label %22 [
i32 0, label %8
i32 1, label %11
i32 2, label %14
i32 5, label %17
]
8: ; preds = %6
%9 = tail call i32* @skip_varint(i32* %4, i32* %1)
%10 = icmp eq i32* %9, null
br i1 %10, label %22, label %20
11: ; preds = %6
%12 = tail call i32* @skip_fixed64(i32* %4, i32* %1)
%13 = icmp eq i32* %12, null
br i1 %13, label %22, label %20
14: ; preds = %6
%15 = tail call i32* @skip_bytes(i32* %4, i32* %1)
%16 = icmp eq i32* %15, null
br i1 %16, label %22, label %20
17: ; preds = %6
%18 = tail call i32* @skip_fixed32(i32* %4, i32* %1)
%19 = icmp eq i32* %18, null
br i1 %19, label %22, label %20
20: ; preds = %17, %14, %11, %8
%21 = phi i32* [ %18, %17 ], [ %15, %14 ], [ %12, %11 ], [ %9, %8 ]
br label %22
22: ; preds = %6, %17, %14, %11, %8, %2, %20
%23 = phi i32* [ %21, %20 ], [ null, %2 ], [ null, %8 ], [ null, %11 ], [ null, %14 ], [ null, %17 ], [ null, %6 ]
ret i32* %23
}