#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 */
struct iphdr {
  int dummy;
};
struct icmphdr {
  int /*<<< orphan*/ checksum;
  scalar_t__ code;
  scalar_t__ type;
};
struct ethhdr {
  int dummy;
};

/* Variables and functions */
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ print_data(char *, int);
int /*<<< orphan*/ printf(char *, ...);
void ip_icmp_packet_callback(char *packet_content, int size) {
  struct icmphdr *icmpst;
  int header_size;
  icmpst = (struct icmphdr *)(packet_content + sizeof(struct ethhdr) +
                              sizeof(struct iphdr));
  header_size =
      sizeof(struct ethhdr) + sizeof(struct iphdr) + sizeof(struct icmphdr);
  printf("ICMP Header\n");
  printf("   |-Message Type           :%d\n", (unsigned int)icmpst->type);
  printf("   |-Type Sub Code          :%d\n", (unsigned int)icmpst->code);
  printf("   |-Check Sum              :%d\n", ntohs(icmpst->checksum));
  printf("[Ethner Header]\n");
  print_data(packet_content, sizeof(struct ethhdr));
  printf("[IP Header]\n");
  print_data(packet_content + sizeof(struct ethhdr), sizeof(struct iphdr));
  printf("[Data Payload]\n");
  print_data(packet_content + header_size, size - header_size);
}


x86 assembly (clang, -O0):
<ip_icmp_packet_callback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
movl   $0x20,-0x1c(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %eax,%esi
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %eax,%esi
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <ntohs@plt>
mov    %eax,%esi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x4,%esi
call   1040 <print_data@plt>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
mov    $0x4,%esi
call   1040 <print_data@plt>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0xc(%rbp),%esi
sub    -0x1c(%rbp),%esi
call   1040 <print_data@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip_icmp_packet_callback>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x4(%rdi),%r14
lea    0xf0f(%rip),%rdi
call   1030 <puts@plt>
mov    0x18(%rbx),%esi
lea    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%esi
lea    0xead(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%edi
call   1060 <ntohs@plt>
lea    0xeb8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed5(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1050 <print_data@plt>
lea    0xecc(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    $0x4,%esi
call   1050 <print_data@plt>
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
add    $0x20,%rbx
add    $0xffffffe0,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <print_data@plt>

LLVM IR (-O0):
%struct.icmphdr = type { i32, i64, i64 }
@.str = [13 x i8] c"ICMP Header\0A\00"
@.str.1 = [33 x i8] c" |-Message Type :%d\0A\00"
@.str.2 = [33 x i8] c" |-Type Sub Code :%d\0A\00"
@.str.3 = [33 x i8] c" |-Check Sum :%d\0A\00"
@.str.4 = [17 x i8] c"[Ethner Header]\0A\00"
@.str.5 = [13 x i8] c"[IP Header]\0A\00"
@.str.6 = [16 x i8] c"[Data Payload]\0A\00"
define void @ip_icmp_packet_callback(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.icmphdr*
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 4
%9 = getelementptr inbounds i8, i8* %8, i64 4
%10 = bitcast i8* %9 to %struct.icmphdr*
store %struct.icmphdr* %10, %struct.icmphdr** %5
store i32 32, i32* %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = load %struct.icmphdr*, %struct.icmphdr** %5
%13 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %12, i32 0, i32 2
%14 = load i64, i64* %13
%15 = trunc i64 %14 to i32
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load %struct.icmphdr*, %struct.icmphdr** %5
%18 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %17, i32 0, i32 1
%19 = load i64, i64* %18
%20 = trunc i64 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = load %struct.icmphdr*, %struct.icmphdr** %5
%23 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @ntohs(i32 %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%28 = load i8*, i8** %3
%29 = call i32 @print_data(i8* %28, i32 4)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 4
%33 = call i32 @print_data(i8* %32, i32 4)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%35 = load i8*, i8** %3
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i32, i32* %4
%40 = load i32, i32* %6
%41 = sub nsw i32 %39, %40
%42 = call i32 @print_data(i8* %38, i32 %41)
ret void
}

LLVM IR (-O2):
@.str.1 = [33 x i8] c" |-Message Type :%d\0A\00"
@.str.2 = [33 x i8] c" |-Type Sub Code :%d\0A\00"
@.str.3 = [33 x i8] c" |-Check Sum :%d\0A\00"
@str = [12 x i8] c"ICMP Header\00"
@str.7 = [16 x i8] c"[Ethner Header]\00"
@str.8 = [12 x i8] c"[IP Header]\00"
@str.9 = [15 x i8] c"[Data Payload]\00"
define void @ip_icmp_packet_callback(i8* %0, i32 %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 4
%4 = getelementptr inbounds i8, i8* %0, i64 8
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%6 = getelementptr inbounds i8, i8* %0, i64 24
%7 = bitcast i8* %6 to i64*
%8 = load i64, i64* %7
%9 = trunc i64 %8 to i32
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds i8, i8* %0, i64 16
%12 = bitcast i8* %11 to i64*
%13 = load i64, i64* %12
%14 = trunc i64 %13 to i32
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = bitcast i8* %4 to i32*
%17 = load i32, i32* %16
%18 = tail call i32 @ntohs(i32 %17)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
%21 = tail call i32 @print_data(i8* %0, i32 4)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.8, i64 0, i64 0))
%23 = tail call i32 @print_data(i8* %3, i32 4)
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.9, i64 0, i64 0))
%25 = getelementptr inbounds i8, i8* %0, i64 32
%26 = add nsw i32 %1, -32
%27 = tail call i32 @print_data(i8* %25, i32 %26)
ret void
}