#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__ atoi(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
void insertionSort(char **elements, int count) {
  for (int i = 1; i < count; i++) {
    char *elm = (char *)malloc(sizeof(char) * (100 + 1));
    strcpy(elm, elements[i]);
    int j = i;
    while (j > 0) {
      if (atoi(elements[j - 1]) > atoi(elm)) {
        strcpy(elements[j], elements[j - 1]);
        j--;
      } else {
        break;
      }
    }
    strcpy(elements[j], elm);
    free(elm);
  }
}


x86 assembly (clang, -O0):
<insertionSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    122e <insertionSort+0xee>
mov    $0x65,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1202 <insertionSort+0xc2>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <atoi@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <atoi@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jle    11f8 <insertionSort+0xb8>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11fd <insertionSort+0xbd>
jmp    1202 <insertionSort+0xc2>
jmp    118b <insertionSort+0x4b>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1156 <insertionSort+0x16>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insertionSort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%esi
jl     1203 <insertionSort+0xc3>
mov    %rdi,%r15
mov    %esi,%eax
mov    %rax,0x8(%rsp)
mov    $0x1,%r13d
jmp    1197 <insertionSort+0x57>
nopl   0x0(%rax)
movslq %r13d,%rax
mov    (%r15,%rax,8),%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%r13
add    $0x1,%r13
cmp    0x8(%rsp),%r13
je     1203 <insertionSort+0xc3>
mov    $0x65,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    (%r15,%r13,8),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %r13,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
lea    -0x1(%r13),%rbp
mov    %ebp,%eax
mov    (%r15,%rax,8),%rbx
mov    %rbx,%rdi
call   1060 <atoi@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1060 <atoi@plt>
cmp    %rax,%r12
jle    1170 <insertionSort+0x30>
mov    (%r15,%r13,8),%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0x1(%rbp),%rax
mov    %rbp,%r13
cmp    $0x1,%rax
jg     11c0 <insertionSort+0x80>
xor    %r13d,%r13d
jmp    1170 <insertionSort+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @insertionSort(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8** %0, i8*** %3
store i32 %1, i32* %4
store i32 1, i32* %5
br label %8
8: ; preds = %64, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %67
12: ; preds = %8
%13 = call i64 @malloc(i32 101)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = load i8**, i8*** %3
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = call i32 @strcpy(i8* %15, i8* %20)
%22 = load i32, i32* %5
store i32 %22, i32* %7
br label %23
23: ; preds = %53, %12
%24 = load i32, i32* %7
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %54
26: ; preds = %23
%27 = load i8**, i8*** %3
%28 = load i32, i32* %7
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %27, i64 %30
%32 = load i8*, i8** %31
%33 = call i64 @atoi(i8* %32)
%34 = load i8*, i8** %6
%35 = call i64 @atoi(i8* %34)
%36 = icmp sgt i64 %33, %35
br i1 %36, label %37, label %52
37: ; preds = %26
%38 = load i8**, i8*** %3
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = load i8**, i8*** %3
%44 = load i32, i32* %7
%45 = sub nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %43, i64 %46
%48 = load i8*, i8** %47
%49 = call i32 @strcpy(i8* %42, i8* %48)
%50 = load i32, i32* %7
%51 = add nsw i32 %50, -1
store i32 %51, i32* %7
br label %53
52: ; preds = %26
br label %54
53: ; preds = %37
br label %23
54: ; preds = %52, %23
%55 = load i8**, i8*** %3
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
%59 = load i8*, i8** %58
%60 = load i8*, i8** %6
%61 = call i32 @strcpy(i8* %59, i8* %60)
%62 = load i8*, i8** %6
%63 = call i32 @free(i8* %62)
br label %64
64: ; preds = %54
%65 = load i32, i32* %5
%66 = add nsw i32 %65, 1
store i32 %66, i32* %5
br label %8
67: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @insertionSort(i8** nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %7
6: ; preds = %28, %2
ret void
7: ; preds = %4, %28
%8 = phi i64 [ 1, %4 ], [ %36, %28 ]
%9 = tail call i64 @malloc(i32 101)
%10 = inttoptr i64 %9 to i8*
%11 = getelementptr inbounds i8*, i8** %0, i64 %8
%12 = load i8*, i8** %11
%13 = tail call i32 @strcpy(i8* %10, i8* %12)
br label %14
14: ; preds = %7, %23
%15 = phi i64 [ %8, %7 ], [ %16, %23 ]
%16 = add nsw i64 %15, -1
%17 = and i64 %16, 4294967295
%18 = getelementptr inbounds i8*, i8** %0, i64 %17
%19 = load i8*, i8** %18
%20 = tail call i64 @atoi(i8* %19)
%21 = tail call i64 @atoi(i8* %10)
%22 = icmp sgt i64 %20, %21
br i1 %22, label %23, label %28
23: ; preds = %14
%24 = getelementptr inbounds i8*, i8** %0, i64 %15
%25 = load i8*, i8** %24
%26 = tail call i32 @strcpy(i8* %25, i8* %19)
%27 = icmp sgt i64 %15, 1
br i1 %27, label %14, label %28
28: ; preds = %14, %23
%29 = phi i64 [ %15, %14 ], [ 0, %23 ]
%30 = shl i64 %29, 32
%31 = ashr exact i64 %30, 32
%32 = getelementptr inbounds i8*, i8** %0, i64 %31
%33 = load i8*, i8** %32
%34 = tail call i32 @strcpy(i8* %33, i8* %10)
%35 = tail call i32 @free(i8* %10)
%36 = add nuw nsw i64 %8, 1
%37 = icmp eq i64 %36, %5
br i1 %37, label %6, label %7
}