#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 uint16_t;
struct virtio_net_hdr {
  int gso_type;
  int gso_size;
  int hdr_len;
  scalar_t__ flags;
  int csum_start;
  int csum_offset;
};

/* Variables and functions */
scalar_t__ VIRTIO_NET_HDR_F_NEEDS_CSUM;
int VIRTIO_NET_HDR_GSO_ECN;
#define VIRTIO_NET_HDR_GSO_NONE 131
#define VIRTIO_NET_HDR_GSO_TCPV4 130
#define VIRTIO_NET_HDR_GSO_TCPV6 129
#define VIRTIO_NET_HDR_GSO_UDP 128
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void parse_vnet(struct virtio_net_hdr *vnet) {
  uint16_t gso_type;
  char *type;
  gso_type = vnet->gso_type & ~VIRTIO_NET_HDR_GSO_ECN;
  switch (gso_type) {
  case VIRTIO_NET_HDR_GSO_NONE:
    type = "none";
    break;
  case VIRTIO_NET_HDR_GSO_TCPV4:
    type = "tcpv4";
    break;
  case VIRTIO_NET_HDR_GSO_TCPV6:
    type = "tcpv6";
    break;
  case VIRTIO_NET_HDR_GSO_UDP:
    type = "udp";
    break;
  default:
    type = "unknown";
  }
  fprintf(stderr, "vnet: gso_type=%s gso_size=%u hlen=%u ecn=%s\n", type,
          vnet->gso_size, vnet->hdr_len,
          (vnet->gso_type & VIRTIO_NET_HDR_GSO_ECN) ? "on " : "off");
  if (vnet->flags == VIRTIO_NET_HDR_F_NEEDS_CSUM)
    fprintf(stderr, "csum: start=%u off=%u\n", vnet->csum_start,
            vnet->csum_offset);
}


