#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() {
  unsigned short host_port = 0x1234;
  unsigned long host_address = 0x12345678;
  unsigned short netword_port = htons(host_port);
  unsigned long netword_address = htonl(host_address);
  printf("主机字节序(short) = %#x\n", host_port);
  printf("网络字节序(short) = %#x\n", netword_port);
  printf("主机字节序(long) = %#lx\n", host_address);
  printf("网络字节序(long) = %#lx\n", netword_address);
  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,-0x12(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <htonl@plt>
mov    %rax,-0x20(%rbp)
movzwl -0x6(%rbp),%eax
mov    %eax,%esi
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
movzwl -0x12(%rbp),%eax
mov    %eax,%esi
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xea6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xeb4(%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    0xeb6(%rip),%rdi
call   1040 <printf@plt>
lea    0xec8(%rip),%rdi
mov    $0x12345678,%esi
call   1040 <printf@plt>
lea    0xed5(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [30 x i8] c"\E4\B8\BB\E6\9C\BA\E5\AD\97\E8\8A\82\E5\BA\8F(short) = %#x\0A\00"
@.str.1 = [30 x i8] c"\E7\BD\91\E7\BB\9C\E5\AD\97\E8\8A\82\E5\BA\8F(short) = %#x\0A\00"
@.str.2 = [30 x i8] c"\E4\B8\BB\E6\9C\BA\E5\AD\97\E8\8A\82\E5\BA\8F(long) = %#lx\0A\00"
@.str.3 = [30 x i8] c"\E7\BD\91\E7\BB\9C\E5\AD\97\E8\8A\82\E5\BA\8F(long) = %#lx\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i64
%4 = alloca i16
%5 = alloca i64
store i32 0, i32* %1
store i16 4660, i16* %2
store i64 305419896, i64* %3
%6 = load i16, i16* %2
%7 = call zeroext i16 @htons(i16 zeroext %6)
store i16 %7, i16* %4
%8 = load i64, i64* %3
%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 ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %11)
%13 = load i16, i16* %4
%14 = zext i16 %13 to i64
%15 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i64 %14)
%16 = load i64, i64* %3
%17 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i64 %16)
%18 = load i64, i64* %5
%19 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i64 %18)
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"\E4\B8\BB\E6\9C\BA\E5\AD\97\E8\8A\82\E5\BA\8F(short) = %#x\0A\00"
@.str.1 = [30 x i8] c"\E7\BD\91\E7\BB\9C\E5\AD\97\E8\8A\82\E5\BA\8F(short) = %#x\0A\00"
@.str.2 = [30 x i8] c"\E4\B8\BB\E6\9C\BA\E5\AD\97\E8\8A\82\E5\BA\8F(long) = %#lx\0A\00"
@.str.3 = [30 x i8] c"\E7\BD\91\E7\BB\9C\E5\AD\97\E8\8A\82\E5\BA\8F(long) = %#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 ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 4660)
%4 = zext i16 %1 to i64
%5 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i64 %4)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i64 305419896)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i64 %2)
ret i32 0
}