#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_char;
struct iphdr {
  int ihl;
  int version;
  int tos;
  int tot_len;
  int id;
  int frag_off;
  int ttl;
  int protocol;
  int check;
  int /*<<< orphan*/ daddr;
  int /*<<< orphan*/ saddr;
};
struct in_addr {
  int dummy;
};

/* Variables and functions */
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
void pr_iph(struct iphdr *ip) {
  int hlen;
  u_char *cp;
  hlen = ip->ihl << 2;
  cp = (u_char *)ip + 20;
  (void)printf(
      "Vr HL TOS  Len   ID Flg  off TTL Pro  cks      Src      Dst Data\n");
  (void)printf(" %1x  %1x  %02x %04x %04x", ip->version, ip->ihl, ip->tos,
               ip->tot_len, ip->id);
  (void)printf("   %1x %04x", ((ip->frag_off) & 0xe000) >> 13,
               (ip->frag_off) & 0x1fff);
  (void)printf("  %02x  %02x %04x", ip->ttl, ip->protocol, ip->check);
  (void)printf(" %s ", inet_ntoa(*((struct in_addr *)&ip->saddr)));
  (void)printf(" %s ", inet_ntoa(*((struct in_addr *)&ip->daddr)));
  while (hlen-- > 20) {
    (void)printf("%02x", *cp++);
  }
  (void)putchar('\n');
}


x86 assembly (clang, -O0):
<pr_iph>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
shl    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rax
mov    %rax,-0x18(%rbp)
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%r8d
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%r9d
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x14(%rax),%esi
and    $0xe000,%esi
sar    $0xd,%esi
mov    -0x8(%rbp),%rax
mov    0x14(%rax),%edx
and    $0x1fff,%edx
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%esi
mov    -0x8(%rbp),%rax
mov    0x1c(%rax),%edx
mov    -0x8(%rbp),%rax
mov    0x20(%rax),%ecx
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x28(%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x24(%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x14,%eax
jle    1254 <pr_iph+0x124>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%esi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    121c <pr_iph+0xec>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pr_iph>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%ebp
shl    $0x2,%ebp
lea    0xeef(%rip),%rdi
call   1040 <puts@plt>
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    0x8(%rbx),%ecx
mov    0xc(%rbx),%r8d
mov    0x10(%rbx),%r9d
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x14(%rbx),%edx
mov    %edx,%esi
shr    $0xd,%esi
and    $0x7,%esi
and    $0x1fff,%edx
lea    0xe8c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x18(%rbx),%esi
mov    0x1c(%rbx),%edx
mov    0x20(%rbx),%ecx
lea    0xe81(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x28(%rbx),%edi
call   1050 <inet_ntoa@plt>
lea    0xe7d(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x24(%rbx),%edi
call   1050 <inet_ntoa@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x15,%ebp
jl     1208 <pr_iph+0xc8>
add    $0x50,%rbx
add    $0x1,%ebp
lea    0xe4d(%rip),%r14
mov    (%rbx),%esi
add    $0x4,%rbx
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0xffffffff,%ebp
cmp    $0x15,%ebp
ja     11f0 <pr_iph+0xb0>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
%struct.iphdr = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.in_addr = type { i32 }
@.str = [66 x i8] c"Vr HL TOS Len ID Flg off TTL Pro cks Src Dst Data\0A\00"
@.str.1 = [26 x i8] c" %1x %1x %02x %04x %04x\00"
@.str.2 = [12 x i8] c" %1x %04x\00"
@.str.3 = [18 x i8] c" %02x %02x %04x\00"
@.str.4 = [5 x i8] c" %s \00"
@.str.5 = [5 x i8] c"%02x\00"
define void @pr_iph(%struct.iphdr* %0) {
%2 = alloca %struct.iphdr*
%3 = alloca i32
%4 = alloca i32*
store %struct.iphdr* %0, %struct.iphdr** %2
%5 = load %struct.iphdr*, %struct.iphdr** %2
%6 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %5, i32 0, i32 0
%7 = load i32, i32* %6
%8 = shl i32 %7, 2
store i32 %8, i32* %3
%9 = load %struct.iphdr*, %struct.iphdr** %2
%10 = bitcast %struct.iphdr* %9 to i32*
%11 = getelementptr inbounds i32, i32* %10, i64 20
store i32* %11, i32** %4
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%13 = load %struct.iphdr*, %struct.iphdr** %2
%14 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = load %struct.iphdr*, %struct.iphdr** %2
%17 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = load %struct.iphdr*, %struct.iphdr** %2
%20 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %19, i32 0, i32 2
%21 = load i32, i32* %20
%22 = load %struct.iphdr*, %struct.iphdr** %2
%23 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %22, i32 0, i32 3
%24 = load i32, i32* %23
%25 = load %struct.iphdr*, %struct.iphdr** %2
%26 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %25, i32 0, i32 4
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %18, i32 %21, i32 %24, i32 %27)
%29 = load %struct.iphdr*, %struct.iphdr** %2
%30 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %29, i32 0, i32 5
%31 = load i32, i32* %30
%32 = and i32 %31, 57344
%33 = ashr i32 %32, 13
%34 = load %struct.iphdr*, %struct.iphdr** %2
%35 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %34, i32 0, i32 5
%36 = load i32, i32* %35
%37 = and i32 %36, 8191
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %33, i32 %37)
%39 = load %struct.iphdr*, %struct.iphdr** %2
%40 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %39, i32 0, i32 6
%41 = load i32, i32* %40
%42 = load %struct.iphdr*, %struct.iphdr** %2
%43 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %42, i32 0, i32 7
%44 = load i32, i32* %43
%45 = load %struct.iphdr*, %struct.iphdr** %2
%46 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %45, i32 0, i32 8
%47 = load i32, i32* %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %41, i32 %44, i32 %47)
%49 = load %struct.iphdr*, %struct.iphdr** %2
%50 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %49, i32 0, i32 10
%51 = bitcast i32* %50 to %struct.in_addr*
%52 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %51, i32 0, i32 0
%53 = load i32, i32* %52
%54 = call i8* @inet_ntoa(i32 %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %54)
%56 = load %struct.iphdr*, %struct.iphdr** %2
%57 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %56, i32 0, i32 9
%58 = bitcast i32* %57 to %struct.in_addr*
%59 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %58, i32 0, i32 0
%60 = load i32, i32* %59
%61 = call i8* @inet_ntoa(i32 %60)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %61)
br label %63
63: ; preds = %67, %1
%64 = load i32, i32* %3
%65 = add nsw i32 %64, -1
store i32 %65, i32* %3
%66 = icmp sgt i32 %64, 20
br i1 %66, label %67, label %72
67: ; preds = %63
%68 = load i32*, i32** %4
%69 = getelementptr inbounds i32, i32* %68, i32 1
store i32* %69, i32** %4
%70 = load i32, i32* %68
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %70)
br label %63
72: ; preds = %63
%73 = call i32 @putchar(i8 signext 10)
ret void
}

