#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;
scalar_t__ existeArquivo(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, int);
int /*<<< orphan*/ stderr;
int strlen(char const *);
int contarArquivos(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;
  }
  for (int i = 0; i < 10; i++) {
    sprintf(nomeArquivo, "%s%d", nomeBase, i);
    if (existeArquivo(nomeArquivo)) {
      quantidadeArquivos++;
    }
  }
  free(nomeArquivo);
  return quantidadeArquivos;
}


x86 assembly (clang, -O0):
<contarArquivos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
add    $0xa,%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c2 <contarArquivos+0x62>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1228 <contarArquivos+0xc8>
movl   $0x0,-0x24(%rbp)
cmpl   $0xa,-0x24(%rbp)
jge    1219 <contarArquivos+0xb9>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xe56(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <existeArquivo@plt>
cmp    $0x0,%rax
je     1206 <contarArquivos+0xa6>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    120b <contarArquivos+0xab>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c9 <contarArquivos+0x69>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<contarArquivos>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
add    $0xa,%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     12ea <contarArquivos+0x18a>
mov    %rax,%rbx
lea    0xeae(%rip),%r15
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <existeArquivo@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    $0x1,%ecx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <existeArquivo@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    $0x2,%ecx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <existeArquivo@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    $0x3,%ecx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <existeArquivo@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    $0x4,%ecx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <existeArquivo@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    $0x5,%ecx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <existeArquivo@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    $0x6,%ecx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <existeArquivo@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    $0x7,%ecx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <existeArquivo@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    $0x8,%ecx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <existeArquivo@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    $0x9,%ecx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <existeArquivo@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1308 <contarArquivos+0x1a8>
mov    0x2cef(%rip),%rax
mov    (%rax),%edi
lea    0xd06(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2cd2(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
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 = [5 x i8] c"%s%d\00"
define i32 @contarArquivos(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 10
%9 = call i32 @strlen(i8* %8)
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 1
%12 = trunc i64 %11 to i32
%13 = call i8* @malloc(i32 %12)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %1
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %2
br label %43
20: ; preds = %1
store i32 0, i32* %6
br label %21
21: ; preds = %36, %20
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 10
br i1 %23, label %24, label %39
24: ; preds = %21
%25 = load i8*, i8** %5
%26 = load i8*, i8** %3
%27 = load i32, i32* %6
%28 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32 %27)
%29 = load i8*, i8** %5
%30 = call i64 @existeArquivo(i8* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %24
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %35
35: ; preds = %32, %24
br label %36
36: ; preds = %35
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %21
39: ; preds = %21
%40 = load i8*, i8** %5
%41 = call i32 @free(i8* %40)
%42 = load i32, i32* %4
store i32 %42, i32* %2
br label %43
43: ; preds = %39, %16
%44 = load i32, i32* %2
ret i32 %44
}

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"
define i32 @contarArquivos(i8* %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 10
%3 = tail call i32 @strlen(i8* %2)
%4 = tail call i8* @malloc(i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %57, label %6
6: ; preds = %1
%7 = tail call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 0)
%8 = tail call i64 @existeArquivo(i8* %4)
%9 = icmp ne i64 %8, 0
%10 = zext i1 %9 to i32
%11 = tail call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 1)
%12 = tail call i64 @existeArquivo(i8* %4)
%13 = icmp ne i64 %12, 0
%14 = zext i1 %13 to i32
%15 = add nuw nsw i32 %10, %14
%16 = tail call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 2)
%17 = tail call i64 @existeArquivo(i8* %4)
%18 = icmp ne i64 %17, 0
%19 = zext i1 %18 to i32
%20 = add nuw nsw i32 %15, %19
%21 = tail call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 3)
%22 = tail call i64 @existeArquivo(i8* %4)
%23 = icmp ne i64 %22, 0
%24 = zext i1 %23 to i32
%25 = add nuw nsw i32 %20, %24
%26 = tail call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 4)
%27 = tail call i64 @existeArquivo(i8* %4)
%28 = icmp ne i64 %27, 0
%29 = zext i1 %28 to i32
%30 = add nuw nsw i32 %25, %29
%31 = tail call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 5)
%32 = tail call i64 @existeArquivo(i8* %4)
%33 = icmp ne i64 %32, 0
%34 = zext i1 %33 to i32
%35 = add nuw nsw i32 %30, %34
%36 = tail call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 6)
%37 = tail call i64 @existeArquivo(i8* %4)
%38 = icmp ne i64 %37, 0
%39 = zext i1 %38 to i32
%40 = add nuw nsw i32 %35, %39
%41 = tail call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 7)
%42 = tail call i64 @existeArquivo(i8* %4)
%43 = icmp ne i64 %42, 0
%44 = zext i1 %43 to i32
%45 = add nuw nsw i32 %40, %44
%46 = tail call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 8)
%47 = tail call i64 @existeArquivo(i8* %4)
%48 = icmp ne i64 %47, 0
%49 = zext i1 %48 to i32
%50 = add nuw nsw i32 %45, %49
%51 = tail call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 9)
%52 = tail call i64 @existeArquivo(i8* %4)
%53 = icmp ne i64 %52, 0
%54 = zext i1 %53 to i32
%55 = add nuw nsw i32 %50, %54
%56 = tail call i32 @free(i8* %4)
br label %61
57: ; preds = %1
%58 = load i32, i32* @stderr
%59 = tail call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
%60 = load i32, i32* @EXIT_FAILURE
br label %61
61: ; preds = %6, %57
%62 = phi i32 [ %60, %57 ], [ %55, %6 ]
ret i32 %62
}