#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int a[50];
  int n;
  printf("Dati un element natural n\n");
  scanf("%d", &n);
  int temp, value;
  for (int h = 0; h < n; ++h) {
    printf("a[%d]= ", h);
    scanf("%d", &a[h]);
    if (h > 1) {
      for (int i = 1; i < n - 1; ++i) {
        value = a[i];
        temp = i;
        while (temp > 0 && a[temp - 1] > value) {
          a[temp] = a[temp - 1];
          --temp;
        }
        a[temp] = value;
      }
    }
    for (int j = 0; j <= h; ++j) {
      printf("%d ", a[j]);
    }
    printf("\n");
  }
  printf("Exit...\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed4(%rip),%rdi
lea    -0xd4(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0xe0(%rbp)
mov    -0xe0(%rbp),%eax
cmp    -0xd4(%rbp),%eax
jge    130a <main+0x1ea>
mov    -0xe0(%rbp),%esi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0xe0(%rbp),%rax
lea    -0xd0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe7c(%rip),%rdi
call   1040 <scanf@plt>
cmpl   $0x1,-0xe0(%rbp)
jle    129c <main+0x17c>
movl   $0x1,-0xe4(%rbp)
mov    -0xe4(%rbp),%eax
mov    -0xd4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1297 <main+0x177>
movslq -0xe4(%rbp),%rax
mov    -0xd0(%rbp,%rax,4),%eax
mov    %eax,-0xdc(%rbp)
mov    -0xe4(%rbp),%eax
mov    %eax,-0xd8(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xd8(%rbp)
mov    %al,-0xe9(%rbp)
jle    1228 <main+0x108>
mov    -0xd8(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0xd0(%rbp,%rax,4),%eax
cmp    -0xdc(%rbp),%eax
setg   %al
mov    %al,-0xe9(%rbp)
mov    -0xe9(%rbp),%al
test   $0x1,%al
jne    123b <main+0x11b>
jmp    126f <main+0x14f>
mov    -0xd8(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0xd0(%rbp,%rax,4),%ecx
movslq -0xd8(%rbp),%rax
mov    %ecx,-0xd0(%rbp,%rax,4)
mov    -0xd8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xd8(%rbp)
jmp    11f2 <main+0xd2>
mov    -0xdc(%rbp),%ecx
movslq -0xd8(%rbp),%rax
mov    %ecx,-0xd0(%rbp,%rax,4)
mov    -0xe4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xe4(%rbp)
jmp    11bb <main+0x9b>
jmp    129c <main+0x17c>
movl   $0x0,-0xe8(%rbp)
mov    -0xe8(%rbp),%eax
cmp    -0xe0(%rbp),%eax
jg     12e8 <main+0x1c8>
movslq -0xe8(%rbp),%rax
mov    -0xd0(%rbp,%rax,4),%esi
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xe8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xe8(%rbp)
jmp    12a6 <main+0x186>
lea    0xd42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xe0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xe0(%rbp)
jmp    115d <main+0x3d>
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
lea    0xeb7(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9c(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1277 <main+0x137>
mov    $0x1,%ebx
lea    0xe7e(%rip),%r14
lea    0xe74(%rip),%r15
lea    0xe78(%rip),%r13
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    (%rsp,%r12,4),%rsi
add    $0x10,%rsi
mov    %r15,%rdi
call   1060 <scanf@plt>
cmp    $0x1,%r12
jbe    1230 <main+0xf0>
mov    0xc(%rsp),%eax
cmp    $0x3,%eax
jl     1230 <main+0xf0>
add    $0xffffffff,%eax
mov    $0x1,%ecx
jmp    11f0 <main+0xb0>
cs nopw 0x0(%rax,%rax,1)
movslq %esi,%rsi
mov    %edx,0x10(%rsp,%rsi,4)
add    $0x1,%rcx
cmp    %rax,%rcx
je     1230 <main+0xf0>
mov    0x10(%rsp,%rcx,4),%edx
mov    %rcx,%rsi
nopw   0x0(%rax,%rax,1)
lea    -0x1(%rsi),%rdi
mov    %edi,%ebp
mov    0x10(%rsp,%rbp,4),%ebp
cmp    %edx,%ebp
jle    11e0 <main+0xa0>
mov    %ebp,0x10(%rsp,%rsi,4)
lea    0x1(%rdi),%rbp
mov    %rdi,%rsi
cmp    $0x1,%rbp
jg     1200 <main+0xc0>
xor    %esi,%esi
jmp    11e0 <main+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x10(%rsp,%rbp,4),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1240 <main+0x100>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r12
movslq 0xc(%rsp),%rax
add    $0x1,%rbx
cmp    %rax,%r12
jl     11a0 <main+0x60>
lea    0xdab(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Dati un element natural n\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [8 x i8] c"a[%d]= \00"
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [9 x i8] c"Exit...\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
store i32 0, i32* %6
br label %11
11: ; preds = %85, %0
%12 = load i32, i32* %6
%13 = load i32, i32* %3
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %88
15: ; preds = %11
%16 = load i32, i32* %6
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %19
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %20)
%22 = load i32, i32* %6
%23 = icmp sgt i32 %22, 1
br i1 %23, label %24, label %69
24: ; preds = %15
store i32 1, i32* %7
br label %25
25: ; preds = %65, %24
%26 = load i32, i32* %7
%27 = load i32, i32* %3
%28 = sub nsw i32 %27, 1
%29 = icmp slt i32 %26, %28
br i1 %29, label %30, label %68
30: ; preds = %25
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %32
%34 = load i32, i32* %33
store i32 %34, i32* %5
%35 = load i32, i32* %7
store i32 %35, i32* %4
br label %36
36: ; preds = %49, %30
%37 = load i32, i32* %4
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %47
39: ; preds = %36
%40 = load i32, i32* %4
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = load i32, i32* %5
%46 = icmp sgt i32 %44, %45
br label %47
47: ; preds = %39, %36
%48 = phi i1 [ false, %36 ], [ %46, %39 ]
br i1 %48, label %49, label %60
49: ; preds = %47
%50 = load i32, i32* %4
%51 = sub nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = load i32, i32* %4
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %56
store i32 %54, i32* %57
%58 = load i32, i32* %4
%59 = add nsw i32 %58, -1
store i32 %59, i32* %4
br label %36
60: ; preds = %47
%61 = load i32, i32* %5
%62 = load i32, i32* %4
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %63
store i32 %61, i32* %64
br label %65
65: ; preds = %60
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
store i32 %67, i32* %7
br label %25
68: ; preds = %25
br label %69
69: ; preds = %68, %15
store i32 0, i32* %8
br label %70
70: ; preds = %80, %69
%71 = load i32, i32* %8
%72 = load i32, i32* %6
%73 = icmp sle i32 %71, %72
br i1 %73, label %74, label %83
74: ; preds = %70
%75 = load i32, i32* %8
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %76
%78 = load i32, i32* %77
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %78)
br label %80
80: ; preds = %74
%81 = load i32, i32* %8
%82 = add nsw i32 %81, 1
store i32 %82, i32* %8
br label %70
83: ; preds = %70
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %85
85: ; preds = %83
%86 = load i32, i32* %6
%87 = add nsw i32 %86, 1
store i32 %87, i32* %6
br label %11
88: ; preds = %11
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [8 x i8] c"a[%d]= \00"
@.str.3 = [4 x i8] c"%d \00"
@str = [26 x i8] c"Dati un element natural n\00"
@str.6 = [8 x i8] c"Exit...\00"
define i32 @main() {
%1 = alloca [50 x i32]
%2 = alloca i32
%3 = bitcast [50 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 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 = icmp sgt i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %47, %0
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.6, i64 0, i64 0))
ret i32 0
11: ; preds = %0, %47
%12 = phi i64 [ %49, %47 ], [ 0, %0 ]
%13 = phi i64 [ %53, %47 ], [ 1, %0 ]
%14 = trunc i64 %12 to i32
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 %12
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %16)
%18 = icmp ugt i64 %12, 1
br i1 %18, label %20, label %19
19: ; preds = %40, %20, %11
br label %54
20: ; preds = %11
%21 = load i32, i32* %2
%22 = icmp sgt i32 %21, 2
br i1 %22, label %23, label %19
23: ; preds = %20
%24 = add nsw i32 %21, -1
%25 = zext i32 %24 to i64
br label %26
26: ; preds = %23, %40
%27 = phi i64 [ 1, %23 ], [ %45, %40 ]
%28 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 %27
%29 = load i32, i32* %28
br label %30
30: ; preds = %26, %37
%31 = phi i64 [ %27, %26 ], [ %32, %37 ]
%32 = add nsw i64 %31, -1
%33 = and i64 %32, 4294967295
%34 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = icmp sgt i32 %35, %29
br i1 %36, label %37, label %40
37: ; preds = %30
%38 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 %31
store i32 %35, i32* %38
%39 = icmp sgt i64 %31, 1
br i1 %39, label %30, label %40
40: ; preds = %37, %30
%41 = phi i64 [ 0, %37 ], [ %31, %30 ]
%42 = shl i64 %41, 32
%43 = ashr exact i64 %42, 32
%44 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 %43
store i32 %29, i32* %44
%45 = add nuw nsw i64 %27, 1
%46 = icmp eq i64 %45, %25
br i1 %46, label %19, label %26
47: ; preds = %54
%48 = call i32 @putchar(i32 10)
%49 = add nuw nsw i64 %12, 1
%50 = load i32, i32* %2
%51 = sext i32 %50 to i64
%52 = icmp slt i64 %49, %51
%53 = add nuw nsw i64 %13, 1
br i1 %52, label %11, label %9
54: ; preds = %19, %54
%55 = phi i64 [ %59, %54 ], [ 0, %19 ]
%56 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 %55
%57 = load i32, i32* %56
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %57)
%59 = add nuw nsw i64 %55, 1
%60 = icmp eq i64 %59, %13
br i1 %60, label %47, label %54
}