#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;
  printf("0x12345678: %d\n", host_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
mov    -0x10(%rbp),%rsi
lea    0xea8(%rip),%rdi
call   1040 <printf@plt>
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
lea    0xec5(%rip),%rdi
mov    $0x12345678,%esi
call   1040 <printf@plt>
mov    $0x1234,%edi
call   1030 <htons@plt>
mov    %eax,%ebx
mov    $0x12345678,%edi
call   1050 <htonl@plt>
mov    %rax,%r14
lea    0xeab(%rip),%rdi
mov    $0x1234,%esi
call   1040 <printf@plt>
movzwl %bx,%esi
lea    0xeaf(%rip),%rdi
call   1040 <printf@plt>
lea    0xebe(%rip),%rdi
mov    $0x12345678,%esi
call   1040 <printf@plt>
lea    0xec9(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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