#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 big2littlei(int);
scalar_t__ isLittleEndian();
int little2bigi(int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main(void) {
  {
    if (isLittleEndian())
      printf("The host is little endian\n");
    else
      printf("The host is big endian\n");
  }
  {
    srand((unsigned)time(NULL));
    int num = rand();
    printf("big endian number %d is converted to little endian number %d\n",
           num, big2littlei(num));
  }
  {
    srand((unsigned)time(NULL));
    int num = rand();
    printf("little endian number %d is converted to big endian number %d\n",
           num, little2bigi(num));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <isLittleEndian@plt>
cmp    $0x0,%rax
je     11a3 <main+0x33>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b1 <main+0x41>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1080 <rand@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <big2littlei@plt>
mov    -0x14(%rbp),%esi
mov    %eax,%edx
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1080 <rand@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1090 <little2bigi@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%edx
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1080 <isLittleEndian@plt>
test   %rax,%rax
lea    0xeea(%rip),%rax
lea    0xefa(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <big2littlei@plt>
lea    0xe39(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   10a0 <little2bigi@plt>
lea    0xe47(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [27 x i8] c"The host is little endian\0A\00"
@.str.1 = [24 x i8] c"The host is big endian\0A\00"
@.str.2 = [62 x i8] c"big endian number %d is converted to little endian number %d\0A\00"
@.str.3 = [62 x i8] c"little endian number %d is converted to big endian number %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i64 (...) @isLittleEndian()
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %6
%11 = call i64 @time(i32* null)
%12 = trunc i64 %11 to i32
%13 = call i32 @srand(i32 %12)
%14 = call i32 (...) @rand()
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = load i32, i32* %2
%17 = call i32 @big2littlei(i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), i32 %15, i32 %17)
%19 = call i64 @time(i32* null)
%20 = trunc i64 %19 to i32
%21 = call i32 @srand(i32 %20)
%22 = call i32 (...) @rand()
store i32 %22, i32* %3
%23 = load i32, i32* %3
%24 = load i32, i32* %3
%25 = call i32 @little2bigi(i32 %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.3, i64 0, i64 0), i32 %23, i32 %25)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [62 x i8] c"big endian number %d is converted to little endian number %d\0A\00"
@.str.3 = [62 x i8] c"little endian number %d is converted to big endian number %d\0A\00"
@str = [23 x i8] c"The host is big endian\00"
@str.4 = [26 x i8] c"The host is little endian\00"
define i32 @main() {
%1 = tail call i64 (...) @isLittleEndian()
%2 = icmp eq i64 %1, 0
%3 = select i1 %2, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @str.4, i64 0, i64 0)
%4 = tail call i32 @puts(i8* dereferenceable(1) %3)
%5 = tail call i64 @time(i32* null)
%6 = trunc i64 %5 to i32
%7 = tail call i32 @srand(i32 %6)
%8 = tail call i32 (...) @rand()
%9 = tail call i32 @big2littlei(i32 %8)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), i32 %8, i32 %9)
%11 = tail call i64 @time(i32* null)
%12 = trunc i64 %11 to i32
%13 = tail call i32 @srand(i32 %12)
%14 = tail call i32 (...) @rand()
%15 = tail call i32 @little2bigi(i32 %14)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.3, i64 0, i64 0), i32 %14, i32 %15)
ret i32 0
}