#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 detect_endian();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
char *to_binary(int, char *, int);
int main() {
  printf("Enter n: ");
  int n;
  char s[100];
  scanf("%d", &n);
  printf("Bit pattern of %d in    big-endian is: %s\n", n, to_binary(n, s, 1));
  printf("Bit pattern of %d in little-endian is: %s\n", n, to_binary(n, s, 0));
  int detect = detect_endian();
  printf("Detect endianness of your PC's architecture: %s\n",
         detect == 0 ? "undefined"
                     : (detect == 1 ? "little-endian" : "big-endian"));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xea3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x1,%edx
call   1040 <to_binary@plt>
mov    -0x7c(%rbp),%esi
mov    %rax,%rdx
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x78(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x70(%rbp),%rsi
xor    %edx,%edx
call   1040 <to_binary@plt>
mov    -0x78(%rbp),%esi
mov    %rax,%rdx
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <detect_endian@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
jne    11ea <main+0xaa>
lea    0xeb6(%rip),%rax
mov    %rax,-0x88(%rbp)
jmp    1209 <main+0xc9>
mov    -0x74(%rbp),%edx
lea    0xeb8(%rip),%rax
lea    0xea3(%rip),%rcx
cmp    $0x1,%edx
cmove  %rcx,%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rsi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x78,%rsp
lea    0xeb2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeae(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%ebx
lea    0x10(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <to_binary@plt>
lea    0xe88(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%ebx
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <to_binary@plt>
lea    0xe90(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <detect_endian@plt>
cmp    $0x1,%eax
lea    0xed9(%rip),%rcx
lea    0xee0(%rip),%rdx
cmove  %rcx,%rdx
test   %eax,%eax
lea    0xebb(%rip),%rsi
cmovne %rdx,%rsi
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"Enter n: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [43 x i8] c"Bit pattern of %d in big-endian is: %s\0A\00"
@.str.3 = [43 x i8] c"Bit pattern of %d in little-endian is: %s\0A\00"
@.str.4 = [49 x i8] c"Detect endianness of your PC's architecture: %s\0A\00"
@.str.5 = [10 x i8] c"undefined\00"
@.str.6 = [14 x i8] c"little-endian\00"
@.str.7 = [11 x i8] c"big-endian\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = load i32, i32* %2
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%10 = call i8* @to_binary(i32 %8, i8* %9, i32 1)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %7, i8* %10)
%12 = load i32, i32* %2
%13 = load i32, i32* %2
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%15 = call i8* @to_binary(i32 %13, i8* %14, i32 0)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %12, i8* %15)
%17 = call i32 (...) @detect_endian()
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %0
br label %26
21: ; preds = %0
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 1
%24 = zext i1 %23 to i64
%25 = select i1 %23, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0)
br label %26
26: ; preds = %21, %20
%27 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), %20 ], [ %25, %21 ]
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i8* %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"Enter n: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [43 x i8] c"Bit pattern of %d in big-endian is: %s\0A\00"
@.str.3 = [43 x i8] c"Bit pattern of %d in little-endian is: %s\0A\00"
@.str.4 = [49 x i8] c"Detect endianness of your PC's architecture: %s\0A\00"
@.str.5 = [10 x i8] c"undefined\00"
@.str.6 = [14 x i8] c"little-endian\00"
@.str.7 = [11 x i8] c"big-endian\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%4 = bitcast i32* %1 to i8*
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = call i8* @to_binary(i32 %7, i8* %5, i32 1)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %7, i8* %8)
%10 = load i32, i32* %1
%11 = call i8* @to_binary(i32 %10, i8* %5, i32 0)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %10, i8* %11)
%13 = call i32 (...) @detect_endian()
%14 = icmp eq i32 %13, 0
%15 = icmp eq i32 %13, 1
%16 = select i1 %15, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0)
%17 = select i1 %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* %16
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i8* %17)
ret i32 0
}