#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 */
unsigned long htonl(unsigned long);
unsigned short htons(unsigned short);
int /*<<< orphan*/ printf(char *, unsigned long);
int main(int argc, char *argv[]) {
  unsigned short host_port = 0x1234;
  unsigned short net_port;
  unsigned long host_addr = 0x12345678;
  unsigned long net_addr;
  net_port = htons(host_port);
  net_addr = htonl(host_addr);
  printf("Host ordered port    : %#x \n", host_port);
  printf("Network ordered port : %#x \n", net_port);
  printf("Host ordered address    : %#lx \n", host_addr);
  printf("Network ordered address : %#lx \n", net_addr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movw   $0x1234,-0x12(%rbp)
movq   $0x12345678,-0x20(%rbp)
12
movzwl -0x12(%rbp),%edi
call   1030 <htons@plt>
mov    %ax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <htonl@plt>
mov    %rax,-0x28(%rbp)
movzwl -0x12(%rbp),%eax
mov    %eax,%esi
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
movzwl -0x14(%rbp),%eax
mov    %eax,%esi
lea    0xe90(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe9d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xeae(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x1234,%edi
call   1030 <htons@plt>
mov    %eax,%ebx
mov    $0x12345678,%edi
call   1050 <htonl@plt>
mov    %rax,%r14
lea    0xeac(%rip),%rdi
mov    $0x1234,%esi
call   1040 <printf@plt>
movzwl %bx,%esi
lea    0xeb5(%rip),%rdi
call   1040 <printf@plt>
lea    0xec6(%rip),%rdi
mov    $0x12345678,%esi
call   1040 <printf@plt>
lea    0xed6(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Host ordered port : %#x \0A\00"
@.str.1 = [29 x i8] c"Network ordered port : %#x \0A\00"
@.str.2 = [33 x i8] c"Host ordered address : %#lx \0A\00"
@.str.3 = [33 x i8] c"Network ordered address : %#lx \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i16
%7 = alloca i16
%8 = alloca i64
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i16 4660, i16* %6
store i64 305419896, i64* %8
%10 = load i16, i16* %6
%11 = call zeroext i16 @htons(i16 zeroext %10)
store i16 %11, i16* %7
%12 = load i64, i64* %8
%13 = call i64 @htonl(i64 %12)
store i64 %13, i64* %9
%14 = load i16, i16* %6
%15 = zext i16 %14 to i64
%16 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 %15)
%17 = load i16, i16* %7
%18 = zext i16 %17 to i64
%19 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i64 %18)
%20 = load i64, i64* %8
%21 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i64 %20)
%22 = load i64, i64* %9
%23 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i64 %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [29 x i8] c"Host ordered port : %#x \0A\00"
@.str.1 = [29 x i8] c"Network ordered port : %#x \0A\00"
@.str.2 = [33 x i8] c"Host ordered address : %#lx \0A\00"
@.str.3 = [33 x i8] c"Network ordered address : %#lx \0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call zeroext i16 @htons(i16 zeroext 4660)
%4 = tail call i64 @htonl(i64 305419896)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 4660)
%6 = zext i16 %3 to i64
%7 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i64 %6)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i64 305419896)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i64 %4)
ret i32 0
}