#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(void) {
  unsigned short host_port = 0x1234, net_port;
  unsigned long host_addr = 0x12345678, 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    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movw   $0x1234,-0x6(%rbp)
movq   $0x12345678,-0x10(%rbp)
12
movzwl -0x6(%rbp),%edi
call   1030 <htons@plt>
mov    %ax,-0x8(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <htonl@plt>
mov    %rax,-0x18(%rbp)
movzwl -0x6(%rbp),%eax
mov    %eax,%esi
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
movzwl -0x8(%rbp),%eax
mov    %eax,%esi
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe9d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xea9(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%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    0xeb0(%rip),%rdi
call   1040 <printf@plt>
lea    0xebf(%rip),%rdi
mov    $0x12345678,%esi
call   1040 <printf@plt>
lea    0xeca(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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