#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*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int main() {
  FILE *f;
  char filename[] = "input.txt";
  char riga[] = "a b c";
  char parola[100];
  char c;
  int i = 0;
  printf("Apro il file %s in lettura (r)\n", filename);
  f = fopen(filename, "r");
  if (f) {
    printf("File aperto correttamente.\nLeggo il contenuto:\n");
    while ((c = getc(f)) != EOF) {
      putchar(c);
      i++;
    }
    printf("\nHo letto %d caratteri\n", i);
    fclose(f);
    printf("Apro il file %s in lettura/scrittura (r+)\n", filename);
    f = fopen(filename, "r+");
    printf("Scrivo: %s\n", riga);
    fprintf(f, "%s", riga);
    printf("Leggo il contenuto:\n");
    fseek(f, 0, SEEK_SET);
    i = 0;
    while ((c = getc(f)) != EOF) {
      putchar(c);
      i++;
    }
    printf("\nHo letto %d caratteri\n", i);
    fclose(f);
    printf("Apro il file %s in lettura/scrittura (w+)\n", filename);
    f = fopen(filename, "w+");
    printf("Scrivo: %s\n", riga);
    fprintf(f, "%s", riga);
    printf("Leggo il contenuto:\n");
    fseek(f, 0, SEEK_SET);
    i = 0;
    while ((c = getc(f)) != EOF) {
      putchar(c);
      i++;
    }
    printf("\nHo letto %d caratteri\n", i);
    fclose(f);
    printf("Apro il file %s in lettura/scrittura (a+)\n", filename);
    f = fopen(filename, "a+");
    printf("Scrivo: %s\n", riga);
    fprintf(f, " %s", riga);
    printf("Leggo il contenuto:\n");
    fseek(f, 0, SEEK_SET);
    i = 0;
    while ((c = getc(f)) != EOF) {
      putchar(c);
      i++;
    }
    printf("\nHo letto %d caratteri\n", i);
    fclose(f);
  } else {
    printf("Errore apertura. Forse il file non esiste.\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe77(%rip),%rax
mov    %rax,-0x1a(%rbp)
mov    0xe74(%rip),%ax
mov    %ax,-0x12(%rbp)
mov    0xe6c(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    0xe66(%rip),%ax
mov    %ax,-0x1c(%rbp)
movl   $0x0,-0x98(%rbp)
lea    -0x1a(%rbp),%rsi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x1a(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     14e6 <main+0x376>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1090 <getc@plt>
mov    %al,-0x91(%rbp)
movsbl %al,%eax
mov    0x2dda(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1239 <main+0xc9>
movsbl -0x91(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    11f5 <main+0x85>
mov    -0x98(%rbp),%esi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x1a(%rbp),%rsi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x1a(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x20(%rbp),%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    0xe74(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d1d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
movl   $0x0,-0x98(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <getc@plt>
mov    %al,-0x91(%rbp)
movsbl %al,%eax
mov    0x2d01(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1312 <main+0x1a2>
movsbl -0x91(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    12ce <main+0x15e>
mov    -0x98(%rbp),%esi
lea    0xd43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x1a(%rbp),%rsi
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x1a(%rbp),%rdi
lea    0xd93(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x20(%rbp),%rsi
lea    0xd48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    0xd9b(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xccb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2c44(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
movl   $0x0,-0x98(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <getc@plt>
mov    %al,-0x91(%rbp)
movsbl %al,%eax
mov    0x2c28(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     13eb <main+0x27b>
movsbl -0x91(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    13a7 <main+0x237>
mov    -0x98(%rbp),%esi
lea    0xc6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x1a(%rbp),%rsi
lea    0xccf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x1a(%rbp),%rdi
lea    0xce8(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x20(%rbp),%rsi
lea    0xc6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    0xcc1(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xbf2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2b6b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
movl   $0x0,-0x98(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <getc@plt>
mov    %al,-0x91(%rbp)
movsbl %al,%eax
mov    0x2b4f(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     14c4 <main+0x354>
movsbl -0x91(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    1480 <main+0x310>
mov    -0x98(%rbp),%esi
lea    0xb91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
jmp    14f4 <main+0x384>
lea    0xc27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
movabs $0x78742e7475706e69,%rax
2e 74 78
mov    %rax,0x10(%rsp)
movw   $0x74,0x18(%rsp)
movw   $0x63,0xc(%rsp)
movl   $0x20622061,0x8(%rsp)
20
lea    0xe48(%rip),%rdi
xor    %ebp,%ebp
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe50(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1462 <main+0x2d2>
mov    %rax,%r14
lea    0xf14(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   10b0 <getc@plt>
mov    0x2dd9(%rip),%r15
cmp    (%r15),%al
je     1238 <main+0xa8>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
mov    %r14,%rdi
call   10b0 <getc@plt>
cmp    (%r15),%al
jne    1220 <main+0x90>
lea    0xdf3(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
lea    0xdf1(%rip),%rdi
lea    0x10(%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe06(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r14
lea    0xdf7(%rip),%rdi
lea    0x8(%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1070 <fputs@plt>
lea    0xe88(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d2a(%rip),%r12
mov    (%r12),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r14,%rdi
call   10b0 <getc@plt>
mov    $0x0,%ebp
cmp    (%r15),%al
je     12e8 <main+0x158>
xor    %ebp,%ebp
movsbl %al,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
mov    %r14,%rdi
call   10b0 <getc@plt>
cmp    (%r15),%al
jne    12d0 <main+0x140>
lea    0xd43(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
lea    0xd7d(%rip),%rdi
lea    0x10(%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd92(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r14
lea    0xd49(%rip),%rdi
lea    0x8(%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1070 <fputs@plt>
lea    0xdda(%rip),%rdi
call   1040 <puts@plt>
mov    (%r12),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r14,%rdi
call   10b0 <getc@plt>
cmp    (%r15),%al
je     1398 <main+0x208>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl %al,%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
mov    %r14,%rdi
call   10b0 <getc@plt>
cmp    (%r15),%al
jne    1380 <main+0x1f0>
lea    0xc93(%rip),%rdi
xor    %ebp,%ebp
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
lea    0xcf9(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd0e(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbx
lea    0xc97(%rip),%rdi
lea    0x8(%rsp),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xce9(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1080 <fprintf@plt>
lea    0xd21(%rip),%rdi
call   1040 <puts@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   10b0 <getc@plt>
cmp    (%r15),%al
je     1448 <main+0x2b8>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
call   10b0 <getc@plt>
cmp    (%r15),%al
jne    1430 <main+0x2a0>
lea    0xbe3(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    146e <main+0x2de>
lea    0xc7b(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.filename = [10 x i8] c"input.txt\00"
@__const.main.riga = [6 x i8] c"a b c\00"
@.str = [32 x i8] c"Apro il file %s in lettura (r)\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [48 x i8] c"File aperto correttamente.\0ALeggo il contenuto:\0A\00"
@EOF = global i8 0
@.str.3 = [24 x i8] c"\0AHo letto %d caratteri\0A\00"
@.str.4 = [43 x i8] c"Apro il file %s in lettura/scrittura (r+)\0A\00"
@.str.5 = [3 x i8] c"r+\00"
@.str.6 = [12 x i8] c"Scrivo: %s\0A\00"
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [21 x i8] c"Leggo il contenuto:\0A\00"
@SEEK_SET = global i32 0
@.str.9 = [43 x i8] c"Apro il file %s in lettura/scrittura (w+)\0A\00"
@.str.10 = [3 x i8] c"w+\00"
@.str.11 = [43 x i8] c"Apro il file %s in lettura/scrittura (a+)\0A\00"
@.str.12 = [3 x i8] c"a+\00"
@.str.13 = [4 x i8] c" %s\00"
@.str.14 = [44 x i8] c"Errore apertura. Forse il file non esiste.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [10 x i8]
%4 = alloca [6 x i8]
%5 = alloca [100 x i8]
%6 = alloca i8
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [10 x i8]* %3 to i8*
%9 = bitcast [6 x i8]* %4 to i8*
store i32 0, i32* %7
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %2
%14 = load i32*, i32** %2
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %125
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %25, %16
%19 = load i32*, i32** %2
%20 = call signext i8 @getc(i32* %19)
store i8 %20, i8* %6
%21 = sext i8 %20 to i32
%22 = load i8, i8* @EOF
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %21, %23
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = load i8, i8* %6
%27 = call i32 @putchar(i8 signext %26)
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %18
30: ; preds = %18
%31 = load i32, i32* %7
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = load i32*, i32** %2
%34 = call i32 @fclose(i32* %33)
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %35)
%37 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %38, i32** %2
%39 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %39)
%41 = load i32*, i32** %2
%42 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%43 = call i32 @fprintf(i32* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%45 = load i32*, i32** %2
%46 = load i32, i32* @SEEK_SET
%47 = call i32 @fseek(i32* %45, i32 0, i32 %46)
store i32 0, i32* %7
br label %48
48: ; preds = %55, %30
%49 = load i32*, i32** %2
%50 = call signext i8 @getc(i32* %49)
store i8 %50, i8* %6
%51 = sext i8 %50 to i32
%52 = load i8, i8* @EOF
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %51, %53
br i1 %54, label %55, label %60
55: ; preds = %48
%56 = load i8, i8* %6
%57 = call i32 @putchar(i8 signext %56)
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %48
60: ; preds = %48
%61 = load i32, i32* %7
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %61)
%63 = load i32*, i32** %2
%64 = call i32 @fclose(i32* %63)
%65 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.9, i64 0, i64 0), i8* %65)
%67 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%68 = call i32* @fopen(i8* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
store i32* %68, i32** %2
%69 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %69)
%71 = load i32*, i32** %2
%72 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%73 = call i32 @fprintf(i32* %71, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %72)
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%75 = load i32*, i32** %2
%76 = load i32, i32* @SEEK_SET
%77 = call i32 @fseek(i32* %75, i32 0, i32 %76)
store i32 0, i32* %7
br label %78
78: ; preds = %85, %60
%79 = load i32*, i32** %2
%80 = call signext i8 @getc(i32* %79)
store i8 %80, i8* %6
%81 = sext i8 %80 to i32
%82 = load i8, i8* @EOF
%83 = sext i8 %82 to i32
%84 = icmp ne i32 %81, %83
br i1 %84, label %85, label %90
85: ; preds = %78
%86 = load i8, i8* %6
%87 = call i32 @putchar(i8 signext %86)
%88 = load i32, i32* %7
%89 = add nsw i32 %88, 1
store i32 %89, i32* %7
br label %78
90: ; preds = %78
%91 = load i32, i32* %7
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %91)
%93 = load i32*, i32** %2
%94 = call i32 @fclose(i32* %93)
%95 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.11, i64 0, i64 0), i8* %95)
%97 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%98 = call i32* @fopen(i8* %97, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
store i32* %98, i32** %2
%99 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %99)
%101 = load i32*, i32** %2
%102 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%103 = call i32 @fprintf(i32* %101, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), i8* %102)
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%105 = load i32*, i32** %2
%106 = load i32, i32* @SEEK_SET
%107 = call i32 @fseek(i32* %105, i32 0, i32 %106)
store i32 0, i32* %7
br label %108
108: ; preds = %115, %90
%109 = load i32*, i32** %2
%110 = call signext i8 @getc(i32* %109)
store i8 %110, i8* %6
%111 = sext i8 %110 to i32
%112 = load i8, i8* @EOF
%113 = sext i8 %112 to i32
%114 = icmp ne i32 %111, %113
br i1 %114, label %115, label %120
115: ; preds = %108
%116 = load i8, i8* %6
%117 = call i32 @putchar(i8 signext %116)
%118 = load i32, i32* %7
%119 = add nsw i32 %118, 1
store i32 %119, i32* %7
br label %108
120: ; preds = %108
%121 = load i32, i32* %7
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %121)
%123 = load i32*, i32** %2
%124 = call i32 @fclose(i32* %123)
br label %127
125: ; preds = %0
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.14, i64 0, i64 0))
br label %127
127: ; preds = %125, %120
%128 = load i32, i32* %1
ret i32 %128
}

LLVM IR (-O2):
@__const.main.filename = [10 x i8] c"input.txt\00"
@__const.main.riga = [6 x i8] c"a b c\00"
@.str = [32 x i8] c"Apro il file %s in lettura (r)\0A\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.3 = [24 x i8] c"\0AHo letto %d caratteri\0A\00"
@.str.4 = [43 x i8] c"Apro il file %s in lettura/scrittura (r+)\0A\00"
@.str.5 = [3 x i8] c"r+\00"
@.str.6 = [12 x i8] c"Scrivo: %s\0A\00"
@SEEK_SET = global i32 0
@.str.9 = [43 x i8] c"Apro il file %s in lettura/scrittura (w+)\0A\00"
@.str.10 = [3 x i8] c"w+\00"
@.str.11 = [43 x i8] c"Apro il file %s in lettura/scrittura (a+)\0A\00"
@.str.12 = [3 x i8] c"a+\00"
@.str.13 = [4 x i8] c" %s\00"
@str = [43 x i8] c"Errore apertura. Forse il file non esiste.\00"
@str.15 = [47 x i8] c"File aperto correttamente.\0ALeggo il contenuto:\00"
@str.18 = [20 x i8] c"Leggo il contenuto:\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = alloca [6 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %3)
%6 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %91, label %8
8: ; preds = %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.15, i64 0, i64 0))
%10 = call signext i8 @getc(i32* %6)
%11 = load i8, i8* @EOF
%12 = icmp eq i8 %10, %11
br i1 %12, label %21, label %13
13: ; preds = %8, %13
%14 = phi i8 [ %18, %13 ], [ %10, %8 ]
%15 = phi i32 [ %17, %13 ], [ 0, %8 ]
%16 = call i32 @putchar(i8 signext %14)
%17 = add nuw nsw i32 %15, 1
%18 = call signext i8 @getc(i32* %6)
%19 = load i8, i8* @EOF
%20 = icmp eq i8 %18, %19
br i1 %20, label %21, label %13
21: ; preds = %13, %8
%22 = phi i32 [ 0, %8 ], [ %17, %13 ]
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = call i32 @fclose(i32* %6)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%26 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%28 = call i32 @fputs(i8* %4, i32* %26)
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.18, i64 0, i64 0))
%30 = load i32, i32* @SEEK_SET
%31 = call i32 @fseek(i32* %26, i32 0, i32 %30)
%32 = call signext i8 @getc(i32* %26)
%33 = load i8, i8* @EOF
%34 = icmp eq i8 %32, %33
br i1 %34, label %43, label %35
35: ; preds = %21, %35
%36 = phi i8 [ %40, %35 ], [ %32, %21 ]
%37 = phi i32 [ %39, %35 ], [ 0, %21 ]
%38 = call i32 @putchar(i8 signext %36)
%39 = add nuw nsw i32 %37, 1
%40 = call signext i8 @getc(i32* %26)
%41 = load i8, i8* @EOF
%42 = icmp eq i8 %40, %41
br i1 %42, label %43, label %35
43: ; preds = %35, %21
%44 = phi i32 [ 0, %21 ], [ %39, %35 ]
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%46 = call i32 @fclose(i32* %26)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.9, i64 0, i64 0), i8* %3)
%48 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%50 = call i32 @fputs(i8* %4, i32* %48)
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.18, i64 0, i64 0))
%52 = load i32, i32* @SEEK_SET
%53 = call i32 @fseek(i32* %48, i32 0, i32 %52)
%54 = call signext i8 @getc(i32* %48)
%55 = load i8, i8* @EOF
%56 = icmp eq i8 %54, %55
br i1 %56, label %65, label %57
57: ; preds = %43, %57
%58 = phi i8 [ %62, %57 ], [ %54, %43 ]
%59 = phi i32 [ %61, %57 ], [ 0, %43 ]
%60 = call i32 @putchar(i8 signext %58)
%61 = add nuw nsw i32 %59, 1
%62 = call signext i8 @getc(i32* %48)
%63 = load i8, i8* @EOF
%64 = icmp eq i8 %62, %63
br i1 %64, label %65, label %57
65: ; preds = %57, %43
%66 = phi i32 [ 0, %43 ], [ %61, %57 ]
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %66)
%68 = call i32 @fclose(i32* %48)
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.11, i64 0, i64 0), i8* %3)
%70 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%72 = call i32 @fprintf(i32* %70, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), i8* %4)
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.18, i64 0, i64 0))
%74 = load i32, i32* @SEEK_SET
%75 = call i32 @fseek(i32* %70, i32 0, i32 %74)
%76 = call signext i8 @getc(i32* %70)
%77 = load i8, i8* @EOF
%78 = icmp eq i8 %76, %77
br i1 %78, label %87, label %79
79: ; preds = %65, %79
%80 = phi i8 [ %84, %79 ], [ %76, %65 ]
%81 = phi i32 [ %83, %79 ], [ 0, %65 ]
%82 = call i32 @putchar(i8 signext %80)
%83 = add nuw nsw i32 %81, 1
%84 = call signext i8 @getc(i32* %70)
%85 = load i8, i8* @EOF
%86 = icmp eq i8 %84, %85
br i1 %86, label %87, label %79
87: ; preds = %79, %65
%88 = phi i32 [ 0, %65 ], [ %83, %79 ]
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %88)
%90 = call i32 @fclose(i32* %70)
br label %93
91: ; preds = %0
%92 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %93
93: ; preds = %91, %87
ret i32 0
}