#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*/ heap_sort(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int a[50];
  srand(time(NULL));
  int i;
  for (i = 0; i < 50; i++) {
    a[i] = rand() % (1000 - 0) + 0;
    printf("%d ", a[i]);
  }
  printf("\n");
  heap_sort(a, 50);
  for (i = 0; i < 50; i++) {
    printf("%d ", a[i]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movl   $0x0,-0xe4(%rbp)
cmpl   $0x32,-0xe4(%rbp)
jge    11e0 <main+0x90>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
add    $0x0,%edx
movslq -0xe4(%rbp),%rax
mov    %edx,-0xe0(%rbp,%rax,4)
movslq -0xe4(%rbp),%rax
mov    -0xe0(%rbp,%rax,4),%esi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xe4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xe4(%rbp)
jmp    1183 <main+0x33>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xe0(%rbp),%rdi
mov    $0x32,%esi
call   1030 <heap_sort@plt>
movl   $0x0,-0xe4(%rbp)
cmpl   $0x32,-0xe4(%rbp)
jge    1246 <main+0xf6>
movslq -0xe4(%rbp),%rax
mov    -0xe0(%rbp,%rax,4),%esi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xe4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xe4(%rbp)
jmp    1209 <main+0xb9>
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xc8,%rsp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
lea    0xe81(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <rand@plt>
movslq %eax,%rsi
imul   $0x10624dd3,%rsi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
imul   $0x3e8,%eax,%eax
sub    %eax,%esi
mov    %esi,(%rsp,%rbx,4)
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    $0x32,%rbx
jne    1190 <main+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rsp,%rdi
mov    $0x32,%esi
call   1040 <heap_sort@plt>
lea    0xe15(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
mov    (%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    $0x32,%rbx
jne    11f0 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [50 x i32]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @time(i32* null)
%9 = call i32 @srand(i32 %8)
store i32 0, i32* %7
br label %10
10: ; preds = %25, %2
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 50
br i1 %12, label %13, label %28
13: ; preds = %10
%14 = call i32 (...) @rand()
%15 = srem i32 %14, 1000
%16 = add nsw i32 %15, 0
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [50 x i32], [50 x i32]* %6, i64 0, i64 %18
store i32 %16, i32* %19
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [50 x i32], [50 x i32]* %6, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %13
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %10
28: ; preds = %10
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = getelementptr inbounds [50 x i32], [50 x i32]* %6, i64 0, i64 0
%31 = call i32 @heap_sort(i32* %30, i32 50)
store i32 0, i32* %7
br label %32
32: ; preds = %41, %28
%33 = load i32, i32* %7
%34 = icmp slt i32 %33, 50
br i1 %34, label %35, label %44
35: ; preds = %32
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [50 x i32], [50 x i32]* %6, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %35
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %32
44: ; preds = %32
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [50 x i32]
%4 = bitcast [50 x i32]* %3 to i8*
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
br label %7
7: ; preds = %2, %7
%8 = phi i64 [ 0, %2 ], [ %13, %7 ]
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 1000
%11 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %8
store i32 %10, i32* %11
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %10)
%13 = add nuw nsw i64 %8, 1
%14 = icmp eq i64 %13, 50
br i1 %14, label %15, label %7
15: ; preds = %7
%16 = tail call i32 @putchar(i32 10)
%17 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 0
%18 = call i32 @heap_sort(i32* %17, i32 50)
br label %19
19: ; preds = %15, %19
%20 = phi i64 [ 0, %15 ], [ %24, %19 ]
%21 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = add nuw nsw i64 %20, 1
%25 = icmp eq i64 %24, 50
br i1 %25, label %26, label %19
26: ; preds = %19
%27 = call i32 @putchar(i32 10)
ret i32 0
}