#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*/ u_int8_t;
typedef int /*<<< orphan*/ u_int16_t;
struct ether_header {
  int /*<<< orphan*/ ether_type;
  scalar_t__ ether_dhost;
  scalar_t__ ether_shost;
};
struct ether_addr {
  int dummy;
};

/* Variables and functions */
int ETHER_HDR_LEN;
char *ether_ntoa(struct ether_addr *);
int /*<<< orphan*/ hexdump(int /*<<< orphan*/ *, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, int, int,
                           int /*<<< orphan*/);
char *dumppacket(void *packet, int packet_len) {
  static char printbuf[4096];
  struct ether_header *eh = (struct ether_header *)packet;
  sprintf(printbuf, "%s -> %s, type: %02x length: %hd\n%s",
          ether_ntoa((struct ether_addr *)eh->ether_shost),
          ether_ntoa((struct ether_addr *)eh->ether_dhost),
          ntohs(eh->ether_type),
          ntohs(*(u_int16_t *)((u_int8_t *)packet + ETHER_HDR_LEN)),
          hexdump((u_int8_t *)packet + ETHER_HDR_LEN + sizeof(u_int16_t),
                  packet_len - ETHER_HDR_LEN));
  return printbuf;
}


x86 assembly (clang, -O0):
<dumppacket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <ether_ntoa@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <ether_ntoa@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <ntohs@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    0x2e4e(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,4),%edi
call   1050 <ntohs@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e35(%rip),%rax
movslq (%rax),%rax
shl    $0x2,%rax
add    %rax,%rdi
add    $0x10,%rdi
mov    -0xc(%rbp),%esi
mov    0x2e1d(%rip),%rax
sub    (%rax),%esi
call   1040 <hexdump@plt>
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
lea    0x2e6f(%rip),%rdi
lea    0xe18(%rip),%rsi
mov    %eax,(%rsp)
call   1060 <sprintf@plt>
lea    0x2e59(%rip),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dumppacket>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x10(%rdi),%rdi
call   1030 <ether_ntoa@plt>
mov    %rax,0x10(%rsp)
mov    0x8(%rbx),%rdi
call   1030 <ether_ntoa@plt>
mov    %rax,%r15
mov    (%rbx),%edi
call   1050 <ntohs@plt>
mov    %eax,%r12d
mov    0x2e62(%rip),%r14
movslq (%r14),%rax
mov    (%rbx,%rax,4),%edi
call   1050 <ntohs@plt>
mov    %eax,%r13d
movslq (%r14),%rax
lea    (%rbx,%rax,4),%rdi
add    $0x10,%rdi
sub    %eax,%ebp
mov    %ebp,%esi
call   1040 <hexdump@plt>
mov    %eax,(%rsp)
lea    0x2ea6(%rip),%rbx
lea    0xe4f(%rip),%rsi
mov    %rbx,%rdi
mov    0x10(%rsp),%rdx
mov    %r15,%rcx
mov    %r12d,%r8d
mov    %r13d,%r9d
call   1060 <sprintf@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ether_header = type { i32, i64, i64 }
%struct.ether_addr = type { i32 }
@dumppacket.printbuf = internal global [4096 x i8] zeroinitializer
@.str = [36 x i8] c"%s -> %s, type: %02x length: %hd\0A%s\00"
@ETHER_HDR_LEN = global i32 0
define i8* @dumppacket(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.ether_header*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = bitcast i8* %6 to %struct.ether_header*
store %struct.ether_header* %7, %struct.ether_header** %5
%8 = load %struct.ether_header*, %struct.ether_header** %5
%9 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %8, i32 0, i32 2
%10 = load i64, i64* %9
%11 = inttoptr i64 %10 to %struct.ether_addr*
%12 = call i8* @ether_ntoa(%struct.ether_addr* %11)
%13 = load %struct.ether_header*, %struct.ether_header** %5
%14 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %13, i32 0, i32 1
%15 = load i64, i64* %14
%16 = inttoptr i64 %15 to %struct.ether_addr*
%17 = call i8* @ether_ntoa(%struct.ether_addr* %16)
%18 = load %struct.ether_header*, %struct.ether_header** %5
%19 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @ntohs(i32 %20)
%22 = load i8*, i8** %3
%23 = bitcast i8* %22 to i32*
%24 = load i32, i32* @ETHER_HDR_LEN
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = call i32 @ntohs(i32 %27)
%29 = load i8*, i8** %3
%30 = bitcast i8* %29 to i32*
%31 = load i32, i32* @ETHER_HDR_LEN
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = getelementptr inbounds i32, i32* %33, i64 4
%35 = load i32, i32* %4
%36 = load i32, i32* @ETHER_HDR_LEN
%37 = sub nsw i32 %35, %36
%38 = call i32 @hexdump(i32* %34, i32 %37)
%39 = call i32 @sprintf(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @dumppacket.printbuf, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %17, i32 %21, i32 %28, i32 %38)
ret i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @dumppacket.printbuf, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.ether_addr = type { i32 }
@dumppacket.printbuf = internal global [4096 x i8] zeroinitializer
@.str = [36 x i8] c"%s -> %s, type: %02x length: %hd\0A%s\00"
@ETHER_HDR_LEN = global i32 0
define i8* @dumppacket(i8* %0, i32 %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 16
%4 = bitcast i8* %3 to i64*
%5 = load i64, i64* %4
%6 = inttoptr i64 %5 to %struct.ether_addr*
%7 = tail call i8* @ether_ntoa(%struct.ether_addr* %6)
%8 = getelementptr inbounds i8, i8* %0, i64 8
%9 = bitcast i8* %8 to i64*
%10 = load i64, i64* %9
%11 = inttoptr i64 %10 to %struct.ether_addr*
%12 = tail call i8* @ether_ntoa(%struct.ether_addr* %11)
%13 = bitcast i8* %0 to i32*
%14 = load i32, i32* %13
%15 = tail call i32 @ntohs(i32 %14)
%16 = load i32, i32* @ETHER_HDR_LEN
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %13, i64 %17
%19 = load i32, i32* %18
%20 = tail call i32 @ntohs(i32 %19)
%21 = load i32, i32* @ETHER_HDR_LEN
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %13, i64 %22
%24 = getelementptr inbounds i32, i32* %23, i64 4
%25 = sub nsw i32 %1, %21
%26 = tail call i32 @hexdump(i32* %24, i32 %25)
%27 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([4096 x i8], [4096 x i8]* @dumppacket.printbuf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %12, i32 %15, i32 %20, i32 %26)
ret i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @dumppacket.printbuf, i64 0, i64 0)
}