x86 assembly (clang, -O0):
<parse_vnet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    0x2e9f(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     119b <parse_vnet+0x8b>
mov    -0x20(%rbp),%rax
lea    0xeae(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeae(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11a6 <parse_vnet+0x96>
lea    0xea3(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11a6 <parse_vnet+0x96>
lea    0xe99(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11a6 <parse_vnet+0x96>
lea    0xe8f(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11a6 <parse_vnet+0x96>
lea    0xe83(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
mov    0x2df9(%rip),%rax
and    (%rax),%esi
lea    0xe87(%rip),%r9
lea    0xe7c(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%r9
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
mov    0x2ded(%rip),%rcx
cmp    (%rcx),%rax
jne    1231 <parse_vnet+0x121>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%edx
mov    -0x8(%rbp),%rax
mov    0x1c(%rax),%ecx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_vnet>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%eax
mov    0x2ea8(%rip),%rcx
mov    (%rcx),%esi
mov    %esi,%ecx
not    %ecx
and    %eax,%ecx
add    $0xffffff80,%ecx
cmp    $0x3,%ecx
ja     1143 <parse_vnet+0x33>
movslq %ecx,%rcx
lea    0xf32(%rip),%rdi
movslq (%rdi,%rcx,4),%rdx
add    %rdi,%rdx
jmp    114a <parse_vnet+0x3a>
lea    0xecb(%rip),%rdx
mov    0x2e87(%rip),%r14
mov    (%r14),%edi
mov    0x4(%rbx),%ecx
mov    0x8(%rbx),%r8d
test   %eax,%esi
lea    0xeeb(%rip),%rax
lea    0xee0(%rip),%r9
cmove  %rax,%r9
lea    0xea7(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x10(%rbx),%rax
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%rax
jne    11ab <parse_vnet+0x9b>
mov    (%r14),%edi
mov    0x18(%rbx),%edx
mov    0x1c(%rbx),%ecx
lea    0xeb6(%rip),%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.virtio_net_hdr = type { i32, i32, i32, i64, i32, i32 }
@VIRTIO_NET_HDR_GSO_ECN = global i32 0
@.str = [5 x i8] c"none\00"
@.str.1 = [6 x i8] c"tcpv4\00"
@.str.2 = [6 x i8] c"tcpv6\00"
@.str.3 = [4 x i8] c"udp\00"
@.str.4 = [8 x i8] c"unknown\00"
@stderr = global i32 0
@.str.5 = [46 x i8] c"vnet: gso_type=%s gso_size=%u hlen=%u ecn=%s\0A\00"
@.str.6 = [4 x i8] c"on \00"
@.str.7 = [4 x i8] c"off\00"
@VIRTIO_NET_HDR_F_NEEDS_CSUM = global i64 0
@.str.8 = [23 x i8] c"csum: start=%u off=%u\0A\00"
define void @parse_vnet(%struct.virtio_net_hdr* %0) {
%2 = alloca %struct.virtio_net_hdr*
%3 = alloca i32
%4 = alloca i8*
store %struct.virtio_net_hdr* %0, %struct.virtio_net_hdr** %2
%5 = load %struct.virtio_net_hdr*, %struct.virtio_net_hdr** %2
%6 = getelementptr inbounds %struct.virtio_net_hdr, %struct.virtio_net_hdr* %5, i32 0, i32 0
%7 = load i32, i32* %6
%8 = load i32, i32* @VIRTIO_NET_HDR_GSO_ECN
%9 = xor i32 %8, -1
%10 = and i32 %7, %9
store i32 %10, i32* %3
%11 = load i32, i32* %3
switch i32 %11, label %16 [
i32 131, label %12
i32 130, label %13
i32 129, label %14
i32 128, label %15
]
12: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %4
br label %17
13: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %17
14: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %4
br label %17
15: ; preds = %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %4
br label %17
16: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8** %4
br label %17
17: ; preds = %16, %15, %14, %13, %12
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %4
%20 = load %struct.virtio_net_hdr*, %struct.virtio_net_hdr** %2
%21 = getelementptr inbounds %struct.virtio_net_hdr, %struct.virtio_net_hdr* %20, i32 0, i32 1
%22 = load i32, i32* %21
%23 = load %struct.virtio_net_hdr*, %struct.virtio_net_hdr** %2
%24 = getelementptr inbounds %struct.virtio_net_hdr, %struct.virtio_net_hdr* %23, i32 0, i32 2
%25 = load i32, i32* %24
%26 = load %struct.virtio_net_hdr*, %struct.virtio_net_hdr** %2
%27 = getelementptr inbounds %struct.virtio_net_hdr, %struct.virtio_net_hdr* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = load i32, i32* @VIRTIO_NET_HDR_GSO_ECN
%30 = and i32 %28, %29
%31 = icmp ne i32 %30, 0
%32 = zext i1 %31 to i64
%33 = select i1 %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0)
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i8* %19, i32 %22, i32 %25, i8* %33)
%35 = load %struct.virtio_net_hdr*, %struct.virtio_net_hdr** %2
%36 = getelementptr inbounds %struct.virtio_net_hdr, %struct.virtio_net_hdr* %35, i32 0, i32 3
%37 = load i64, i64* %36
%38 = load i64, i64* @VIRTIO_NET_HDR_F_NEEDS_CSUM
%39 = icmp eq i64 %37, %38
br i1 %39, label %40, label %49
40: ; preds = %17
%41 = load i32, i32* @stderr
%42 = load %struct.virtio_net_hdr*, %struct.virtio_net_hdr** %2
%43 = getelementptr inbounds %struct.virtio_net_hdr, %struct.virtio_net_hdr* %42, i32 0, i32 4
%44 = load i32, i32* %43
%45 = load %struct.virtio_net_hdr*, %struct.virtio_net_hdr** %2
%46 = getelementptr inbounds %struct.virtio_net_hdr, %struct.virtio_net_hdr* %45, i32 0, i32 5
%47 = load i32, i32* %46
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %44, i32 %47)
br label %49
49: ; preds = %40, %17
ret void
}

LLVM IR (-O2):
%struct.virtio_net_hdr = type { i32, i32, i32, i64, i32, i32 }
@VIRTIO_NET_HDR_GSO_ECN = global i32 0
@.str = [5 x i8] c"none\00"
@.str.1 = [6 x i8] c"tcpv4\00"
@.str.2 = [6 x i8] c"tcpv6\00"
@.str.3 = [4 x i8] c"udp\00"
@.str.4 = [8 x i8] c"unknown\00"
@stderr = global i32 0
@.str.5 = [46 x i8] c"vnet: gso_type=%s gso_size=%u hlen=%u ecn=%s\0A\00"
@.str.6 = [4 x i8] c"on \00"
@.str.7 = [4 x i8] c"off\00"
@VIRTIO_NET_HDR_F_NEEDS_CSUM = global i64 0
@.str.8 = [23 x i8] c"csum: start=%u off=%u\0A\00"
@reltable.parse_vnet = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.parse_vnet to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.parse_vnet to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.parse_vnet to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str to i64), i64 ptrtoint ([4 x i32]* @reltable.parse_vnet to i64)) to i32)]
define void @parse_vnet(%struct.virtio_net_hdr* nocapture %0) {
%2 = getelementptr inbounds %struct.virtio_net_hdr, %struct.virtio_net_hdr* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = load i32, i32* @VIRTIO_NET_HDR_GSO_ECN
%5 = xor i32 %4, -1
%6 = and i32 %3, %5
%7 = add i32 %6, -128
%8 = icmp ult i32 %7, 4
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = sext i32 %7 to i64
%11 = shl i64 %10, 2
%12 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.parse_vnet to i8*), i64 %11)
br label %13
13: ; preds = %1, %9
%14 = phi i8* [ %12, %9 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), %1 ]
%15 = load i32, i32* @stderr
%16 = getelementptr inbounds %struct.virtio_net_hdr, %struct.virtio_net_hdr* %0, i64 0, i32 1
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.virtio_net_hdr, %struct.virtio_net_hdr* %0, i64 0, i32 2
%19 = load i32, i32* %18
%20 = and i32 %4, %3
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0)
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i8* %14, i32 %17, i32 %19, i8* %22)
%24 = getelementptr inbounds %struct.virtio_net_hdr, %struct.virtio_net_hdr* %0, i64 0, i32 3
%25 = load i64, i64* %24
%26 = load i64, i64* @VIRTIO_NET_HDR_F_NEEDS_CSUM
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %35
28: ; preds = %13
%29 = load i32, i32* @stderr
%30 = getelementptr inbounds %struct.virtio_net_hdr, %struct.virtio_net_hdr* %0, i64 0, i32 4
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.virtio_net_hdr, %struct.virtio_net_hdr* %0, i64 0, i32 5
%33 = load i32, i32* %32
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %31, i32 %33)
br label %35
35: ; preds = %28, %13
ret void
}