#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*/ Merge_Sort(char *, int, int);
int criaArquivosOrdenados(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
void Merge_Sort_Externo(char *nome) {
  char novo[20];
  int K = criaArquivosOrdenados(nome);
  int i, T = 1310720 / (K + 1);
  printf("Nro de arquivos:%d\n", K);
  printf("K:%d\n", T);
  remove(nome);
  Merge_Sort(nome, K, T);
  for (i = 0; i < K; i++) {
    sprintf(novo, "Temp%d.txt", i + 1);
    remove(novo);
  }
  printf("Fim!\n");
}


x86 assembly (clang, -O0):
<Merge_Sort_Externo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <criaArquivosOrdenados@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    $0x140000,%eax
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <remove@plt>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1060 <Merge_Sort@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11f3 <Merge_Sort_Externo+0xa3>
lea    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%edx
add    $0x1,%edx
lea    0xe43(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x20(%rbp),%rdi
call   1030 <remove@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11ba <Merge_Sort_Externo+0x6a>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Merge_Sort_Externo>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
call   1060 <criaArquivosOrdenados@plt>
mov    %eax,%r15d
lea    0x1(%r15),%ecx
mov    $0x140000,%eax
xor    %edx,%edx
idiv   %ecx
mov    %eax,%ebx
lea    0xe74(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe77(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <remove@plt>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
call   1070 <Merge_Sort@plt>
test   %r15d,%r15d
jle    1208 <Merge_Sort_Externo+0xa8>
neg    %r15d
mov    $0x1,%ebx
lea    0xe4b(%rip),%r14
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1080 <sprintf@plt>
mov    %r12,%rdi
call   1030 <remove@plt>
lea    (%r15,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    11e0 <Merge_Sort_Externo+0x80>
lea    0xe16(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"Nro de arquivos:%d\0A\00"
@.str.1 = [6 x i8] c"K:%d\0A\00"
@.str.2 = [11 x i8] c"Temp%d.txt\00"
@.str.3 = [6 x i8] c"Fim!\0A\00"
define void @Merge_Sort_Externo(i8* %0) {
%2 = alloca i8*
%3 = alloca [20 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @criaArquivosOrdenados(i8* %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = add nsw i32 %9, 1
%11 = sdiv i32 1310720, %10
store i32 %11, i32* %6
%12 = load i32, i32* %4
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %6
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i8*, i8** %2
%17 = call i32 @remove(i8* %16)
%18 = load i8*, i8** %2
%19 = load i32, i32* %4
%20 = load i32, i32* %6
%21 = call i32 @Merge_Sort(i8* %18, i32 %19, i32 %20)
store i32 0, i32* %5
br label %22
22: ; preds = %33, %1
%23 = load i32, i32* %5
%24 = load i32, i32* %4
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %36
26: ; preds = %22
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
%30 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%32 = call i32 @remove(i8* %31)
br label %33
33: ; preds = %26
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %22
36: ; preds = %22
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"Nro de arquivos:%d\0A\00"
@.str.1 = [6 x i8] c"K:%d\0A\00"
@.str.2 = [11 x i8] c"Temp%d.txt\00"
@str = [5 x i8] c"Fim!\00"
define void @Merge_Sort_Externo(i8* %0) {
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @criaArquivosOrdenados(i8* %0)
%5 = add nsw i32 %4, 1
%6 = sdiv i32 1310720, %5
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %4)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%9 = tail call i32 @remove(i8* %0)
%10 = tail call i32 @Merge_Sort(i8* %0, i32 %4, i32 %6)
%11 = icmp sgt i32 %4, 0
br i1 %11, label %12, label %18
12: ; preds = %1, %12
%13 = phi i32 [ %14, %12 ], [ 0, %1 ]
%14 = add nuw nsw i32 %13, 1
%15 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = call i32 @remove(i8* %3)
%17 = icmp eq i32 %14, %4
br i1 %17, label %18, label %12
18: ; preds = %12, %1
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
ret void
}