#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 *, ...);
int main(void) {
  unsigned int x = 0x12345678;
  printf("unsigned int x = 0x%x\n", x);
  unsigned char *p = (unsigned char *)&x;
  printf("host byte order:\n");
  printf("%x %x %x %x\n", p[0], p[1], p[2], p[3]);
  unsigned int y = htonl(x);
  printf("network byte order:\n");
  p = (unsigned char *)&y;
  printf("%x %x %x %x\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)
mov    -0x8(%rbp),%esi
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movzbl (%rax),%esi
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%edx
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%ecx
mov    -0x10(%rbp),%rax
movzbl 0x3(%rax),%r8d
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1040 <htonl@plt>
mov    %eax,-0x14(%rbp)
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x14(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%esi
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%edx
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%ecx
mov    -0x10(%rbp),%rax
movzbl 0x3(%rax),%r8d
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xec2(%rip),%rdi
mov    $0x12345678,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
lea    0xeba(%rip),%r14
mov    %r14,%rdi
mov    $0x78,%esi
mov    $0x56,%edx
mov    $0x34,%ecx
mov    $0x12,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x12345678,%edi
call   1050 <htonl@plt>
mov    %eax,%ebx
mov    %eax,%ebp
shr    $0x10,%ebp
mov    %eax,%r15d
shr    $0x18,%r15d
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
movzbl %bl,%esi
movzbl %bh,%edx
movzbl %bpl,%ecx
mov    %r14,%rdi
mov    %r15d,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [23 x i8] c"unsigned int x = 0x%x\0A\00"
@.str.2 = [13 x i8] c"%x %x %x %x\0A\00"
@str = [17 x i8] c"host byte order:\00"
@str.4 = [20 x i8] c"network byte order:\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 305419896)
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 120, i32 86, i32 52, i32 18)
%4 = tail call i32 @htonl(i32 305419896)
%5 = lshr i32 %4, 8
%6 = lshr i32 %4, 16
%7 = lshr i32 %4, 24
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.4, i64 0, i64 0))
%9 = and i32 %4, 255
%10 = and i32 %5, 255
%11 = and i32 %6, 255
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %9, i32 %10, i32 %11, i32 %7)
ret i32 0
}