#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int N, cnt = 1, temp, tcnt = 1, i, j, tmp;
  int *toys;
  printf("Enter No. of Toys");
  scanf("%d", &N);
  toys = (int *)malloc(N * sizeof(int));
  for (i = 0; i < N; i++) {
    scanf("%d", &temp);
    j = i;
    while (i > 0) {
      if (temp < toys[i - 1]) {
        i--;
        printf("%d", i);
      }
    }
    tmp = toys[i];
    toys[i] = temp;
    toys[j] = tmp;
    printf("Hi");
    i = j;
  }
  for (i = 0; i < N; i++)
    printf("\n%d", toys[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x14(%rbp)
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb4(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1235 <main+0x105>
lea    0xe7e(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    11e9 <main+0xb9>
mov    -0x10(%rbp),%eax
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jge    11e4 <main+0xb4>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a7 <main+0x77>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1185 <main+0x55>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    126f <main+0x13f>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    123c <main+0x10c>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec6(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
mov    (%rsp),%edi
shl    $0x2,%edi
call   1040 <malloc@plt>
cmpl   $0x0,(%rsp)
jle    122c <main+0xfc>
mov    %rax,%r13
lea    0xe9f(%rip),%r14
lea    0x4(%rsp),%r15
lea    0xe8f(%rip),%r12
xor    %ebp,%ebp
jmp    11bc <main+0x8c>
nopw   0x0(%rax,%rax,1)
cltq
mov    0x0(%r13,%rax,4),%ecx
mov    0x4(%rsp),%edx
mov    %edx,0x0(%r13,%rax,4)
mov    %ecx,0x0(%r13,%rbp,4)
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbp
movslq (%rsp),%rax
cmp    %rax,%rbp
jge    1202 <main+0xd2>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
mov    $0x0,%eax
test   %rbp,%rbp
je     1190 <main+0x60>
mov    %ebp,%eax
jmp    11e4 <main+0xb4>
cs nopw 0x0(%rax,%rax,1)
nop
test   %eax,%eax
jle    1190 <main+0x60>
mov    0x4(%rsp),%ecx
lea    -0x1(%rax),%ebx
cmp    0x0(%r13,%rbx,4),%ecx
jge    11e0 <main+0xb0>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%eax
jmp    11e0 <main+0xb0>
test   %eax,%eax
jle    122c <main+0xfc>
lea    0xe08(%rip),%r14
xor    %ebx,%ebx
nop
mov    0x0(%r13,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
movslq (%rsp),%rax
cmp    %rax,%rbx
jl     1210 <main+0xe0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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