#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*/ display_array(int *, int);
int largest_element(int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ shift(int *, int, int);
int main(void) {
  int a[5], i;
  printf("enter the elements: ");
  for (i = 0; i < 5; i++) {
    scanf("%d", &a[i]);
  }
  printf("\n");
  for (i = 5 - 1; i > 0; i--) {
    int index = largest_element(a, i);
    shift(a, 5, index);
  }
  display_array(a, 5);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x5,-0x24(%rbp)
jge    11a5 <main+0x55>
movslq -0x24(%rbp),%rax
lea    -0x20(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe83(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1172 <main+0x22>
lea    0xe6c(%rip),%rdi
call   1040 <printf@plt>
movl   $0x4,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    11f0 <main+0xa0>
lea    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <largest_element@plt>
mov    %eax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    $0x5,%esi
call   1060 <shift@plt>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    11b8 <main+0x68>
lea    -0x20(%rbp),%rdi
mov    $0x5,%esi
call   1030 <display_array@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xe92(%rip),%rdi
call   1050 <printf@plt>
lea    0xe9b(%rip),%rbx
mov    %rsp,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <scanf@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <scanf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <scanf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <scanf@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
mov    $0x4,%esi
call   1060 <largest_element@plt>
mov    %r14,%rdi
mov    $0x5,%esi
mov    %eax,%edx
call   1070 <shift@plt>
mov    %r14,%rdi
mov    $0x3,%esi
call   1060 <largest_element@plt>
mov    %r14,%rdi
mov    $0x5,%esi
mov    %eax,%edx
call   1070 <shift@plt>
mov    %r14,%rdi
mov    $0x2,%esi
call   1060 <largest_element@plt>
mov    %r14,%rdi
mov    $0x5,%esi
mov    %eax,%edx
call   1070 <shift@plt>
mov    %r14,%rdi
mov    $0x1,%esi
call   1060 <largest_element@plt>
mov    %r14,%rdi
mov    $0x5,%esi
mov    %eax,%edx
call   1070 <shift@plt>
mov    %r14,%rdi
mov    $0x5,%esi
call   1040 <display_array@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [21 x i8] c"enter the elements: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %6
6: ; preds = %14, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 5
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 %11
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %12)
br label %14
14: ; preds = %9
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %6
17: ; preds = %6
%18 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 4, i32* %3
br label %19
19: ; preds = %29, %17
%20 = load i32, i32* %3
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %19
%23 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%24 = load i32, i32* %3
%25 = call i32 @largest_element(i32* %23, i32 %24)
store i32 %25, i32* %4
%26 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%27 = load i32, i32* %4
%28 = call i32 @shift(i32* %26, i32 5, i32 %27)
br label %29
29: ; preds = %22
%30 = load i32, i32* %3
%31 = add nsw i32 %30, -1
store i32 %31, i32* %3
br label %19
32: ; preds = %19
%33 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%34 = call i32 @display_array(i32* %33, i32 5)
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"enter the elements: \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca [5 x i32]
%2 = bitcast [5 x i32]* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%6 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 1
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%8 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 2
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%10 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 3
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %10)
%12 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 4
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %12)
%14 = call i32 @putchar(i32 10)
%15 = call i32 @largest_element(i32* %4, i32 4)
%16 = call i32 @shift(i32* %4, i32 5, i32 %15)
%17 = call i32 @largest_element(i32* %4, i32 3)
%18 = call i32 @shift(i32* %4, i32 5, i32 %17)
%19 = call i32 @largest_element(i32* %4, i32 2)
%20 = call i32 @shift(i32* %4, i32 5, i32 %19)
%21 = call i32 @largest_element(i32* %4, i32 1)
%22 = call i32 @shift(i32* %4, i32 5, i32 %21)
%23 = call i32 @display_array(i32* %4, i32 5)
ret i32 0
}