#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*/ heapsort(int *, int);
int /*<<< orphan*/ print_list(int *, int);
int /*<<< orphan*/ printf(char *);
int rand();
int main() {
  int l[50];
  int size = 50;
  int c;
  for (c = 0; c < size; c++)
    l[c] = rand() % 100;
  printf("out of order:\n");
  print_list(l, size - 1);
  printf("in order:\n");
  heapsort(l, size - 1);
  print_list(l, size - 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x32,-0xd4(%rbp)
movl   $0x0,-0xd8(%rbp)
mov    -0xd8(%rbp),%eax
cmp    -0xd4(%rbp),%eax
jge    11a9 <main+0x69>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
movslq -0xd8(%rbp),%rax
mov    %edx,-0xd0(%rbp,%rax,4)
mov    -0xd8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd8(%rbp)
jmp    1166 <main+0x26>
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
lea    -0xd0(%rbp),%rdi
mov    -0xd4(%rbp),%esi
sub    $0x1,%esi
call   1030 <print_list@plt>
lea    0xe3e(%rip),%rdi
call   1040 <printf@plt>
lea    -0xd0(%rbp),%rdi
mov    -0xd4(%rbp),%esi
sub    $0x1,%esi
call   1050 <heapsort@plt>
lea    -0xd0(%rbp),%rdi
mov    -0xd4(%rbp),%esi
sub    $0x1,%esi
call   1030 <print_list@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xd0,%rsp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x32,%rbx
jne    1150 <main+0x10>
lea    0xe7a(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x31,%esi
call   1040 <print_list@plt>
lea    0xe6c(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x31,%esi
call   1050 <heapsort@plt>
mov    %rbx,%rdi
mov    $0x31,%esi
call   1040 <print_list@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"out of order:\0A\00"
@.str.1 = [11 x i8] c"in order:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 50, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %15, %0
%6 = load i32, i32* %4
%7 = load i32, i32* %3
%8 = icmp slt i32 %6, %7
br i1 %8, label %9, label %18
9: ; preds = %5
%10 = call i32 (...) @rand()
%11 = srem i32 %10, 100
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %13
store i32 %11, i32* %14
br label %15
15: ; preds = %9
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
br label %5
18: ; preds = %5
%19 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%20 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 0
%21 = load i32, i32* %3
%22 = sub nsw i32 %21, 1
%23 = call i32 @print_list(i32* %20, i32 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%25 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 0
%26 = load i32, i32* %3
%27 = sub nsw i32 %26, 1
%28 = call i32 @heapsort(i32* %25, i32 %27)
%29 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 0
%30 = load i32, i32* %3
%31 = sub nsw i32 %30, 1
%32 = call i32 @print_list(i32* %29, i32 %31)
ret i32 0
}

LLVM IR (-O2):
@str = [14 x i8] c"out of order:\00"
@str.2 = [10 x i8] c"in order:\00"
define i32 @main() {
%1 = alloca [50 x i32]
%2 = bitcast [50 x i32]* %1 to i8*
br label %3
3: ; preds = %0, %3
%4 = phi i64 [ 0, %0 ], [ %8, %3 ]
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 100
%7 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 %4
store i32 %6, i32* %7
%8 = add nuw nsw i64 %4, 1
%9 = icmp eq i64 %8, 50
br i1 %9, label %10, label %3
10: ; preds = %3
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%12 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 0
%13 = call i32 @print_list(i32* %12, i32 49)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.2, i64 0, i64 0))
%15 = call i32 @heapsort(i32* %12, i32 49)
%16 = call i32 @print_list(i32* %12, i32 49)
ret i32 0
}