LLVM IR (-O2):
%struct.iphdr = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
@.str.1 = [26 x i8] c" %1x %1x %02x %04x %04x\00"
@.str.2 = [12 x i8] c" %1x %04x\00"
@.str.3 = [18 x i8] c" %02x %02x %04x\00"
@.str.4 = [5 x i8] c" %s \00"
@.str.5 = [5 x i8] c"%02x\00"
@str = [65 x i8] c"Vr HL TOS Len ID Flg off TTL Pro cks Src Dst Data\00"
define void @pr_iph(%struct.iphdr* nocapture %0) {
%2 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = shl i32 %3, 2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str, i64 0, i64 0))
%6 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 1
%7 = load i32, i32* %6
%8 = load i32, i32* %2
%9 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 2
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 3
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 4
%14 = load i32, i32* %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %8, i32 %10, i32 %12, i32 %14)
%16 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 5
%17 = load i32, i32* %16
%18 = lshr i32 %17, 13
%19 = and i32 %18, 7
%20 = and i32 %17, 8191
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %20)
%22 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 6
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 7
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 8
%27 = load i32, i32* %26
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %23, i32 %25, i32 %27)
%29 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 10
%30 = load i32, i32* %29
%31 = tail call i8* @inet_ntoa(i32 %30)
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %31)
%33 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 9
%34 = load i32, i32* %33
%35 = tail call i8* @inet_ntoa(i32 %34)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %35)
%37 = icmp sgt i32 %4, 20
br i1 %37, label %38, label %48
38: ; preds = %1
%39 = getelementptr inbounds i32, i32* %2, i64 20
br label %40
40: ; preds = %38, %40
%41 = phi i32* [ %44, %40 ], [ %39, %38 ]
%42 = phi i32 [ %43, %40 ], [ %4, %38 ]
%43 = add nsw i32 %42, -1
%44 = getelementptr inbounds i32, i32* %41, i64 1
%45 = load i32, i32* %41
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %45)
%47 = icmp ugt i32 %42, 21
br i1 %47, label %40, label %48
48: ; preds = %40, %1
%49 = tail call i32 @putchar(i8 signext 10)
ret void
}