#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct iphdr {
  int ihl;
  int version;
  int protocol;
  int ttl;
  int /*<<< orphan*/ daddr;
  int /*<<< orphan*/ tot_len;
  int /*<<< orphan*/ saddr;
};
struct in_addr {
  int /*<<< orphan*/ s_addr;
};
struct TYPE_3__ {
  int id;
  int sequence;
};
struct TYPE_4__ {
  TYPE_1__ echo;
};
struct icmphdr {
  int type;
  int code;
  TYPE_2__ un;
  int /*<<< orphan*/ checksum;
};

/* Variables and functions */
char *inet_ntoa(struct in_addr);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void output_to_display(void *netPacket, int bytes, int pid) {
  int i;
  struct iphdr *ip = netPacket;
  struct icmphdr *icmpPtr = netPacket + ip->ihl * 4;
  struct in_addr tmp_addr;
  printf("\n************** -- Ping Tests - "
         "**********************************************\n");
  for (i = 0; i < bytes; i++) {
    if (!(i & 15)) {
      printf("\n[%d]:  ", i);
    }
    printf("[%d] ", ((unsigned char *)netPacket)[i]);
  }
  printf("\n");
  tmp_addr.s_addr = ip->saddr;
  printf("IPv%d: hdr-size=%d pkt-size=%d protocol=%d TTL=%d src=%s ",
         ip->version, ip->ihl * 4, ntohs(ip->tot_len), ip->protocol, ip->ttl,
         inet_ntoa(tmp_addr));
  tmp_addr.s_addr = ip->daddr;
  printf("dst=%s\n", inet_ntoa(tmp_addr));
  if (icmpPtr->un.echo.id == pid) {
    printf("ICMP: type[%d/%d] checksum[%d] id[%d] seq[%d]\n\n", icmpPtr->type,
           icmpPtr->code, ntohs(icmpPtr->checksum), icmpPtr->un.echo.id,
           icmpPtr->un.echo.sequence);
  }
}


