#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 EXIT_FAILURE;
int contarArquivos(char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int intercalar(char const *, int);
char *malloc(int);
int /*<<< orphan*/ stderr;
int strlen(char const *);
int ordenar(const char *nomeBase) {
  int quantidadeArquivos = 0;
  char *nomeArquivo = malloc(strlen(nomeBase + 10) * sizeof(char));
  if (nomeArquivo == NULL) {
    fprintf(stderr,
            "Problema com alocacao dinamica! Possivel falta de memoria\n");
    return EXIT_FAILURE;
  }
  quantidadeArquivos = contarArquivos(nomeBase);
  if (quantidadeArquivos == 0) {
    fprintf(
        stderr,
        "Nao existe outros arquivos a patir do arquivo base especificado!\n");
    return EXIT_FAILURE;
  }
  return intercalar(nomeBase, quantidadeArquivos);
}


x86 assembly (clang, -O0):
<ordenar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
add    $0xa,%rdi
call   1040 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b2 <ordenar+0x62>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11fd <ordenar+0xad>
mov    -0x10(%rbp),%rdi
call   1050 <contarArquivos@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11ee <ordenar+0x9e>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11fd <ordenar+0xad>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <intercalar@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ordenar>:
push   %rbx
mov    %rdi,%rbx
add    $0xa,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
call   1050 <contarArquivos@plt>
test   %eax,%eax
je     1164 <ordenar+0x24>
mov    %rbx,%rdi
mov    %eax,%esi
pop    %rbx
jmp    1030 <intercalar@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
lea    0xe8c(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [59 x i8] c"Problema com alocacao dinamica! Possivel falta de memoria\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [66 x i8] c"Nao existe outros arquivos a patir do arquivo base especificado!\0A\00"
define i32 @ordenar(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 0, i32* %4
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 10
%8 = call i32 @strlen(i8* %7)
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 1
%11 = trunc i64 %10 to i32
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
store i32 %18, i32* %2
br label %32
19: ; preds = %1
%20 = load i8*, i8** %3
%21 = call i32 @contarArquivos(i8* %20)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
store i32 %27, i32* %2
br label %32
28: ; preds = %19
%29 = load i8*, i8** %3
%30 = load i32, i32* %4
%31 = call i32 @intercalar(i8* %29, i32 %30)
store i32 %31, i32* %2
br label %32
32: ; preds = %28, %24, %15
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [66 x i8] c"Nao existe outros arquivos a patir do arquivo base especificado!\0A\00"
define i32 @ordenar(i8* %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 10
%3 = tail call i32 @strlen(i8* %2)
%4 = tail call i32 @contarArquivos(i8* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
br label %12
10: ; preds = %1
%11 = tail call i32 @intercalar(i8* %0, i32 %4)
br label %12
12: ; preds = %10, %6
%13 = phi i32 [ %9, %6 ], [ %11, %10 ]
ret i32 %13
}