#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 */

/* Variables and functions */
int ntohs(unsigned short);
int /*<<< orphan*/ printf(char *, ...);
void PrintHeaderHex(unsigned short *datagram) {
  printf("\n---------- HEX START ----------\n");
  for (int i = 0; i < 10; i++)
    printf("\n%d: %X", i, ntohs(datagram[i]));
  printf("\n---------- HEX END ----------\n");
}


x86 assembly (clang, -O0):
<PrintHeaderHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    1183 <PrintHeaderHex+0x63>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movzwl (%rax,%rcx,2),%edi
call   1040 <ntohs@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%edx
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1141 <PrintHeaderHex+0x21>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PrintHeaderHex>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xeca(%rip),%rdi
call   1030 <puts@plt>
movzwl (%rbx),%edi
call   1050 <ntohs@plt>
lea    0xeae(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movzwl 0x2(%rbx),%edi
call   1050 <ntohs@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movzwl 0x4(%rbx),%edi
call   1050 <ntohs@plt>
mov    %r14,%rdi
mov    $0x2,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movzwl 0x6(%rbx),%edi
call   1050 <ntohs@plt>
mov    %r14,%rdi
mov    $0x3,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movzwl 0x8(%rbx),%edi
call   1050 <ntohs@plt>
mov    %r14,%rdi
mov    $0x4,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movzwl 0xa(%rbx),%edi
call   1050 <ntohs@plt>
mov    %r14,%rdi
mov    $0x5,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movzwl 0xc(%rbx),%edi
call   1050 <ntohs@plt>
mov    %r14,%rdi
mov    $0x6,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movzwl 0xe(%rbx),%edi
call   1050 <ntohs@plt>
mov    %r14,%rdi
mov    $0x7,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movzwl 0x10(%rbx),%edi
call   1050 <ntohs@plt>
mov    %r14,%rdi
mov    $0x8,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movzwl 0x12(%rbx),%edi
call   1050 <ntohs@plt>
mov    %r14,%rdi
mov    $0x9,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdd8(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"\0A---------- HEX START ----------\0A\00"
@.str.1 = [8 x i8] c"\0A%d: %X\00"
@.str.2 = [32 x i8] c"\0A---------- HEX END ----------\0A\00"
define void @PrintHeaderHex(i16* %0) {
%2 = alloca i16*
%3 = alloca i32
store i16* %0, i16** %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %5
5: ; preds = %17, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %20
8: ; preds = %5
%9 = load i32, i32* %3
%10 = load i16*, i16** %2
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i16, i16* %10, i64 %12
%14 = load i16, i16* %13
%15 = call i32 @ntohs(i16 zeroext %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %15)
br label %17
17: ; preds = %8
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %5
20: ; preds = %5
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [8 x i8] c"\0A%d: %X\00"
@str = [33 x i8] c"\0A---------- HEX START ----------\00"
@str.3 = [31 x i8] c"\0A---------- HEX END ----------\00"
define void @PrintHeaderHex(i16* nocapture %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%3 = load i16, i16* %0
%4 = tail call i32 @ntohs(i16 zeroext %3)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %4)
%6 = getelementptr inbounds i16, i16* %0, i64 1
%7 = load i16, i16* %6
%8 = tail call i32 @ntohs(i16 zeroext %7)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %8)
%10 = getelementptr inbounds i16, i16* %0, i64 2
%11 = load i16, i16* %10
%12 = tail call i32 @ntohs(i16 zeroext %11)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 %12)
%14 = getelementptr inbounds i16, i16* %0, i64 3
%15 = load i16, i16* %14
%16 = tail call i32 @ntohs(i16 zeroext %15)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 3, i32 %16)
%18 = getelementptr inbounds i16, i16* %0, i64 4
%19 = load i16, i16* %18
%20 = tail call i32 @ntohs(i16 zeroext %19)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 4, i32 %20)
%22 = getelementptr inbounds i16, i16* %0, i64 5
%23 = load i16, i16* %22
%24 = tail call i32 @ntohs(i16 zeroext %23)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 5, i32 %24)
%26 = getelementptr inbounds i16, i16* %0, i64 6
%27 = load i16, i16* %26
%28 = tail call i32 @ntohs(i16 zeroext %27)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 6, i32 %28)
%30 = getelementptr inbounds i16, i16* %0, i64 7
%31 = load i16, i16* %30
%32 = tail call i32 @ntohs(i16 zeroext %31)
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7, i32 %32)
%34 = getelementptr inbounds i16, i16* %0, i64 8
%35 = load i16, i16* %34
%36 = tail call i32 @ntohs(i16 zeroext %35)
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 8, i32 %36)
%38 = getelementptr inbounds i16, i16* %0, i64 9
%39 = load i16, i16* %38
%40 = tail call i32 @ntohs(i16 zeroext %39)
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 9, i32 %40)
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.3, i64 0, i64 0))
ret void
}