#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*/ free(char **);
int identifyEpisode(char *, int);
char **malloc(int);
char **sortEpisodes(char **episodes, int epCount, int firstEp, int digit) {
  char **temp;
  int i, num;
  temp = malloc(sizeof(char *) * epCount);
  for (i = 0; i < epCount; i++) {
    num = identifyEpisode(episodes[i], digit);
    temp[num - firstEp] = episodes[i];
  }
  free(episodes);
  return temp;
}


x86 assembly (clang, -O0):
<sortEpisodes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ad <sortEpisodes+0x7d>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x14(%rbp),%esi
call   1050 <identifyEpisode@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%ecx
sub    -0x10(%rbp),%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115f <sortEpisodes+0x2f>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sortEpisodes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%rbx
lea    0x0(,%r12,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r13
test   %r12d,%r12d
jle    1193 <sortEpisodes+0x63>
mov    %r12d,%r12d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rbx,%rbp,8),%rdi
mov    %r14d,%esi
call   1050 <identifyEpisode@plt>
mov    (%rbx,%rbp,8),%rcx
sub    %r15d,%eax
cltq
mov    %rcx,0x0(%r13,%rax,8)
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1170 <sortEpisodes+0x40>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8** @sortEpisodes(i8** %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8**
%10 = alloca i32
%11 = alloca i32
store i8** %0, i8*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i32, i32* %6
%13 = sext i32 %12 to i64
%14 = mul i64 8, %13
%15 = trunc i64 %14 to i32
%16 = call i8** @malloc(i32 %15)
store i8** %16, i8*** %9
store i32 0, i32* %10
br label %17
17: ; preds = %40, %4
%18 = load i32, i32* %10
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %43
21: ; preds = %17
%22 = load i8**, i8*** %5
%23 = load i32, i32* %10
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = load i32, i32* %8
%28 = call i32 @identifyEpisode(i8* %26, i32 %27)
store i32 %28, i32* %11
%29 = load i8**, i8*** %5
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = load i8**, i8*** %9
%35 = load i32, i32* %11
%36 = load i32, i32* %7
%37 = sub nsw i32 %35, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %34, i64 %38
store i8* %33, i8** %39
br label %40
40: ; preds = %21
%41 = load i32, i32* %10
%42 = add nsw i32 %41, 1
store i32 %42, i32* %10
br label %17
43: ; preds = %17
%44 = load i8**, i8*** %5
%45 = call i32 @free(i8** %44)
%46 = load i8**, i8*** %9
ret i8** %46
}

LLVM IR (-O2):
define noalias i8** @sortEpisodes(i8** nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = shl i32 %1, 3
%6 = tail call i8** @malloc(i32 %5)
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %21
8: ; preds = %4
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %19, %10 ]
%12 = getelementptr inbounds i8*, i8** %0, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i32 @identifyEpisode(i8* %13, i32 %3)
%15 = load i8*, i8** %12
%16 = sub nsw i32 %14, %2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %6, i64 %17
store i8* %15, i8** %18
%19 = add nuw nsw i64 %11, 1
%20 = icmp eq i64 %19, %9
br i1 %20, label %21, label %10
21: ; preds = %10, %4
%22 = tail call i32 @free(i8** %0)
ret i8** %6
}