#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);
unsigned int ntohl(unsigned int);
int /*<<< orphan*/ printf(char *, unsigned char, unsigned char, unsigned char,
                          unsigned char);
int main(void) {
  unsigned int x = 0x12345678;
  unsigned char *p = (unsigned char *)&x;
  printf("%0x_%0x_%0x_%0x\n", p[0], p[1], p[2], p[3]);
  unsigned int y = htonl(x);
  p = (unsigned char *)&y;
  printf("%0x_%0x_%0x_%0x\n", p[0], p[1], p[2], p[3]);
  unsigned int z = ntohl(y);
  p = (unsigned char *)&z;
  printf("%0x_%0x_%0x_%0x\n", p[0], p[1], p[2], p[3]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x12345678,-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    0xe92(%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,-0x14(%rbp)
lea    -0x14(%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    0xe4b(%rip),%rdi
movzbl %sil,%esi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl 0x3(%rax),%r8d
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <ntohl@plt>
mov    %eax,-0x18(%rbp)
lea    -0x18(%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    0xe04(%rip),%rdi
movzbl %sil,%esi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl 0x3(%rax),%r8d
call   1030 <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),%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,%ebx
mov    %eax,%ecx
shr    $0x10,%ecx
shr    $0x18,%eax
movzbl %bl,%esi
movzbl %bh,%edx
movzbl %cl,%ecx
mov    %r14,%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
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 = [17 x i8] c"%0x_%0x_%0x_%0x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 305419896, i32* %2
%6 = bitcast i32* %2 to i8*
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 0
%9 = load i8, i8* %8
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %11
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 2
%15 = load i8, i8* %14
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 3
%18 = load i8, i8* %17
%19 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 zeroext %9, i8 zeroext %12, i8 zeroext %15, i8 zeroext %18)
%20 = load i32, i32* %2
%21 = call i32 @htonl(i32 %20)
store i32 %21, i32* %4
%22 = bitcast i32* %4 to i8*
store i8* %22, i8** %3
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i64 2
%31 = load i8, i8* %30
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i64 3
%34 = load i8, i8* %33
%35 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 zeroext %25, i8 zeroext %28, i8 zeroext %31, i8 zeroext %34)
%36 = load i32, i32* %4
%37 = call i32 @ntohl(i32 %36)
store i32 %37, i32* %5
%38 = bitcast i32* %5 to i8*
store i8* %38, i8** %3
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i64 0
%41 = load i8, i8* %40
%42 = load i8*, i8** %3
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8, i8* %43
%45 = load i8*, i8** %3
%46 = getelementptr inbounds i8, i8* %45, i64 2
%47 = load i8, i8* %46
%48 = load i8*, i8** %3
%49 = getelementptr inbounds i8, i8* %48, i64 3
%50 = load i8, i8* %49
%51 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 zeroext %41, i8 zeroext %44, i8 zeroext %47, i8 zeroext %50)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"%0x_%0x_%0x_%0x\0A\00"
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 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 ([17 x i8], [17 x i8]* @.str, 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 ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 zeroext %12, i8 zeroext %14, i8 zeroext %16, i8 zeroext %18)
ret i32 0
}