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


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   1030 <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   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <pr_options@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pr_iph>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%r15d
shl    $0x2,%r15d
lea    0x50(%rdi),%r14
lea    0xed1(%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    0xe78(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x14(%rbx),%edx
mov    %edx,%esi
shr    $0xd,%esi
and    $0x7,%esi
and    $0x1fff,%edx
lea    0xe73(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x18(%rbx),%esi
mov    0x1c(%rbx),%edx
mov    0x20(%rbx),%ecx
lea    0xe68(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x28(%rbx),%edi
call   1050 <inet_ntoa@plt>
lea    0xe64(%rip),%rbp
mov    %rbp,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x24(%rbx),%edi
call   1050 <inet_ntoa@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
mov    %r15d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <pr_options@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 = [2 x i8] c"\0A\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)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%64 = load i32*, i32** %4
%65 = load i32, i32* %3
%66 = call i32 @pr_options(i32* %64, i32 %65)
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 = [65 x i8] c"Vr HL TOS Len ID Flg off TTL Pro cks Src Dst Data\00"
define void @pr_iph(%struct.iphdr* %0) {
%2 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = shl i32 %3, 2
%5 = getelementptr inbounds i32, i32* %2, i64 20
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str, i64 0, i64 0))
%7 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 1
%8 = load i32, i32* %7
%9 = load i32, i32* %2
%10 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 2
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 3
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 4
%15 = load i32, i32* %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %9, i32 %11, i32 %13, i32 %15)
%17 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 5
%18 = load i32, i32* %17
%19 = lshr i32 %18, 13
%20 = and i32 %19, 7
%21 = and i32 %18, 8191
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %21)
%23 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 6
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 7
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 8
%28 = load i32, i32* %27
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %24, i32 %26, i32 %28)
%30 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 10
%31 = load i32, i32* %30
%32 = tail call i8* @inet_ntoa(i32 %31)
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 9
%35 = load i32, i32* %34
%36 = tail call i8* @inet_ntoa(i32 %35)
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %36)
%38 = tail call i32 @putchar(i32 10)
%39 = tail call i32 @pr_options(i32* %5, i32 %4)
ret void
}