#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*/ aleatorio;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ atoi_reverse(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void cria_arquivos(int quant_arquivos, int tamanho) {
  char nome_arq[22];
  char arqv[] = "arquivos/arquivo";
  for (int i = 0; i < 16; i++) {
    nome_arq[i] = arqv[i];
  }
  nome_arq[17] = '.';
  nome_arq[18] = 'b';
  nome_arq[19] = 'i';
  nome_arq[20] = 'n';
  nome_arq[21] = '\0';
  srand(time(NULL));
  for (int i = 0; i < quant_arquivos; i++) {
    nome_arq[16] = (char)atoi_reverse(i);
    FILE *arq = fopen(nome_arq, "wb");
    if (arq == NULL) {
      printf("Error ao abrir arquivo..\n");
      return;
    }
    for (int k = 0; k < (tamanho * 1024) / 4; k++) {
      int aleatorio = rand();
      fwrite(&aleatorio, sizeof(aleatorio), 1, arq);
    }
    fclose(arq);
  }
}


x86 assembly (clang, -O0):
<cria_arquivos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0xe6b(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe68(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe66(%rip),%al
mov    %al,-0x30(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x10,-0x44(%rbp)
jge    11dc <cria_arquivos+0x5c>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,1),%cl
movslq -0x44(%rbp),%rax
mov    %cl,-0x20(%rbp,%rax,1)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11b4 <cria_arquivos+0x34>
movb   $0x2e,-0xf(%rbp)
movb   $0x62,-0xe(%rbp)
movb   $0x69,-0xd(%rbp)
movb   $0x6e,-0xc(%rbp)
movb   $0x0,-0xb(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12bc <cria_arquivos+0x13c>
mov    -0x48(%rbp),%edi
call   1070 <atoi_reverse@plt>
mov    %al,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
lea    0xde8(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    124e <cria_arquivos+0xce>
lea    0xdd0(%rip),%rdi
call   1040 <printf@plt>
jmp    12bc <cria_arquivos+0x13c>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x8(%rbp),%eax
shl    $0xa,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
cmp    %ecx,%eax
jge    12a5 <cria_arquivos+0x125>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    %eax,-0x58(%rbp)
mov    -0x50(%rbp),%rcx
lea    -0x58(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1255 <cria_arquivos+0xd5>
mov    -0x50(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1207 <cria_arquivos+0x87>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cria_arquivos>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,0x8(%rsp)
mov    %edi,%r13d
movaps 0xe64(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x6e69622e,0x21(%rsp)
6e
movb   $0x0,0x25(%rsp)
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
test   %r13d,%r13d
jle    1258 <cria_arquivos+0xd8>
mov    0x8(%rsp),%r15d
shl    $0x8,%r15d
cmp    $0x2,%r15d
mov    $0x1,%eax
cmovl  %eax,%r15d
lea    0xc(%rsp),%rbx
xor    %ebp,%ebp
jmp    1200 <cria_arquivos+0x80>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   1040 <fclose@plt>
add    $0x1,%ebp
cmp    %r13d,%ebp
je     1258 <cria_arquivos+0xd8>
mov    %ebp,%edi
call   1070 <atoi_reverse@plt>
mov    %al,0x20(%rsp)
lea    0x10(%rsp),%rdi
lea    0xdfa(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1267 <cria_arquivos+0xe7>
mov    %rax,%r14
mov    %r15d,%r12d
cmpl   $0x0,0x8(%rsp)
jle    11f0 <cria_arquivos+0x70>
xchg   %ax,%ax
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %eax,0xc(%rsp)
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1090 <fwrite@plt>
add    $0xffffffff,%r12d
jne    1230 <cria_arquivos+0xb0>
jmp    11f0 <cria_arquivos+0x70>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda6(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@__const.cria_arquivos.arqv = [17 x i8] c"arquivos/arquivo\00"
@.str = [3 x i8] c"wb\00"
@.str.1 = [26 x i8] c"Error ao abrir arquivo..\0A\00"
define void @cria_arquivos(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [22 x i8]
%6 = alloca [17 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%12 = bitcast [17 x i8]* %6 to i8*
store i32 0, i32* %7
br label %13
13: ; preds = %24, %2
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 16
br i1 %15, label %16, label %27
16: ; preds = %13
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [17 x i8], [17 x i8]* %6, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [22 x i8], [22 x i8]* %5, i64 0, i64 %22
store i8 %20, i8* %23
br label %24
24: ; preds = %16
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %13
27: ; preds = %13
%28 = getelementptr inbounds [22 x i8], [22 x i8]* %5, i64 0, i64 17
store i8 46, i8* %28
%29 = getelementptr inbounds [22 x i8], [22 x i8]* %5, i64 0, i64 18
store i8 98, i8* %29
%30 = getelementptr inbounds [22 x i8], [22 x i8]* %5, i64 0, i64 19
store i8 105, i8* %30
%31 = getelementptr inbounds [22 x i8], [22 x i8]* %5, i64 0, i64 20
store i8 110, i8* %31
%32 = getelementptr inbounds [22 x i8], [22 x i8]* %5, i64 0, i64 21
store i8 0, i8* %32
%33 = call i32 @time(i32* null)
%34 = call i32 @srand(i32 %33)
store i32 0, i32* %8
br label %35
35: ; preds = %67, %27
%36 = load i32, i32* %8
%37 = load i32, i32* %3
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %70
39: ; preds = %35
%40 = load i32, i32* %8
%41 = call i64 @atoi_reverse(i32 %40)
%42 = trunc i64 %41 to i8
%43 = getelementptr inbounds [22 x i8], [22 x i8]* %5, i64 0, i64 16
store i8 %42, i8* %43
%44 = getelementptr inbounds [22 x i8], [22 x i8]* %5, i64 0, i64 0
%45 = call i32* @fopen(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %45, i32** %9
%46 = load i32*, i32** %9
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %50
48: ; preds = %39
%49 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %70
50: ; preds = %39
store i32 0, i32* %10
br label %51
51: ; preds = %61, %50
%52 = load i32, i32* %10
%53 = load i32, i32* %4
%54 = mul nsw i32 %53, 1024
%55 = sdiv i32 %54, 4
%56 = icmp slt i32 %52, %55
br i1 %56, label %57, label %64
57: ; preds = %51
%58 = call i32 (...) @rand()
store i32 %58, i32* %11
%59 = load i32*, i32** %9
%60 = call i32 @fwrite(i32* %11, i32 4, i32 1, i32* %59)
br label %61
61: ; preds = %57
%62 = load i32, i32* %10
%63 = add nsw i32 %62, 1
store i32 %63, i32* %10
br label %51
64: ; preds = %51
%65 = load i32*, i32** %9
%66 = call i32 @fclose(i32* %65)
br label %67
67: ; preds = %64
%68 = load i32, i32* %8
%69 = add nsw i32 %68, 1
store i32 %69, i32* %8
br label %35
70: ; preds = %48, %35
ret void
}

LLVM IR (-O2):
@__const.cria_arquivos.arqv = [17 x i8] c"arquivos/arquivo\00"
@.str = [3 x i8] c"wb\00"
@str = [25 x i8] c"Error ao abrir arquivo..\00"
define void @cria_arquivos(i32 %0, i32 %1) {
%3 = alloca [22 x i8]
%4 = getelementptr inbounds [22 x i8], [22 x i8]* %3, i64 0, i64 0
%5 = alloca i32
%6 = getelementptr inbounds [22 x i8], [22 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [22 x i8], [22 x i8]* %3, i64 0, i64 17
store i8 46, i8* %7
%8 = getelementptr inbounds [22 x i8], [22 x i8]* %3, i64 0, i64 18
store i8 98, i8* %8
%9 = getelementptr inbounds [22 x i8], [22 x i8]* %3, i64 0, i64 19
store i8 105, i8* %9
%10 = getelementptr inbounds [22 x i8], [22 x i8]* %3, i64 0, i64 20
store i8 110, i8* %10
%11 = getelementptr inbounds [22 x i8], [22 x i8]* %3, i64 0, i64 21
store i8 0, i8* %11
%12 = tail call i32 @time(i32* null)
%13 = tail call i32 @srand(i32 %12)
%14 = icmp sgt i32 %0, 0
br i1 %14, label %15, label %40
15: ; preds = %2
%16 = getelementptr inbounds [22 x i8], [22 x i8]* %3, i64 0, i64 16
%17 = shl i32 %1, 8
%18 = icmp sgt i32 %1, 0
%19 = bitcast i32* %5 to i8*
%20 = call i32 @llvm.smax.i32(i32 %17, i32 1)
br label %25
21: ; preds = %34, %31
%22 = tail call i32 @fclose(i32* %29)
%23 = add nuw nsw i32 %26, 1
%24 = icmp eq i32 %23, %0
br i1 %24, label %40, label %25
25: ; preds = %15, %21
%26 = phi i32 [ 0, %15 ], [ %23, %21 ]
%27 = tail call i64 @atoi_reverse(i32 %26)
%28 = trunc i64 %27 to i8
store i8 %28, i8* %16
%29 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %32, label %31
31: ; preds = %25
br i1 %18, label %34, label %21
32: ; preds = %25
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %40
34: ; preds = %31, %34
%35 = phi i32 [ %38, %34 ], [ 0, %31 ]
%36 = tail call i32 (...) @rand()
store i32 %36, i32* %5
%37 = call i32 @fwrite(i32* %5, i32 4, i32 1, i32* %29)
%38 = add nuw nsw i32 %35, 1
%39 = icmp eq i32 %38, %20
br i1 %39, label %21, label %34
40: ; preds = %21, %2, %32
ret void
}