#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 ihl;
  int check;
  int /*<<< orphan*/ daddr;
  int /*<<< orphan*/ saddr;
  int /*<<< orphan*/ tot_len;
};
struct in_addr {
  int dummy;
};

/* Variables and functions */
char *inet_ntoa(struct in_addr);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void printIPHeader(struct iphdr *iph) {
  printf("------------IP Header\n");
  printf("ip header length : %d\n", iph->ihl * 4);
  printf("total length: %d\n", ntohs(iph->tot_len));
  printf("source: \t%s\n", inet_ntoa(*(struct in_addr *)&iph->saddr));
  printf("dest: \t\t%s\n", inet_ntoa(*(struct in_addr *)&iph->daddr));
  printf("check: %d\n", iph->check);
  printf("----------------------\n\n");
}


x86 assembly (clang, -O0):
<printIPHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
shl    $0x2,%esi
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%edi
call   1050 <ntohs@plt>
mov    %eax,%esi
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printIPHeader>:
push   %rbx
mov    %rdi,%rbx
lea    0xf02(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%esi
shl    $0x2,%esi
lea    0xea4(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rbx),%edi
call   1060 <ntohs@plt>
lea    0xea5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rbx),%edi
call   1040 <inet_ntoa@plt>
lea    0xe9f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%edi
call   1040 <inet_ntoa@plt>
lea    0xe93(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rbx),%esi
lea    0xe8b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9e(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>

LLVM IR (-O0):
%struct.iphdr = type { i32, i32, i32, i32, i32 }
%struct.in_addr = type { i32 }
@.str = [23 x i8] c"------------IP Header\0A\00"
@.str.1 = [23 x i8] c"ip header length : %d\0A\00"
@.str.2 = [18 x i8] c"total length: %d\0A\00"
@.str.3 = [13 x i8] c"source: \09%s\0A\00"
@.str.4 = [12 x i8] c"dest: \09\09%s\0A\00"
@.str.5 = [11 x i8] c"check: %d\0A\00"
@.str.6 = [25 x i8] c"----------------------\0A\0A\00"
define void @printIPHeader(%struct.iphdr* %0) {
%2 = alloca %struct.iphdr*
store %struct.iphdr* %0, %struct.iphdr** %2
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%4 = load %struct.iphdr*, %struct.iphdr** %2
%5 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i32 0, i32 0
%6 = load i32, i32* %5
%7 = mul nsw i32 %6, 4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = load %struct.iphdr*, %struct.iphdr** %2
%10 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %9, i32 0, i32 4
%11 = load i32, i32* %10
%12 = call i32 @ntohs(i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = load %struct.iphdr*, %struct.iphdr** %2
%15 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %14, i32 0, i32 3
%16 = bitcast i32* %15 to %struct.in_addr*
%17 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i8* @inet_ntoa(i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = load %struct.iphdr*, %struct.iphdr** %2
%22 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %21, i32 0, i32 2
%23 = bitcast i32* %22 to %struct.in_addr*
%24 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i8* @inet_ntoa(i32 %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %26)
%28 = load %struct.iphdr*, %struct.iphdr** %2
%29 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %28, i32 0, i32 1
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.iphdr = type { i32, i32, i32, i32, i32 }
@.str.1 = [23 x i8] c"ip header length : %d\0A\00"
@.str.2 = [18 x i8] c"total length: %d\0A\00"
@.str.3 = [13 x i8] c"source: \09%s\0A\00"
@.str.4 = [12 x i8] c"dest: \09\09%s\0A\00"
@.str.5 = [11 x i8] c"check: %d\0A\00"
@str = [22 x i8] c"------------IP Header\00"
@str.7 = [24 x i8] c"----------------------\0A\00"
define void @printIPHeader(%struct.iphdr* nocapture %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%3 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = shl nsw i32 %4, 2
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 4
%8 = load i32, i32* %7
%9 = tail call i32 @ntohs(i32 %8)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 3
%12 = load i32, i32* %11
%13 = tail call i8* @inet_ntoa(i32 %12)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 2
%16 = load i32, i32* %15
%17 = tail call i8* @inet_ntoa(i32 %16)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 1
%20 = load i32, i32* %19
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %20)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.7, i64 0, i64 0))
ret void
}