#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 */
int EXIT_SUCCESS;
long htonl(long);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int i;
  long x = 0x78A27D0;
  unsigned char *ptr = (char *)&x;
  printf("Valori in host byte order\n");
  printf(" x in Esadecimale: %x\n", x);
  printf("           x byte: ");
  for (i = 0; i < sizeof(long); i++)
    printf("%x\t", ptr[i]);
  printf("\n\n");
  printf("Valori in network byte order\n");
  x = htonl(x);
  printf("dopo la conversione con htonl()\n");
  printf(" x in Esadecimale: %x\n", x);
  printf("           x byte: ");
  for (i = 0; i < sizeof(long); i++)
    printf("%x\t", ptr[i]);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x78a27d0,-0x10(%rbp)
07
lea    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
movslq -0x8(%rbp),%rax
cmp    $0x8,%rax
jae    11aa <main+0x8a>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1174 <main+0x54>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <htonl@plt>
mov    %rax,-0x10(%rbp)
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
movslq -0x8(%rbp),%rax
cmp    $0x8,%rax
jae    123e <main+0x11e>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1208 <main+0xe8>
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeea(%rip),%rdi
call   1030 <puts@plt>
lea    0xeaf(%rip),%rdi
mov    $0x78a27d0,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb9(%rip),%r13
mov    %r13,%rdi
mov    $0xd0,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
mov    $0x27,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
mov    $0x8a,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe30(%rip),%rdi
call   1030 <puts@plt>
lea    0xe58(%rip),%rdi
call   1030 <puts@plt>
mov    $0x78a27d0,%edi
call   1050 <htonl@plt>
mov    %rax,%rbx
mov    %ebx,%r12d
shr    $0x10,%r12d
shr    $0x18,%eax
mov    %eax,0xc(%rsp)
mov    %rbx,%r15
shr    $0x20,%r15
mov    %rbx,%r14
shr    $0x28,%r14
mov    %rbx,%rbp
shr    $0x30,%rbp
mov    %rbx,%rax
shr    $0x38,%rax
mov    %rax,0x10(%rsp)
lea    0xe2d(%rip),%rdi
call   1030 <puts@plt>
lea    0xdbb(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdc1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %bl,%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %bh,%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %r12b,%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
mov    0xc(%rsp),%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %r15b,%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %r14b,%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %bpl,%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
mov    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d0d(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Valori in host byte order\0A\00"
@.str.1 = [23 x i8] c" x in Esadecimale: %x\0A\00"
@.str.2 = [20 x i8] c" x byte: \00"
@.str.3 = [4 x i8] c"%x\09\00"
@.str.4 = [3 x i8] c"\0A\0A\00"
@.str.5 = [30 x i8] c"Valori in network byte order\0A\00"
@.str.6 = [33 x i8] c"dopo la conversione con htonl()\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i8*
store i32 0, i32* %1
store i64 126494672, i64* %3
%5 = bitcast i64* %3 to i8*
store i8* %5, i8** %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%7 = load i64, i64* %3
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %10
10: ; preds = %22, %0
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = icmp ult i64 %12, 8
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %14
%23 = load i32, i32* %2
%24 = add nsw i32 %23, 1
store i32 %24, i32* %2
br label %10
25: ; preds = %10
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%28 = load i64, i64* %3
%29 = call i64 @htonl(i64 %28)
store i64 %29, i64* %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
%31 = load i64, i64* %3
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %34
34: ; preds = %46, %25
%35 = load i32, i32* %2
%36 = sext i32 %35 to i64
%37 = icmp ult i64 %36, 8
br i1 %37, label %38, label %49
38: ; preds = %34
%39 = load i8*, i8** %4
%40 = load i32, i32* %2
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %38
%47 = load i32, i32* %2
%48 = add nsw i32 %47, 1
store i32 %48, i32* %2
br label %34
49: ; preds = %34
%50 = load i32, i32* @EXIT_SUCCESS
ret i32 %50
}

LLVM IR (-O2):
@.str.1 = [23 x i8] c" x in Esadecimale: %x\0A\00"
@.str.2 = [20 x i8] c" x byte: \00"
@.str.3 = [4 x i8] c"%x\09\00"
@EXIT_SUCCESS = global i32 0
@str = [26 x i8] c"Valori in host byte order\00"
@str.7 = [2 x i8] c"\0A\00"
@str.8 = [29 x i8] c"Valori in network byte order\00"
@str.9 = [32 x i8] c"dopo la conversione con htonl()\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 126494672)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 208)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 39)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 138)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 7)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 0)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 0)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 0)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 0)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.7, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.8, i64 0, i64 0))
%14 = tail call i64 @htonl(i64 126494672)
%15 = trunc i64 %14 to i32
%16 = trunc i64 %14 to i32
%17 = lshr i32 %16, 8
%18 = trunc i64 %14 to i32
%19 = lshr i32 %18, 16
%20 = trunc i64 %14 to i32
%21 = lshr i32 %20, 24
%22 = lshr i64 %14, 32
%23 = trunc i64 %22 to i32
%24 = lshr i64 %14, 40
%25 = trunc i64 %24 to i32
%26 = lshr i64 %14, 48
%27 = trunc i64 %26 to i32
%28 = lshr i64 %14, 56
%29 = trunc i64 %28 to i32
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.9, i64 0, i64 0))
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 %14)
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%33 = and i32 %15, 255
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%35 = and i32 %17, 255
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = and i32 %19, 255
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%40 = and i32 %23, 255
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %40)
%42 = and i32 %25, 255
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %42)
%44 = and i32 %27, 255
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%47 = load i32, i32* @EXIT_SUCCESS
ret i32 %47
}