x86 assembly (clang, -O0):
<output_to_display>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ca <output_to_display+0x9a>
mov    -0x14(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    11a2 <output_to_display+0x72>
mov    -0x14(%rbp),%esi
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1176 <output_to_display+0x46>
lea    0xefe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
shl    $0x2,%eax
mov    %eax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    0x14(%rax),%edi
call   1050 <ntohs@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    -0x44(%rbp),%esi
mov    -0x40(%rbp),%edx
mov    -0x3c(%rbp),%ecx
mov    -0x38(%rbp),%r8d
mov    -0x34(%rbp),%r9d
lea    0xe24(%rip),%rdi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%eax
cmp    -0x10(%rbp),%eax
jne    12be <output_to_display+0x18e>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%edi
call   1050 <ntohs@plt>
mov    -0x4c(%rbp),%esi
mov    -0x48(%rbp),%edx
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x28(%rbp),%rax
mov    0xc(%rax),%r9d
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_to_display>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,0xc(%rsp)
mov    %esi,%ebp
mov    %rdi,%r14
movslq (%rdi),%rax
mov    %rax,0x10(%rsp)
lea    0xf0b(%rip),%rdi
call   1040 <puts@plt>
test   %ebp,%ebp
jle    11cc <output_to_display+0x7c>
mov    %ebp,%ebx
lea    0xe78(%rip),%r15
lea    0xe7a(%rip),%r12
xor    %ebp,%ebp
jmp    11b8 <output_to_display+0x68>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r14,%rbp,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
je     11cc <output_to_display+0x7c>
test   $0xf,%bpl
jne    11a0 <output_to_display+0x50>
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11a0 <output_to_display+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x18(%r14),%r15d
mov    (%r14),%ebp
mov    0x4(%r14),%eax
mov    %eax,0x8(%rsp)
shl    $0x2,%ebp
mov    0x14(%r14),%edi
call   1070 <ntohs@plt>
mov    %eax,%r13d
mov    0x8(%r14),%ebx
mov    0xc(%r14),%r12d
mov    %r15d,%edi
call   1050 <inet_ntoa@plt>
mov    %rax,(%rsp)
lea    0xe00(%rip),%rdi
mov    0x8(%rsp),%esi
mov    %ebp,%edx
mov    %r13d,%ecx
mov    %ebx,%r8d
mov    %r12d,%r9d
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%r14),%edi
call   1050 <inet_ntoa@plt>
lea    0xe14(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rsp),%rbx
mov    0xc(%rsp),%eax
cmp    %eax,0x8(%r14,%rbx,4)
jne    128f <output_to_display+0x13f>
mov    (%r14,%rbx,4),%ebp
mov    0x4(%r14,%rbx,4),%r15d
mov    0x10(%r14,%rbx,4),%edi
call   1070 <ntohs@plt>
mov    0x8(%r14,%rbx,4),%r8d
mov    0xc(%r14,%rbx,4),%r9d
lea    0xdde(%rip),%rdi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %eax,%ecx
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.iphdr = type { i32, i32, i32, i32, i32, i32, i32 }
%struct.icmphdr = type { i32, i32, %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32, i32 }
%struct.in_addr = type { i32 }
@.str = [80 x i8] c"\0A************** -- Ping Tests - **********************************************\0A\00"
@.str.1 = [9 x i8] c"\0A[%d]: \00"
@.str.2 = [6 x i8] c"[%d] \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [58 x i8] c"IPv%d: hdr-size=%d pkt-size=%d protocol=%d TTL=%d src=%s \00"
@.str.5 = [8 x i8] c"dst=%s\0A\00"
@.str.6 = [48 x i8] c"ICMP: type[%d/%d] checksum[%d] id[%d] seq[%d]\0A\0A\00"
define void @output_to_display(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.iphdr*
%9 = alloca %struct.icmphdr*
%10 = alloca %struct.in_addr
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i8*, i8** %4
%12 = bitcast i8* %11 to %struct.iphdr*
store %struct.iphdr* %12, %struct.iphdr** %8
%13 = load i8*, i8** %4
%14 = load %struct.iphdr*, %struct.iphdr** %8
%15 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = mul nsw i32 %16, 4
%18 = sext i32 %17 to i64
%19 = getelementptr i8, i8* %13, i64 %18
%20 = bitcast i8* %19 to %struct.icmphdr*
store %struct.icmphdr* %20, %struct.icmphdr** %9
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %22
22: ; preds = %41, %3
%23 = load i32, i32* %7
%24 = load i32, i32* %5
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %44
26: ; preds = %22
%27 = load i32, i32* %7
%28 = and i32 %27, 15
%29 = icmp ne i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %26
%31 = load i32, i32* %7
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %30, %26
%34 = load i8*, i8** %4
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %33
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %22
44: ; preds = %22
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%46 = load %struct.iphdr*, %struct.iphdr** %8
%47 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %46, i32 0, i32 6
%48 = load i32, i32* %47
%49 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %10, i32 0, i32 0
store i32 %48, i32* %49
%50 = load %struct.iphdr*, %struct.iphdr** %8
%51 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %50, i32 0, i32 1
%52 = load i32, i32* %51
%53 = load %struct.iphdr*, %struct.iphdr** %8
%54 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %53, i32 0, i32 0
%55 = load i32, i32* %54
%56 = mul nsw i32 %55, 4
%57 = load %struct.iphdr*, %struct.iphdr** %8
%58 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %57, i32 0, i32 5
%59 = load i32, i32* %58
%60 = call i32 @ntohs(i32 %59)
%61 = load %struct.iphdr*, %struct.iphdr** %8
%62 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %61, i32 0, i32 2
%63 = load i32, i32* %62
%64 = load %struct.iphdr*, %struct.iphdr** %8
%65 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %64, i32 0, i32 3
%66 = load i32, i32* %65
%67 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %10, i32 0, i32 0
%68 = load i32, i32* %67
%69 = call i8* @inet_ntoa(i32 %68)
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0), i32 %52, i32 %56, i32 %60, i32 %63, i32 %66, i8* %69)
%71 = load %struct.iphdr*, %struct.iphdr** %8
%72 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %71, i32 0, i32 4
%73 = load i32, i32* %72
%74 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %10, i32 0, i32 0
store i32 %73, i32* %74
%75 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %10, i32 0, i32 0
%76 = load i32, i32* %75
%77 = call i8* @inet_ntoa(i32 %76)
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %77)
%79 = load %struct.icmphdr*, %struct.icmphdr** %9
%80 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %79, i32 0, i32 2
%81 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %80, i32 0, i32 0
%82 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %81, i32 0, i32 0
%83 = load i32, i32* %82
%84 = load i32, i32* %6
%85 = icmp eq i32 %83, %84
br i1 %85, label %86, label %108
86: ; preds = %44
%87 = load %struct.icmphdr*, %struct.icmphdr** %9
%88 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %87, i32 0, i32 0
%89 = load i32, i32* %88
%90 = load %struct.icmphdr*, %struct.icmphdr** %9
%91 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %90, i32 0, i32 1
%92 = load i32, i32* %91
%93 = load %struct.icmphdr*, %struct.icmphdr** %9
%94 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %93, i32 0, i32 3
%95 = load i32, i32* %94
%96 = call i32 @ntohs(i32 %95)
%97 = load %struct.icmphdr*, %struct.icmphdr** %9
%98 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %97, i32 0, i32 2
%99 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %98, i32 0, i32 0
%100 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %99, i32 0, i32 0
%101 = load i32, i32* %100
%102 = load %struct.icmphdr*, %struct.icmphdr** %9
%103 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %102, i32 0, i32 2
%104 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %103, i32 0, i32 0
%105 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %104, i32 0, i32 1
%106 = load i32, i32* %105
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0), i32 %89, i32 %92, i32 %96, i32 %101, i32 %106)
br label %108
108: ; preds = %86, %44
ret void
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"\0A[%d]: \00"
@.str.2 = [6 x i8] c"[%d] \00"
@.str.4 = [58 x i8] c"IPv%d: hdr-size=%d pkt-size=%d protocol=%d TTL=%d src=%s \00"
@.str.5 = [8 x i8] c"dst=%s\0A\00"
@.str.6 = [48 x i8] c"ICMP: type[%d/%d] checksum[%d] id[%d] seq[%d]\0A\0A\00"
@str = [79 x i8] c"\0A************** -- Ping Tests - **********************************************\00"
define void @output_to_display(i8* nocapture %0, i32 %1, i32 %2) {
%4 = bitcast i8* %0 to i32*
%5 = load i32, i32* %4
%6 = shl nsw i32 %5, 2
%7 = sext i32 %6 to i64
%8 = getelementptr i8, i8* %0, i64 %7
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @str, i64 0, i64 0))
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %27
11: ; preds = %3
%12 = zext i32 %1 to i64
br label %13
13: ; preds = %11, %20
%14 = phi i64 [ 0, %11 ], [ %25, %20 ]
%15 = trunc i64 %14 to i32
%16 = and i32 %15, 15
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %20
20: ; preds = %18, %13
%21 = getelementptr inbounds i8, i8* %0, i64 %14
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = add nuw nsw i64 %14, 1
%26 = icmp eq i64 %25, %12
br i1 %26, label %27, label %13
27: ; preds = %20, %3
%28 = tail call i32 @putchar(i32 10)
%29 = getelementptr inbounds i8, i8* %0, i64 24
%30 = bitcast i8* %29 to i32*
%31 = load i32, i32* %30
%32 = getelementptr inbounds i8, i8* %0, i64 4
%33 = bitcast i8* %32 to i32*
%34 = load i32, i32* %33
%35 = load i32, i32* %4
%36 = shl nsw i32 %35, 2
%37 = getelementptr inbounds i8, i8* %0, i64 20
%38 = bitcast i8* %37 to i32*
%39 = load i32, i32* %38
%40 = tail call i32 @ntohs(i32 %39)
%41 = getelementptr inbounds i8, i8* %0, i64 8
%42 = bitcast i8* %41 to i32*
%43 = load i32, i32* %42
%44 = getelementptr inbounds i8, i8* %0, i64 12
%45 = bitcast i8* %44 to i32*
%46 = load i32, i32* %45
%47 = tail call i8* @inet_ntoa(i32 %31)
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0), i32 %34, i32 %36, i32 %40, i32 %43, i32 %46, i8* %47)
%49 = getelementptr inbounds i8, i8* %0, i64 16
%50 = bitcast i8* %49 to i32*
%51 = load i32, i32* %50
%52 = tail call i8* @inet_ntoa(i32 %51)
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %52)
%54 = getelementptr inbounds i8, i8* %8, i64 8
%55 = bitcast i8* %54 to i32*
%56 = load i32, i32* %55
%57 = icmp eq i32 %56, %2
br i1 %57, label %58, label %73
58: ; preds = %27
%59 = bitcast i8* %8 to i32*
%60 = load i32, i32* %59
%61 = getelementptr inbounds i8, i8* %8, i64 4
%62 = bitcast i8* %61 to i32*
%63 = load i32, i32* %62
%64 = getelementptr inbounds i8, i8* %8, i64 16
%65 = bitcast i8* %64 to i32*
%66 = load i32, i32* %65
%67 = tail call i32 @ntohs(i32 %66)
%68 = load i32, i32* %55
%69 = getelementptr inbounds i8, i8* %54, i64 4
%70 = bitcast i8* %69 to i32*
%71 = load i32, i32* %70
%72 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0), i32 %60, i32 %63, i32 %67, i32 %68, i32 %71)
br label %73
73: ; preds = %58, %27
ret void
}