#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 */
typedef int /*<<< orphan*/ array;

/* Variables and functions */
int insertSorted(int *, int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int array[20] = {12, 16, 20, 40, 50, 70};
  int capacity = sizeof(array) / sizeof(array[0]);
  int n = 6;
  int i, key = 26;
  printf("\nBefore Insertion: ");
  for (i = 0; i < n; ++i)
    printf("%d ", array[i]);
  n = insertSorted(array, n, key, capacity);
  printf("\nAfter Insertion: ");
  for (i = 0; i < n; ++i)
    printf("%d ", array[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1040 <memset@plt>
movl   $0xc,-0x60(%rbp)
movl   $0x10,-0x5c(%rbp)
movl   $0x14,-0x58(%rbp)
movl   $0x28,-0x54(%rbp)
movl   $0x32,-0x50(%rbp)
movl   $0x46,-0x4c(%rbp)
movl   $0x14,-0x64(%rbp)
movl   $0x6,-0x68(%rbp)
movl   $0x1a,-0x70(%rbp)
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
cmp    -0x68(%rbp),%eax
jge    11d3 <main+0xa3>
movslq -0x6c(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    11a3 <main+0x73>
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%esi
mov    -0x70(%rbp),%edx
mov    -0x64(%rbp),%ecx
call   1050 <insertSorted@plt>
mov    %eax,-0x68(%rbp)
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
cmp    -0x68(%rbp),%eax
jge    122d <main+0xfd>
movslq -0x6c(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    11fd <main+0xcd>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps 0xeb9(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x4600000032,%rax
mov    %rax,0x10(%rsp)
lea    0xeaf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb5(%rip),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x14,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x28,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x32,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x46,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,%rdi
mov    $0x6,%esi
mov    $0x1a,%edx
mov    $0x14,%ecx
call   1040 <insertSorted@plt>
mov    %eax,%ebx
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
test   %ebx,%ebx
jle    1216 <main+0xf6>
mov    %ebx,%r15d
lea    0xe26(%rip),%r14
xor    %ebx,%ebx
mov    (%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1200 <main+0xe0>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [20 x i8] c"\0ABefore Insertion: \00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [19 x i8] c"\0AAfter Insertion: \00"
define i32 @main() {
%1 = alloca [20 x i32]
%2 = bitcast [20 x i32]* %1 to i8*
%3 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 4
%4 = bitcast i32* %3 to i8*
%5 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%6 = bitcast [20 x i32]* %1 to <4 x i32>*
store <4 x i32> <i32 12, i32 16, i32 20, i32 40>, <4 x i32>* %6
%7 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 4
store i32 50, i32* %7
%8 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 5
store i32 70, i32* %8
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 12)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 16)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 20)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 40)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 50)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 70)
%16 = call i32 @insertSorted(i32* %5, i32 6, i32 26, i32 20)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp sgt i32 %16, 0
br i1 %18, label %19, label %28
19: ; preds = %0
%20 = zext i32 %16 to i64
br label %21
21: ; preds = %19, %21
%22 = phi i64 [ 0, %19 ], [ %26, %21 ]
%23 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = add nuw nsw i64 %22, 1
%27 = icmp eq i64 %26, %20
br i1 %27, label %28, label %21
28: ; preds = %21, %0
ret i32 0
}