#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char fscanf(int /*<<< orphan*/ *, char *, char);
int /*<<< orphan*/ printf(char *, ...);
void main() {
  FILE *arquivo;
  char access, ch;
  int cont;
  arquivo = fopen("arq8.txt", "r");
  if (arquivo == NULL) {
    printf("Erro ao abrir arquivo ");
  } else {
    access = fscanf(arquivo, "%c", ch);
    while (access != EOF) {
      cont++;
      access = fscanf(arquivo, "%c", ch);
    }
    printf("\nTotal de caracteres: %d\n", cont);
  }
  fclose(arquivo);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    117d <main+0x3d>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e0 <main+0xa0>
mov    -0x8(%rbp),%rdi
lea    0xe9a(%rip),%rsi
movsbl -0xa(%rbp),%edx
call   1050 <fscanf@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
mov    0x2e49(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11cf <main+0x8f>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe64(%rip),%rsi
movsbl -0xa(%rbp),%edx
call   1050 <fscanf@plt>
mov    %al,-0x9(%rbp)
jmp    1194 <main+0x54>
mov    -0x10(%rbp),%esi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeb2(%rip),%rdi
lea    0xeb4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11a7 <main+0x67>
lea    0xeb9(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1050 <fscanf@plt>
mov    0x2e6b(%rip),%r15
nopl   (%rax)
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1050 <fscanf@plt>
cmp    (%r15),%al
jne    1180 <main+0x40>
lea    0xe89(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11b5 <main+0x75>
lea    0xe5d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"arq8.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"Erro ao abrir arquivo \00"
@.str.3 = [3 x i8] c"%c\00"
@EOF = global i8 0
@.str.4 = [26 x i8] c"\0ATotal de caracteres: %d\0A\00"
define void @main() {
%1 = alloca i32*
%2 = alloca i8
%3 = alloca i8
%4 = alloca i32
%5 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %1
%6 = load i32*, i32** %1
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %29
10: ; preds = %0
%11 = load i32*, i32** %1
%12 = load i8, i8* %3
%13 = call signext i8 @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8 signext %12)
store i8 %13, i8* %2
br label %14
14: ; preds = %20, %10
%15 = load i8, i8* %2
%16 = sext i8 %15 to i32
%17 = load i8, i8* @EOF
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %16, %18
br i1 %19, label %20, label %26
20: ; preds = %14
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
%23 = load i32*, i32** %1
%24 = load i8, i8* %3
%25 = call signext i8 @fscanf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8 signext %24)
store i8 %25, i8* %2
br label %14
26: ; preds = %14
%27 = load i32, i32* %4
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %26, %8
%30 = load i32*, i32** %1
%31 = call i32 @fclose(i32* %30)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"arq8.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"Erro ao abrir arquivo \00"
@.str.3 = [3 x i8] c"%c\00"
@EOF = global i8 0
@.str.4 = [26 x i8] c"\0ATotal de caracteres: %d\0A\00"
define void @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %17
5: ; preds = %0
%6 = tail call signext i8 @fscanf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8 signext undef)
%7 = load i8, i8* @EOF
%8 = icmp ne i8 %6, %7
br label %9
9: ; preds = %5, %9
%10 = phi i32 [ %11, %9 ], [ undef, %5 ]
%11 = add nsw i32 %10, 1
%12 = tail call signext i8 @fscanf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8 signext undef)
%13 = load i8, i8* @EOF
%14 = icmp eq i8 %12, %13
br i1 %14, label %15, label %9
15: ; preds = %9
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %11)
br label %17
17: ; preds = %15, %3
%18 = tail call i32 @fclose(i32* %1)
ret void
}