#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 int htonl(unsigned int);
int /*<<< orphan*/ printf(char *, unsigned char, unsigned char, unsigned char,
                          unsigned char);
int main(void) {
  unsigned a = 0X12345678;
  unsigned char *p = (unsigned char *)&a;
  printf("%X %X %X %X\n", p[0], p[1], p[2], p[3]);
  a = htonl(a);
  p = (unsigned char *)&a;
  printf("%X %X %X %X\n", p[0], p[1], p[2], p[3]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x12345678,-0x4(%rbp)
lea    -0x4(%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    0xea9(%rip),%rdi
movzbl %sil,%esi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl 0x3(%rax),%r8d
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
call   1040 <htonl@plt>
mov    %eax,-0x4(%rbp)
lea    -0x4(%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    0xe62(%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   %r14
push   %rbx
push   %rax
lea    0xed5(%rip),%r14
mov    %r14,%rdi
mov    $0x78,%esi
mov    $0x56,%edx
mov    $0x34,%ecx
mov    $0x12,%r8d
call   1030 <printf@plt>
mov    $0x12345678,%edi
call   1040 <htonl@plt>
mov    %eax,%ecx
shr    $0x10,%ecx
mov    %eax,%ebx
shr    $0x18,%ebx
movzbl %al,%esi
movzbl %ah,%edx
movzbl %cl,%ecx
mov    %r14,%rdi
mov    %ebx,%r8d
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"%X %X %X %X\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 305419896, i32* %1
%3 = bitcast i32* %1 to i8*
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds i8, i8* %4, i64 0
%6 = load i8, i8* %5
%7 = load i8*, i8** %2
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = load i8, i8* %8
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 2
%12 = load i8, i8* %11
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i64 3
%15 = load i8, i8* %14
%16 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8 zeroext %6, i8 zeroext %9, i8 zeroext %12, i8 zeroext %15)
%17 = load i32, i32* %1
%18 = call i32 @htonl(i32 %17)
store i32 %18, i32* %1
%19 = bitcast i32* %1 to i8*
store i8* %19, i8** %2
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = load i8*, i8** %2
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8, i8* %24
%26 = load i8*, i8** %2
%27 = getelementptr inbounds i8, i8* %26, i64 2
%28 = load i8, i8* %27
%29 = load i8*, i8** %2
%30 = getelementptr inbounds i8, i8* %29, i64 3
%31 = load i8, i8* %30
%32 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8 zeroext %22, i8 zeroext %25, i8 zeroext %28, i8 zeroext %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"%X %X %X %X\0A\00"
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8 zeroext 120, i8 zeroext 86, i8 zeroext 52, i8 zeroext 18)
%2 = tail call i32 @htonl(i32 305419896)
%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 ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8 zeroext %3, i8 zeroext %5, i8 zeroext %7, i8 zeroext %9)
ret i32 0
}