#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*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ leuTodosOsArquivosPorCompleto(int /*<<< orphan*/ **, int);
char *malloc(int);
int pegaMenor(int **, int, int *, int *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, int);
int /*<<< orphan*/ stderr;
int strlen(char const *);
int intercalar(const char *nomeBase, int quantidadeArquivos) {
  FILE *arquivosEntrada[10];
  FILE *arquivoSaida;
  int buffer[10][5];
  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;
  }
  for (int i = 0; i < quantidadeArquivos; i++) {
    sprintf(nomeArquivo, "%s%d", nomeBase, i);
    arquivosEntrada[i] = fopen(nomeArquivo, "rb");
    if (arquivosEntrada[i] == NULL) {
      fprintf(stderr, "Problema na abertura do arquivo %s\n", nomeArquivo);
      for (int j = 0; j < i; j++) {
        fclose(arquivosEntrada[j]);
      }
      free(nomeArquivo);
      return EXIT_FAILURE;
    }
  }
  arquivoSaida = fopen(nomeBase, "wb");
  if (arquivoSaida == NULL) {
    fprintf(stderr, "Problema na abertura do arquivo %s\n", nomeBase);
    for (int i = 0; i < quantidadeArquivos; i++) {
      fclose(arquivosEntrada[i]);
    }
    free(nomeArquivo);
    return EXIT_FAILURE;
  }
  while (!leuTodosOsArquivosPorCompleto(arquivosEntrada, quantidadeArquivos)) {
    int lidoAtual[10] = {0};
    for (int i = 0; i < quantidadeArquivos; i++) {
      lidoAtual[i] = fread(buffer[i], sizeof(int), 5, arquivosEntrada[i]);
    }
    int indices[10] = {0};
    int min = pegaMenor(buffer, quantidadeArquivos, indices, lidoAtual);
    while (min != -1) {
      fwrite(&buffer[min][indices[min]], sizeof(int), 1, arquivoSaida);
      indices[min]++;
      if (indices[min] == lidoAtual[min]) {
        lidoAtual[min] =
            fread(buffer[min], sizeof(int), 5, arquivosEntrada[min]);
        indices[min] = 0;
      }
      min = pegaMenor(buffer, quantidadeArquivos, indices, lidoAtual);
    }
  }
  for (int i = 0; i < quantidadeArquivos; i++) {
    fclose(arquivosEntrada[i]);
  }
  fclose(arquivoSaida);
  free(nomeArquivo);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<intercalar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
