#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 htonl(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int a = 0x12345678;
  printf("%x\n", *(char *)&a);
  printf("[0]0x%x\n", *(char *)&a);
  printf("[1]0x%x\n", *((char *)&a + 1));
  printf("[2]0x%x\n", *((char *)&a + 2));
  printf("[3]0x%x\n", *((char *)&a + 3));
  if (*(char *)&a == 0x12)
    printf("big endian \n");
  else if (*(char *)&a == 0x78)
    printf("little endian \n");
  else
    printf("Unknown \n");
  a = htonl(a);
  printf("[0]0x%x\n", *(char *)&a);
  printf("[1]0x%x\n", *((char *)&a + 1));
  printf("[2]0x%x\n", *((char *)&a + 2));
  printf("[3]0x%x\n", *((char *)&a + 3));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x12345678,-0x8(%rbp)
movsbl -0x8(%rbp),%esi
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x8(%rbp),%esi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x7(%rbp),%esi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x6(%rbp),%esi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x5(%rbp),%esi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x8(%rbp),%eax
cmp    $0x12,%eax
jne    11b0 <main+0x90>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e3 <main+0xc3>
movsbl -0x8(%rbp),%eax
cmp    $0x78,%eax
jne    11d0 <main+0xb0>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11de <main+0xbe>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e3 <main+0xc3>
mov    -0x8(%rbp),%edi
call   1040 <htonl@plt>
mov    %eax,-0x8(%rbp)
movsbl -0x8(%rbp),%esi
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x7(%rbp),%esi
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x6(%rbp),%esi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x5(%rbp),%esi
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xec6(%rip),%rdi
mov    $0x78,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeae(%rip),%rbx
mov    %rbx,%rdi
mov    $0x78,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea1(%rip),%r12
mov    %r12,%rdi
mov    $0x56,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe94(%rip),%r15
mov    %r15,%rdi
mov    $0x34,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe87(%rip),%r14
mov    %r14,%rdi
mov    $0x12,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x12345678,%edi
call   1050 <htonl@plt>
mov    %eax,%ebp
movsbl %bpl,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
shr    $0x8,%eax
movsbl %al,%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
shr    $0x10,%eax
movsbl %al,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
sar    $0x18,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%x\0A\00"
@.str.1 = [9 x i8] c"[0]0x%x\0A\00"
@.str.2 = [9 x i8] c"[1]0x%x\0A\00"
@.str.3 = [9 x i8] c"[2]0x%x\0A\00"
@.str.4 = [9 x i8] c"[3]0x%x\0A\00"
@.str.5 = [13 x i8] c"big endian \0A\00"
@.str.6 = [16 x i8] c"little endian \0A\00"
@.str.7 = [10 x i8] c"Unknown \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 305419896, i32* %2
%3 = bitcast i32* %2 to i8*
%4 = load i8, i8* %3
%5 = sext i8 %4 to i32
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = bitcast i32* %2 to i8*
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = bitcast i32* %2 to i8*
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = bitcast i32* %2 to i8*
%17 = getelementptr inbounds i8, i8* %16, i64 2
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = bitcast i32* %2 to i8*
%22 = getelementptr inbounds i8, i8* %21, i64 3
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %24)
%26 = bitcast i32* %2 to i8*
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 18
br i1 %29, label %30, label %32
30: ; preds = %0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %42
32: ; preds = %0
%33 = bitcast i32* %2 to i8*
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 120
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %41
39: ; preds = %32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
br label %41
41: ; preds = %39, %37
br label %42
42: ; preds = %41, %30
%43 = load i32, i32* %2
%44 = call i32 @htonl(i32 %43)
store i32 %44, i32* %2
%45 = bitcast i32* %2 to i8*
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %47)
%49 = bitcast i32* %2 to i8*
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %52)
%54 = bitcast i32* %2 to i8*
%55 = getelementptr inbounds i8, i8* %54, i64 2
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %57)
%59 = bitcast i32* %2 to i8*
%60 = getelementptr inbounds i8, i8* %59, i64 3
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %62)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%x\0A\00"
@.str.1 = [9 x i8] c"[0]0x%x\0A\00"
@.str.2 = [9 x i8] c"[1]0x%x\0A\00"
@.str.3 = [9 x i8] c"[2]0x%x\0A\00"
@.str.4 = [9 x i8] c"[3]0x%x\0A\00"
@str = [15 x i8] c"little endian \00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 120)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 120)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 86)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 52)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 18)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @htonl(i32 305419896)
%8 = shl i32 %7, 24
%9 = ashr exact i32 %8, 24
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = shl i32 %7, 16
%12 = ashr i32 %11, 24
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = shl i32 %7, 8
%15 = ashr i32 %14, 24
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = ashr i32 %7, 24
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %17)
ret i32 0
}