#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 */
typedef int uint32_t;

/* Variables and functions */
int htonl(int);
int ntohl(int);
int /*<<< orphan*/ printf(char *, unsigned char, unsigned char, unsigned char,
                          unsigned char);
int main() {
  uint32_t value = 0x01020304;
  unsigned char *ptr = (char *)&value;
  printf("Host byte order: %x %x %x %x\n", ptr[0], ptr[1], ptr[2], ptr[3]);
  value = htonl(value);
  printf("Network byte order: %x %x %x %x\n", ptr[0], ptr[1], ptr[2], ptr[3]);
  value = ntohl(value);
  printf("RE: Host byte order: %x %x %x %x\n", ptr[0], ptr[1], ptr[2], ptr[3]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1020304,-0x8(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%sil
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%dl
mov    -0x10(%rbp),%rax
mov    0x2(%rax),%cl
mov    -0x10(%rbp),%rax
lea    0xeb7(%rip),%rdi
movzbl %sil,%esi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl 0x3(%rax),%r8d
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1040 <htonl@plt>
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%sil
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%dl
mov    -0x10(%rbp),%rax
mov    0x2(%rax),%cl
mov    -0x10(%rbp),%rax
lea    0xe53(%rip),%rdi
movzbl %sil,%esi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl 0x3(%rax),%r8d
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <ntohl@plt>
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%sil
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%dl
mov    -0x10(%rbp),%rax
mov    0x2(%rax),%cl
mov    -0x10(%rbp),%rax
lea    0xe35(%rip),%rdi
movzbl %sil,%esi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl 0x3(%rax),%r8d
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeed(%rip),%rdi
mov    $0x4,%esi
mov    $0x3,%edx
mov    $0x2,%ecx
mov    $0x1,%r8d
call   1030 <printf@plt>
mov    $0x1020304,%edi
call   1040 <htonl@plt>
mov    %eax,%ebx
mov    %eax,%ecx
shr    $0x10,%ecx
shr    $0x18,%eax
movzbl %bl,%esi
movzbl %bh,%edx
movzbl %cl,%ecx
lea    0xe8a(%rip),%rdi
mov    %eax,%r8d
call   1030 <printf@plt>
mov    %ebx,%edi
call   1050 <ntohl@plt>
mov    %eax,%ecx
shr    $0x10,%ecx
mov    %eax,%ebx
shr    $0x18,%ebx
movzbl %al,%esi
movzbl %ah,%edx
movzbl %cl,%ecx
lea    0xe82(%rip),%rdi
mov    %ebx,%r8d
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Host byte order: %x %x %x %x\0A\00"
@.str.1 = [33 x i8] c"Network byte order: %x %x %x %x\0A\00"
@.str.2 = [34 x i8] c"RE: Host byte order: %x %x %x %x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
store i32 16909060, i32* %2
%4 = bitcast i32* %2 to i8*
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8, i8* %9
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 2
%13 = load i8, i8* %12
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 3
%16 = load i8, i8* %15
%17 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8 zeroext %7, i8 zeroext %10, i8 zeroext %13, i8 zeroext %16)
%18 = load i32, i32* %2
%19 = call i32 @htonl(i32 %18)
store i32 %19, i32* %2
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8, i8* %24
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 2
%28 = load i8, i8* %27
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i64 3
%31 = load i8, i8* %30
%32 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %22, i8 zeroext %25, i8 zeroext %28, i8 zeroext %31)
%33 = load i32, i32* %2
%34 = call i32 @ntohl(i32 %33)
store i32 %34, i32* %2
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = load i8*, i8** %3
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i8, i8* %39
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i64 2
%43 = load i8, i8* %42
%44 = load i8*, i8** %3
%45 = getelementptr inbounds i8, i8* %44, i64 3
%46 = load i8, i8* %45
%47 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %37, i8 zeroext %40, i8 zeroext %43, i8 zeroext %46)
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"Host byte order: %x %x %x %x\0A\00"
@.str.1 = [33 x i8] c"Network byte order: %x %x %x %x\0A\00"
@.str.2 = [34 x i8] c"RE: Host byte order: %x %x %x %x\0A\00"
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8 zeroext 4, i8 zeroext 3, i8 zeroext 2, i8 zeroext 1)
%2 = tail call i32 @htonl(i32 16909060)
%3 = trunc i32 %2 to i8
%4 = lshr i32 %2, 8
%5 = trunc i32 %4 to i8
%6 = lshr i32 %2, 16
%7 = trunc i32 %6 to i8
%8 = lshr i32 %2, 24
%9 = trunc i32 %8 to i8
%10 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %3, i8 zeroext %5, i8 zeroext %7, i8 zeroext %9)
%11 = tail call i32 @ntohl(i32 %2)
%12 = trunc i32 %11 to i8
%13 = lshr i32 %11, 8
%14 = trunc i32 %13 to i8
%15 = lshr i32 %11, 16
%16 = trunc i32 %15 to i8
%17 = lshr i32 %11, 24
%18 = trunc i32 %17 to i8
%19 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %12, i8 zeroext %14, i8 zeroext %16, i8 zeroext %18)
ret i32 0
}