#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*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  FILE *file_ptr = fopen("readme.md", "r");
  if (file_ptr != NULL) {
    int counter = 0;
    char symb;
    while ((symb = fgetc(file_ptr)) != EOF) {
      printf("%c", symb);
      ++counter;
    }
    printf("Couned %d symbols\n", counter);
    fclose(file_ptr);
  } else
    perror("fopen");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e4 <main+0x94>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x15(%rbp)
movsbl %al,%eax
mov    0x2e4a(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11c7 <main+0x77>
movsbl -0x15(%rbp),%esi
lea    0xe58(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1188 <main+0x38>
mov    -0x14(%rbp),%esi
lea    0xe3e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11f0 <main+0xa0>
lea    0xe37(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xea2(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11de <main+0x8e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e67(%rip),%r15
xor    %ebp,%ebp
cmp    (%r15),%al
je     11bb <main+0x6b>
xor    %ebp,%ebp
lea    0xe7b(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%al
jne    11a0 <main+0x50>
lea    0xe4d(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe3d(%rip),%rdi
call   1070 <perror@plt>
jmp    11d1 <main+0x81>

LLVM IR (-O0):
@.str = [10 x i8] c"readme.md\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [19 x i8] c"Couned %d symbols\0A\00"
@.str.4 = [6 x i8] c"fopen\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i8
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 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** %2
%6 = load i32*, i32** %2
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %27
8: ; preds = %0
store i32 0, i32* %3
br label %9
9: ; preds = %16, %8
%10 = load i32*, i32** %2
%11 = call signext i8 @fgetc(i32* %10)
store i8 %11, i8* %4
%12 = sext i8 %11 to i32
%13 = load i8, i8* @EOF
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %12, %14
br i1 %15, label %16, label %22
16: ; preds = %9
%17 = load i8, i8* %4
%18 = sext i8 %17 to i32
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %9
22: ; preds = %9
%23 = load i32, i32* %3
%24 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = load i32*, i32** %2
%26 = call i32 @fclose(i32* %25)
br label %29
27: ; preds = %0
%28 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %29
29: ; preds = %27, %22
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"readme.md\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [19 x i8] c"Couned %d symbols\0A\00"
@.str.4 = [6 x i8] c"fopen\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 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 %20, label %3
3: ; preds = %0
%4 = tail call signext i8 @fgetc(i32* %1)
%5 = load i8, i8* @EOF
%6 = icmp eq i8 %4, %5
br i1 %6, label %16, label %7
7: ; preds = %3, %7
%8 = phi i8 [ %13, %7 ], [ %4, %3 ]
%9 = phi i32 [ %12, %7 ], [ 0, %3 ]
%10 = sext i8 %8 to i32
%11 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = add nuw nsw i32 %9, 1
%13 = tail call signext i8 @fgetc(i32* %1)
%14 = load i8, i8* @EOF
%15 = icmp eq i8 %13, %14
br i1 %15, label %16, label %7
16: ; preds = %7, %3
%17 = phi i32 [ 0, %3 ], [ %12, %7 ]
%18 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = tail call i32 @fclose(i32* %1)
br label %22
20: ; preds = %0
%21 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
ret i32 0
}