#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 */
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *f_input;
  char riga[80];
  int conta_righe, x;
  if (argc < 2) {
    fprintf(stderr, "Uso: %s [file]\n", argv[0]);
    exit(1);
  }
  if ((f_input = fopen(argv[1], "r")) == NULL) {
    fprintf(stderr, "Errore nell'apertura del file \"%s\".\n", argv[1]);
    exit(1);
  }
  conta_righe = 0;
  while (fgets(riga, 80, f_input) != NULL) {
    conta_righe++;
  }
  printf("Il file \"%s\" contiene \"%d\" righe.\n", argv[1], conta_righe);
  for (x = 0; x < argc; x++) {
    printf("Argomento argv[%d] = %s\n", x, argv[x]);
  }
  fclose(f_input);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a9 <main+0x49>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe66(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe58(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11f2 <main+0x92>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe2f(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0x74(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x50,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1223 <main+0xc3>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    11f9 <main+0x99>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x74(%rbp),%edx
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    127a <main+0x11a>
mov    -0x78(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x78(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    1243 <main+0xe3>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r14
cmp    $0x1,%edi
jle    1229 <main+0xc9>
mov    %edi,%r15d
mov    0x8(%r14),%rdi
lea    0xe88(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     123e <main+0xde>
mov    %rax,%r13
mov    $0xffffffff,%ebp
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x50,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    11b0 <main+0x50>
mov    0x8(%r14),%rsi
lea    0xe64(%rip),%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
test   %r15d,%r15d
jle    1209 <main+0xa9>
mov    %r15d,%ebx
lea    0xe6f(%rip),%r15
xor    %ebp,%ebp
nopl   (%rax)
mov    (%r14,%rbp,8),%rdx
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11f0 <main+0x90>
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xdc4(%rip),%rsi
jmp    1252 <main+0xf2>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xdc0(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"Uso: %s [file]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [37 x i8] c"Errore nell'apertura del file \22%s\22.\0A\00"
@.str.3 = [35 x i8] c"Il file \22%s\22 contiene \22%d\22 righe.\0A\00"
@.str.4 = [25 x i8] c"Argomento argv[%d] = %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [80 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %6
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %32
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %19
store i32 0, i32* %8
br label %33
33: ; preds = %38, %32
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%35 = load i32*, i32** %6
%36 = call i32* @fgets(i8* %34, i32 80, i32* %35)
%37 = icmp ne i32* %36, null
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %33
41: ; preds = %33
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = load i32, i32* %8
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %44, i32 %45)
store i32 0, i32* %9
br label %47
47: ; preds = %59, %41
%48 = load i32, i32* %9
%49 = load i32, i32* %4
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %62
51: ; preds = %47
%52 = load i32, i32* %9
%53 = load i8**, i8*** %5
%54 = load i32, i32* %9
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %52, i8* %57)
br label %59
59: ; preds = %51
%60 = load i32, i32* %9
%61 = add nsw i32 %60, 1
store i32 %61, i32* %9
br label %47
62: ; preds = %47
%63 = load i32*, i32** %6
%64 = call i32 @fclose(i32* %63)
%65 = load i32, i32* @EXIT_SUCCESS
ret i32 %65
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"Uso: %s [file]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [37 x i8] c"Errore nell'apertura del file \22%s\22.\0A\00"
@.str.3 = [35 x i8] c"Il file \22%s\22 contiene \22%d\22 righe.\0A\00"
@.str.4 = [25 x i8] c"Argomento argv[%d] = %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %12
%19 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %11, %21
%22 = phi i32 [ %25, %21 ], [ 0, %11 ]
%23 = call i32* @fgets(i8* %4, i32 80, i32* %14)
%24 = icmp eq i32* %23, null
%25 = add nuw nsw i32 %22, 1
br i1 %24, label %26, label %21
26: ; preds = %21
%27 = load i8*, i8** %12
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %27, i32 %22)
%29 = icmp sgt i32 %0, 0
br i1 %29, label %30, label %40
30: ; preds = %26
%31 = zext i32 %0 to i64
br label %32
32: ; preds = %30, %32
%33 = phi i64 [ 0, %30 ], [ %38, %32 ]
%34 = getelementptr inbounds i8*, i8** %1, i64 %33
%35 = load i8*, i8** %34
%36 = trunc i64 %33 to i32
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %36, i8* %35)
%38 = add nuw nsw i64 %33, 1
%39 = icmp eq i64 %38, %31
br i1 %39, label %40, label %32
40: ; preds = %32, %26
%41 = call i32 @fclose(i32* %14)
%42 = load i32, i32* @EXIT_SUCCESS
ret i32 %42
}