#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 /*<<< orphan*/ print_binary(unsigned int);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, unsigned int *);
unsigned int swap_endianness(unsigned int);
int main(void) {
  printf("Enter an integer to see how it looks when endianness changes\n");
  printf("> ");
  unsigned n;
  while (scanf("%u", &n) == 1) {
    printf("Received:\n");
    printf("\tBase 10: %u\n\tBinary: ", n);
    print_binary(n);
    unsigned swapped = swap_endianness(n);
    printf("\nAfter swapping endianness:\n");
    printf("\tBase 10: %u\n\tBinary: ", swapped);
    print_binary(swapped);
    printf("\n> ");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf1d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xecc(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    11f0 <main+0xb0>
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <print_binary@plt>
mov    -0x8(%rbp),%edi
call   1030 <swap_endianness@plt>
mov    %eax,-0xc(%rbp)
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <print_binary@plt>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    116b <main+0x2b>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebc(%rip),%rdi
call   1030 <puts@plt>
lea    0xead(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe84(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    1216 <main+0xc6>
lea    0xe6d(%rip),%rbx
lea    0xec8(%rip),%r15
lea    0xe76(%rip),%r12
lea    0xe55(%rip),%r13
lea    0x4(%rsp),%rbp
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%edi
call   1060 <print_binary@plt>
mov    0x4(%rsp),%edi
call   1040 <swap_endianness@plt>
mov    %eax,%r14d
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%edi
call   1060 <print_binary@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
je     11b0 <main+0x60>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [62 x i8] c"Enter an integer to see how it looks when endianness changes\0A\00"
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [11 x i8] c"Received:\0A\00"
@.str.4 = [23 x i8] c"\09Base 10: %u\0A\09Binary: \00"
@.str.5 = [29 x i8] c"\0AAfter swapping endianness:\0A\00"
@.str.6 = [4 x i8] c"\0A> \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %9, %0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %23
9: ; preds = %6
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%11 = load i32, i32* %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %2
%14 = call i32 @print_binary(i32 %13)
%15 = load i32, i32* %2
%16 = call i32 @swap_endianness(i32 %15)
store i32 %16, i32* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%18 = load i32, i32* %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %3
%21 = call i32 @print_binary(i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %6
23: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [3 x i8] c"%u\00"
@.str.4 = [23 x i8] c"\09Base 10: %u\0A\09Binary: \00"
@.str.6 = [4 x i8] c"\0A> \00"
@str = [61 x i8] c"Enter an integer to see how it looks when endianness changes\00"
@str.7 = [10 x i8] c"Received:\00"
@str.8 = [28 x i8] c"\0AAfter swapping endianness:\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = bitcast i32* %1 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %21
7: ; preds = %0, %7
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.7, i64 0, i64 0))
%9 = load i32, i32* %1
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %1
%12 = call i32 @print_binary(i32 %11)
%13 = load i32, i32* %1
%14 = call i32 @swap_endianness(i32 %13)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.8, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%17 = call i32 @print_binary(i32 %14)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%20 = icmp eq i32 %19, 1
br i1 %20, label %7, label %21
21: ; preds = %7, %0
ret i32 0
}