add    $0xa,%rdi
call   1060 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x148(%rbp)
cmpq   $0x0,-0x148(%rbp)
jne    1229 <intercalar+0x69>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    15fd <intercalar+0x43d>
movl   $0x0,-0x14c(%rbp)
mov    -0x14c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1329 <intercalar+0x169>
mov    -0x148(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14c(%rbp),%ecx
lea    0xde1(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x148(%rbp),%rdi
lea    0xdd3(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rcx
movslq -0x14c(%rbp),%rax
mov    %rcx,-0x70(%rbp,%rax,8)
movslq -0x14c(%rbp),%rax
cmpq   $0x0,-0x70(%rbp,%rax,8)
jne    1310 <intercalar+0x150>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
mov    -0x148(%rbp),%rdx
lea    0xd98(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x150(%rbp)
mov    -0x150(%rbp),%eax
cmp    -0x14c(%rbp),%eax
jge    12f3 <intercalar+0x133>
movslq -0x150(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rdi
call   1050 <fclose@plt>
mov    -0x150(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x150(%rbp)
jmp    12bc <intercalar+0xfc>
mov    -0x148(%rbp),%rdi
call   1030 <free@plt>
mov    0x2cd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    15fd <intercalar+0x43d>
jmp    1315 <intercalar+0x155>
mov    -0x14c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14c(%rbp)
jmp    1233 <intercalar+0x73>
mov    -0x10(%rbp),%rdi
lea    0xd33(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    13be <intercalar+0x1fe>
mov    0x2c91(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xce7(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x154(%rbp)
mov    -0x154(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    13a1 <intercalar+0x1e1>
movslq -0x154(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rdi
call   1050 <fclose@plt>
mov    -0x154(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x154(%rbp)
jmp    136d <intercalar+0x1ad>
mov    -0x148(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    15fd <intercalar+0x43d>
jmp    13c3 <intercalar+0x203>
lea    -0x70(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10a0 <leuTodosOsArquivosPorCompleto@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    13e4 <intercalar+0x224>
jmp    159e <intercalar+0x3de>
lea    -0x180(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
movl   $0x0,-0x184(%rbp)
mov    -0x184(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1464 <intercalar+0x2a4>
movslq -0x184(%rbp),%rax
lea    -0x140(%rbp),%rdi
imul   $0x14,%rax,%rax
add    %rax,%rdi
movslq -0x184(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rcx
mov    $0x4,%esi
mov    $0x5,%edx
call   1040 <fread@plt>
mov    %eax,%ecx
movslq -0x184(%rbp),%rax
mov    %ecx,-0x180(%rbp,%rax,4)
mov    -0x184(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x184(%rbp)
jmp    1401 <intercalar+0x241>
lea    -0x1b0(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
lea    -0x140(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x1b0(%rbp),%rdx
lea    -0x180(%rbp),%rcx
call   10e0 <pegaMenor@plt>
mov    %eax,-0x1b4(%rbp)
cmpl   $0xffffffff,-0x1b4(%rbp)
je     1599 <intercalar+0x3d9>
movslq -0x1b4(%rbp),%rax
lea    -0x140(%rbp),%rdi
imul   $0x14,%rax,%rax
add    %rax,%rdi
movslq -0x1b4(%rbp),%rax
movslq -0x1b0(%rbp,%rax,4),%rax
ff
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x78(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   10d0 <fwrite@plt>
movslq -0x1b4(%rbp),%rax
mov    -0x1b0(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x1b0(%rbp,%rax,4)
movslq -0x1b4(%rbp),%rax
mov    -0x1b0(%rbp,%rax,4),%eax
movslq -0x1b4(%rbp),%rcx
cmp    -0x180(%rbp,%rcx,4),%eax
jne    1571 <intercalar+0x3b1>
movslq -0x1b4(%rbp),%rax
lea    -0x140(%rbp),%rdi
imul   $0x14,%rax,%rax
add    %rax,%rdi
movslq -0x1b4(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rcx
mov    $0x4,%esi
mov    $0x5,%edx
call   1040 <fread@plt>
mov    %eax,%ecx
movslq -0x1b4(%rbp),%rax
mov    %ecx,-0x180(%rbp,%rax,4)
movslq -0x1b4(%rbp),%rax
movl   $0x0,-0x1b0(%rbp,%rax,4)
lea    -0x140(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x1b0(%rbp),%rdx
lea    -0x180(%rbp),%rcx
call   10e0 <pegaMenor@plt>
mov    %eax,-0x1b4(%rbp)
jmp    149a <intercalar+0x2da>
jmp    13c3 <intercalar+0x203>
movl   $0x0,-0x1b8(%rbp)
mov    -0x1b8(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    15dc <intercalar+0x41c>
movslq -0x1b8(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rdi
call   1050 <fclose@plt>
mov    -0x1b8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b8(%rbp)
jmp    15a8 <intercalar+0x3e8>
mov    -0x78(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x148(%rbp),%rdi
call   1030 <free@plt>
mov    0x29d8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intercalar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x198,%rsp
mov    %esi,%ebx
mov    %rdi,%r12
add    $0xa,%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1282 <intercalar+0xd2>
mov    %rax,%r15
mov    %ebx,%ebp
mov    %ebx,0xc(%rsp)
test   %ebx,%ebx
mov    %rbp,0x18(%rsp)
jle    12fc <intercalar+0x14c>
lea    0xe3f(%rip),%rsi
xor    %ebx,%ebx
mov    %r15,%rdi
mov    %r12,%rdx
xor    %ecx,%ecx
call   10b0 <sprintf@plt>
lea    0xe2e(%rip),%rsi
mov    %r15,%rdi
call   10a0 <fopen@plt>
mov    %rax,0x80(%rsp)
test   %rax,%rax
je     129e <intercalar+0xee>
mov    $0x1,%ebx
lea    0xe08(%rip),%r13
lea    0xe06(%rip),%r14
nopw   0x0(%rax,%rax,1)
cmp    %rbx,%rbp
je     12fc <intercalar+0x14c>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %ebx,%ecx
call   10b0 <sprintf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <fopen@plt>
mov    %rax,0x80(%rsp,%rbx,8)
add    $0x1,%rbx
test   %rax,%rax
jne    1240 <intercalar+0x90>
add    $0xffffffffffffffff,%rbx
cmp    %rbp,%rbx
setb   %r14b
jmp    12a1 <intercalar+0xf1>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
lea    0xd6e(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    13c0 <intercalar+0x210>
mov    $0x1,%r14b
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
lea    0xd92(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
test   %ebx,%ebx
je     12e6 <intercalar+0x136>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x80(%rsp,%rbp,8),%rdi
call   1050 <fclose@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    12d0 <intercalar+0x120>
mov    %r15,%rdi
call   1030 <free@plt>
test   %r14b,%r14b
mov    0x18(%rsp),%rbp
jne    13c0 <intercalar+0x210>
mov    %r15,0x10(%rsp)
lea    0xd5f(%rip),%rsi
mov    %r12,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1371 <intercalar+0x1c1>
mov    %rax,%r15
lea    0x80(%rsp),%rdi
mov    0xc(%rsp),%r13d
mov    %r13d,%esi
call   1090 <leuTodosOsArquivosPorCompleto@plt>
test   %eax,%eax
je     13db <intercalar+0x22b>
test   %r13d,%r13d
jle    1356 <intercalar+0x1a6>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x80(%rsp,%rbx,8),%rdi
call   1050 <fclose@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1340 <intercalar+0x190>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x2c61(%rip),%rax
jmp    13c7 <intercalar+0x217>
mov    0x2c68(%rip),%rax
mov    (%rax),%edi
lea    0xcc2(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
cmpl   $0x0,0xc(%rsp)
jle    13b6 <intercalar+0x206>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x80(%rsp,%rbx,8),%rdi
call   1050 <fclose@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    13a0 <intercalar+0x1f0>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x2c11(%rip),%rax
mov    (%rax),%eax
add    $0x198,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd0(%rsp),%r14
lea    0x50(%rsp),%r12
jmp    140d <intercalar+0x25d>
nopw   0x0(%rax,%rax,1)
lea    0x80(%rsp),%rdi
mov    %r13d,%esi
call   1090 <leuTodosOsArquivosPorCompleto@plt>
test   %eax,%eax
mov    0x18(%rsp),%rbp
jne    1335 <intercalar+0x185>
xorps  %xmm0,%xmm0
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movq   $0x0,0x70(%rsp)
test   %r13d,%r13d
jle    145b <intercalar+0x2ab>
mov    %r14,%r13
xor    %ebx,%ebx
nopl   (%rax)
mov    0x80(%rsp,%rbx,8),%rcx
mov    %r13,%rdi
mov    $0x4,%esi
mov    $0x5,%edx
call   1040 <fread@plt>
mov    %eax,0x50(%rsp,%rbx,4)
add    $0x1,%rbx
add    $0x14,%r13
cmp    %rbx,%rbp
jne    1430 <intercalar+0x280>
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movq   $0x0,0x40(%rsp)
mov    %r14,%rdi
mov    0xc(%rsp),%r13d
jmp    1483 <intercalar+0x2d3>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r13d,%esi
lea    0x20(%rsp),%rdx
mov    %r12,%rcx
call   10d0 <pegaMenor@plt>
cmp    $0xffffffff,%eax
je     13f0 <intercalar+0x240>
movslq %eax,%rbx
movslq 0x20(%rsp,%rbx,4),%rax
lea    (%rbx,%rbx,4),%rcx
lea    (%rsp,%rcx,4),%rbp
add    $0xd0,%rbp
lea    0x0(%rbp,%rax,4),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   10c0 <fwrite@plt>
mov    0x20(%rsp,%rbx,4),%eax
add    $0x1,%eax
mov    %eax,0x20(%rsp,%rbx,4)
cmp    0x50(%rsp,%rbx,4),%eax
jne    1480 <intercalar+0x2d0>
mov    0x80(%rsp,%rbx,8),%rcx
mov    %rbp,%rdi
mov    $0x4,%esi
mov    $0x5,%edx
call   1040 <fread@plt>
mov    %eax,0x50(%rsp,%rbx,4)
movl   $0x0,0x20(%rsp,%rbx,4)
jmp    1480 <intercalar+0x2d0>

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 = [5 x i8] c"%s%d\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [36 x i8] c"Problema na abertura do arquivo %s\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@EXIT_SUCCESS = global i32 0
define i32 @intercalar(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [10 x i32*]
%7 = alloca i32*
%8 = alloca [10 x [5 x i32]]
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [10 x i32]
%14 = alloca i32
%15 = alloca [10 x i32]
%16 = alloca i32
%17 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 10
%20 = call i32 @strlen(i8* %19)
%21 = sext i32 %20 to i64
%22 = mul i64 %21, 1
%23 = trunc i64 %22 to i32
%24 = call i8* @malloc(i32 %23)
store i8* %24, i8** %9
%25 = load i8*, i8** %9
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %31
27: ; preds = %2
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
store i32 %30, i32* %3
br label %212
31: ; preds = %2
store i32 0, i32* %10
br label %32
32: ; preds = %73, %31
%33 = load i32, i32* %10
%34 = load i32, i32* %5
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %76
36: ; preds = %32
%37 = load i8*, i8** %9
%38 = load i8*, i8** %4
%39 = load i32, i32* %10
%40 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %38, i32 %39)
%41 = load i8*, i8** %9
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* %10
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [10 x i32*], [10 x i32*]* %6, i64 0, i64 %44
store i32* %42, i32** %45
%46 = load i32, i32* %10
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [10 x i32*], [10 x i32*]* %6, i64 0, i64 %47
%49 = load i32*, i32** %48
%50 = icmp eq i32* %49, null
br i1 %50, label %51, label %72
51: ; preds = %36
%52 = load i32, i32* @stderr
%53 = load i8*, i8** %9
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %53)
store i32 0, i32* %11
br label %55
55: ; preds = %65, %51
%56 = load i32, i32* %11
%57 = load i32, i32* %10
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %68
59: ; preds = %55
%60 = load i32, i32* %11
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [10 x i32*], [10 x i32*]* %6, i64 0, i64 %61
%63 = load i32*, i32** %62
%64 = call i32 @fclose(i32* %63)
br label %65
65: ; preds = %59
%66 = load i32, i32* %11
%67 = add nsw i32 %66, 1
store i32 %67, i32* %11
br label %55
68: ; preds = %55
%69 = load i8*, i8** %9
%70 = call i32 @free(i8* %69)
%71 = load i32, i32* @EXIT_FAILURE
store i32 %71, i32* %3
br label %212
72: ; preds = %36
br label %73
73: ; preds = %72
%74 = load i32, i32* %10
%75 = add nsw i32 %74, 1
store i32 %75, i32* %10
br label %32
76: ; preds = %32
%77 = load i8*, i8** %4
%78 = call i32* @fopen(i8* %77, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %78, i32** %7
%79 = load i32*, i32** %7
%80 = icmp eq i32* %79, null
br i1 %80, label %81, label %102
81: ; preds = %76
%82 = load i32, i32* @stderr
%83 = load i8*, i8** %4
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %83)
store i32 0, i32* %12
br label %85
85: ; preds = %95, %81
%86 = load i32, i32* %12
%87 = load i32, i32* %5
%88 = icmp slt i32 %86, %87
br i1 %88, label %89, label %98
89: ; preds = %85
%90 = load i32, i32* %12
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds [10 x i32*], [10 x i32*]* %6, i64 0, i64 %91
%93 = load i32*, i32** %92
%94 = call i32 @fclose(i32* %93)
br label %95
95: ; preds = %89
%96 = load i32, i32* %12
%97 = add nsw i32 %96, 1
store i32 %97, i32* %12
br label %85
98: ; preds = %85
%99 = load i8*, i8** %9
%100 = call i32 @free(i8* %99)
%101 = load i32, i32* @EXIT_FAILURE
store i32 %101, i32* %3
br label %212
102: ; preds = %76
br label %103
103: ; preds = %191, %102
%104 = getelementptr inbounds [10 x i32*], [10 x i32*]* %6, i64 0, i64 0
%105 = load i32, i32* %5
%106 = call i32 @leuTodosOsArquivosPorCompleto(i32** %104, i32 %105)
%107 = icmp ne i32 %106, 0
%108 = xor i1 %107, true
br i1 %108, label %109, label %192
109: ; preds = %103
%110 = bitcast [10 x i32]* %13 to i8*
store i32 0, i32* %14
br label %111
111: ; preds = %128, %109
%112 = load i32, i32* %14
%113 = load i32, i32* %5
%114 = icmp slt i32 %112, %113
br i1 %114, label %115, label %131
115: ; preds = %111
%116 = load i32, i32* %14
%117 = sext i32 %116 to i64
%118 = getelementptr inbounds [10 x [5 x i32]], [10 x [5 x i32]]* %8, i64 0, i64 %117
%119 = getelementptr inbounds [5 x i32], [5 x i32]* %118, i64 0, i64 0
%120 = load i32, i32* %14
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds [10 x i32*], [10 x i32*]* %6, i64 0, i64 %121
%123 = load i32*, i32** %122
%124 = call i32 @fread(i32* %119, i32 4, i32 5, i32* %123)
%125 = load i32, i32* %14
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds [10 x i32], [10 x i32]* %13, i64 0, i64 %126
store i32 %124, i32* %127
br label %128
128: ; preds = %115
%129 = load i32, i32* %14
%130 = add nsw i32 %129, 1
store i32 %130, i32* %14
br label %111
131: ; preds = %111
%132 = bitcast [10 x i32]* %15 to i8*
%133 = getelementptr inbounds [10 x [5 x i32]], [10 x [5 x i32]]* %8, i64 0, i64 0
%134 = bitcast [5 x i32]* %133 to i32**
%135 = load i32, i32* %5
%136 = getelementptr inbounds [10 x i32], [10 x i32]* %15, i64 0, i64 0
%137 = getelementptr inbounds [10 x i32], [10 x i32]* %13, i64 0, i64 0
%138 = call i32 @pegaMenor(i32** %134, i32 %135, i32* %136, i32* %137)
store i32 %138, i32* %16
br label %139
139: ; preds = %184, %131
%140 = load i32, i32* %16
%141 = icmp ne i32 %140, -1
br i1 %141, label %142, label %191
142: ; preds = %139
%143 = load i32, i32* %16
%144 = sext i32 %143 to i64
%145 = getelementptr inbounds [10 x [5 x i32]], [10 x [5 x i32]]* %8, i64 0, i64 %144
%146 = load i32, i32* %16
%147 = sext i32 %146 to i64
%148 = getelementptr inbounds [10 x i32], [10 x i32]* %15, i64 0, i64 %147
%149 = load i32, i32* %148
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds [5 x i32], [5 x i32]* %145, i64 0, i64 %150
%152 = load i32*, i32** %7
%153 = call i32 @fwrite(i32* %151, i32 4, i32 1, i32* %152)
%154 = load i32, i32* %16
%155 = sext i32 %154 to i64
%156 = getelementptr inbounds [10 x i32], [10 x i32]* %15, i64 0, i64 %155
%157 = load i32, i32* %156
%158 = add nsw i32 %157, 1
store i32 %158, i32* %156
%159 = load i32, i32* %16
%160 = sext i32 %159 to i64
%161 = getelementptr inbounds [10 x i32], [10 x i32]* %15, i64 0, i64 %160
%162 = load i32, i32* %161
%163 = load i32, i32* %16
%164 = sext i32 %163 to i64
%165 = getelementptr inbounds [10 x i32], [10 x i32]* %13, i64 0, i64 %164
%166 = load i32, i32* %165
%167 = icmp eq i32 %162, %166
br i1 %167, label %168, label %184
168: ; preds = %142
%169 = load i32, i32* %16
%170 = sext i32 %169 to i64
%171 = getelementptr inbounds [10 x [5 x i32]], [10 x [5 x i32]]* %8, i64 0, i64 %170
%172 = getelementptr inbounds [5 x i32], [5 x i32]* %171, i64 0, i64 0
%173 = load i32, i32* %16
%174 = sext i32 %173 to i64
%175 = getelementptr inbounds [10 x i32*], [10 x i32*]* %6, i64 0, i64 %174
%176 = load i32*, i32** %175
%177 = call i32 @fread(i32* %172, i32 4, i32 5, i32* %176)
%178 = load i32, i32* %16
%179 = sext i32 %178 to i64
%180 = getelementptr inbounds [10 x i32], [10 x i32]* %13, i64 0, i64 %179
store i32 %177, i32* %180
%181 = load i32, i32* %16
%182 = sext i32 %181 to i64
%183 = getelementptr inbounds [10 x i32], [10 x i32]* %15, i64 0, i64 %182
store i32 0, i32* %183
br label %184
184: ; preds = %168, %142
%185 = getelementptr inbounds [10 x [5 x i32]], [10 x [5 x i32]]* %8, i64 0, i64 0
%186 = bitcast [5 x i32]* %185 to i32**
%187 = load i32, i32* %5
%188 = getelementptr inbounds [10 x i32], [10 x i32]* %15, i64 0, i64 0
%189 = getelementptr inbounds [10 x i32], [10 x i32]* %13, i64 0, i64 0
%190 = call i32 @pegaMenor(i32** %186, i32 %187, i32* %188, i32* %189)
store i32 %190, i32* %16
br label %139
191: ; preds = %139
br label %103
192: ; preds = %103
store i32 0, i32* %17
br label %193
193: ; preds = %203, %192
%194 = load i32, i32* %17
%195 = load i32, i32* %5
%196 = icmp slt i32 %194, %195
br i1 %196, label %197, label %206
197: ; preds = %193
%198 = load i32, i32* %17
%199 = sext i32 %198 to i64
%200 = getelementptr inbounds [10 x i32*], [10 x i32*]* %6, i64 0, i64 %199
%201 = load i32*, i32** %200
%202 = call i32 @fclose(i32* %201)
br label %203
203: ; preds = %197
%204 = load i32, i32* %17
%205 = add nsw i32 %204, 1
store i32 %205, i32* %17
br label %193
206: ; preds = %193
%207 = load i32*, i32** %7
%208 = call i32 @fclose(i32* %207)
%209 = load i8*, i8** %9
%210 = call i32 @free(i8* %209)
%211 = load i32, i32* @EXIT_SUCCESS
store i32 %211, i32* %3
br label %212
212: ; preds = %206, %98, %68, %27
%213 = load i32, i32* %3
ret i32 %213
}

LLVM IR (-O2):
@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 = [5 x i8] c"%s%d\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [36 x i8] c"Problema na abertura do arquivo %s\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@EXIT_SUCCESS = global i32 0
define i32 @intercalar(i8* %0, i32 %1) {
%3 = alloca [10 x i32*]
%4 = alloca [10 x [5 x i32]]
%5 = alloca [10 x i32]
%6 = alloca [10 x i32]
%7 = bitcast [10 x i32*]* %3 to i8*
%8 = bitcast [10 x [5 x i32]]* %4 to i8*
%9 = getelementptr inbounds i8, i8* %0, i64 10
%10 = tail call i32 @strlen(i8* %9)
%11 = tail call i8* @malloc(i32 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %22, label %13
13: ; preds = %2
%14 = icmp sgt i32 %1, 0
br i1 %14, label %15, label %55
15: ; preds = %13
%16 = zext i32 %1 to i64
%17 = zext i32 %1 to i64
%18 = tail call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 0)
%19 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%20 = getelementptr inbounds [10 x i32*], [10 x i32*]* %3, i64 0, i64 0
store i32* %19, i32** %20
%21 = icmp eq i32* %19, null
br i1 %21, label %33, label %49
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
br label %133
25: ; preds = %49
%26 = trunc i64 %51 to i32
%27 = tail call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %26)
%28 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%29 = getelementptr inbounds [10 x i32*], [10 x i32*]* %3, i64 0, i64 %51
store i32* %28, i32** %29
%30 = icmp eq i32* %28, null
br i1 %30, label %31, label %49
31: ; preds = %25
%32 = icmp ult i64 %51, %16
br label %33
33: ; preds = %31, %15
%34 = phi i64 [ %51, %31 ], [ 0, %15 ]
%35 = phi i1 [ %32, %31 ], [ true, %15 ]
%36 = trunc i64 %34 to i32
%37 = load i32, i32* @stderr
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%39 = icmp eq i32 %36, 0
br i1 %39, label %53, label %40
40: ; preds = %33
%41 = and i64 %34, 4294967295
br label %42
42: ; preds = %40, %42
%43 = phi i64 [ 0, %40 ], [ %47, %42 ]
%44 = getelementptr inbounds [10 x i32*], [10 x i32*]* %3, i64 0, i64 %43
%45 = load i32*, i32** %44
%46 = tail call i32 @fclose(i32* %45)
%47 = add nuw nsw i64 %43, 1
%48 = icmp eq i64 %47, %41
br i1 %48, label %53, label %42
49: ; preds = %15, %25
%50 = phi i64 [ %51, %25 ], [ 0, %15 ]
%51 = add nuw nsw i64 %50, 1
%52 = icmp eq i64 %51, %17
br i1 %52, label %55, label %25
53: ; preds = %42, %33
%54 = tail call i32 @free(i8* %11)
br i1 %35, label %133, label %55
55: ; preds = %49, %13, %53
%56 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%57 = icmp eq i32* %56, null
br i1 %57, label %69, label %58
58: ; preds = %55
%59 = getelementptr inbounds [10 x i32*], [10 x i32*]* %3, i64 0, i64 0
%60 = call i32 @leuTodosOsArquivosPorCompleto(i32** %59, i32 %1)
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %83
62: ; preds = %58
%63 = bitcast [10 x i32]* %5 to i8*
%64 = bitcast [10 x i32]* %6 to i8*
%65 = bitcast [10 x [5 x i32]]* %4 to i32**
%66 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%67 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 0
%68 = zext i32 %1 to i64
br label %86
69: ; preds = %55
%70 = load i32, i32* @stderr
%71 = tail call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br i1 %14, label %72, label %74
72: ; preds = %69
%73 = zext i32 %1 to i64
br label %76
74: ; preds = %76, %69
%75 = tail call i32 @free(i8* %11)
br label %133
76: ; preds = %72, %76
%77 = phi i64 [ 0, %72 ], [ %81, %76 ]
%78 = getelementptr inbounds [10 x i32*], [10 x i32*]* %3, i64 0, i64 %77
%79 = load i32*, i32** %78
%80 = tail call i32 @fclose(i32* %79)
%81 = add nuw nsw i64 %77, 1
%82 = icmp eq i64 %81, %73
br i1 %82, label %74, label %76
83: ; preds = %120, %58
br i1 %14, label %84, label %123
84: ; preds = %83
%85 = zext i32 %1 to i64
br label %126
86: ; preds = %62, %120
br i1 %14, label %90, label %87
87: ; preds = %90, %86
%88 = call i32 @pegaMenor(i32** %65, i32 %1, i32* %66, i32* %67)
%89 = icmp eq i32 %88, -1
br i1 %89, label %120, label %99
90: ; preds = %86, %90
%91 = phi i64 [ %97, %90 ], [ 0, %86 ]
%92 = getelementptr inbounds [10 x [5 x i32]], [10 x [5 x i32]]* %4, i64 0, i64 %91, i64 0
%93 = getelementptr inbounds [10 x i32*], [10 x i32*]* %3, i64 0, i64 %91
%94 = load i32*, i32** %93
%95 = call i32 @fread(i32* %92, i32 4, i32 5, i32* %94)
%96 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 %91
store i32 %95, i32* %96
%97 = add nuw nsw i64 %91, 1
%98 = icmp eq i64 %97, %68
br i1 %98, label %87, label %90
99: ; preds = %87, %117
%100 = phi i32 [ %118, %117 ], [ %88, %87 ]
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %101
%103 = load i32, i32* %102
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds [10 x [5 x i32]], [10 x [5 x i32]]* %4, i64 0, i64 %101, i64 %104
%106 = call i32 @fwrite(i32* %105, i32 4, i32 1, i32* %56)
%107 = load i32, i32* %102
%108 = add nsw i32 %107, 1
store i32 %108, i32* %102
%109 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 %101
%110 = load i32, i32* %109
%111 = icmp eq i32 %108, %110
br i1 %111, label %112, label %117
112: ; preds = %99
%113 = getelementptr inbounds [10 x [5 x i32]], [10 x [5 x i32]]* %4, i64 0, i64 %101, i64 0
%114 = getelementptr inbounds [10 x i32*], [10 x i32*]* %3, i64 0, i64 %101
%115 = load i32*, i32** %114
%116 = call i32 @fread(i32* %113, i32 4, i32 5, i32* %115)
store i32 %116, i32* %109
store i32 0, i32* %102
br label %117
117: ; preds = %112, %99
%118 = call i32 @pegaMenor(i32** %65, i32 %1, i32* %66, i32* %67)
%119 = icmp eq i32 %118, -1
br i1 %119, label %120, label %99
120: ; preds = %117, %87
%121 = call i32 @leuTodosOsArquivosPorCompleto(i32** %59, i32 %1)
%122 = icmp eq i32 %121, 0
br i1 %122, label %86, label %83
123: ; preds = %126, %83
%124 = call i32 @fclose(i32* %56)
%125 = call i32 @free(i8* %11)
br label %133
126: ; preds = %84, %126
%127 = phi i64 [ 0, %84 ], [ %131, %126 ]
%128 = getelementptr inbounds [10 x i32*], [10 x i32*]* %3, i64 0, i64 %127
%129 = load i32*, i32** %128
%130 = call i32 @fclose(i32* %129)
%131 = add nuw nsw i64 %127, 1
%132 = icmp eq i64 %131, %85
br i1 %132, label %123, label %126
133: ; preds = %53, %123, %74, %22
%134 = phi i32* [ @EXIT_FAILURE, %22 ], [ @EXIT_FAILURE, %74 ], [ @EXIT_SUCCESS, %123 ], [ @EXIT_FAILURE, %53 ]
%135 = load i32, i32* %134
ret i32 %135
}