#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_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fptr;
  int numLine = 0;
  char oneLine[81];
  if (argc < 2) {
    printf("Need to provide the file's name.\n");
    return EXIT_FAILURE;
  }
  fptr = fopen(argv[1], "r");
  if (fptr == NULL) {
    printf("fopen fail.\n");
    return EXIT_FAILURE;
  }
  printf("The name of the file is %s.\n", argv[1]);
  while (fgets(oneLine, 81, fptr) != NULL) {
    numLine++;
  }
  fclose(fptr);
  printf("The file has %d lines.\n", numLine);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1186 <main+0x46>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    122e <main+0xee>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c8 <main+0x88>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    122e <main+0xee>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x51,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1208 <main+0xc8>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11de <main+0x9e>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%esi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
cmp    $0x1,%edi
jg     1166 <main+0x16>
lea    0xedf(%rip),%rdi
jmp    11e0 <main+0x90>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe8c(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d9 <main+0x89>
mov    %rax,%rbx
mov    0x8(%rbp),%rsi
lea    0xe76(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%ebp
mov    %rsp,%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x51,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    11a0 <main+0x50>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe58(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e01(%rip),%rax
jmp    11ec <main+0x9c>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Need to provide the file's name.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"fopen fail.\0A\00"
@.str.3 = [29 x i8] c"The name of the file is %s.\0A\00"
@.str.4 = [24 x i8] c"The file has %d lines.\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 i32
%8 = alloca [81 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %3
br label %43
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
store i32 %23, i32* %3
br label %43
24: ; preds = %14
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %34, %24
%30 = getelementptr inbounds [81 x i8], [81 x i8]* %8, i64 0, i64 0
%31 = load i32*, i32** %6
%32 = call i32* @fgets(i8* %30, i32 81, i32* %31)
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %29
37: ; preds = %29
%38 = load i32*, i32** %6
%39 = call i32 @fclose(i32* %38)
%40 = load i32, i32* %7
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %40)
%42 = load i32, i32* @EXIT_SUCCESS
store i32 %42, i32* %3
br label %43
43: ; preds = %37, %21, %11
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [29 x i8] c"The name of the file is %s.\0A\00"
@.str.4 = [24 x i8] c"The file has %d lines.\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [12 x i8] c"fopen fail.\00"
@str.5 = [33 x i8] c"Need to provide the file's name.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [81 x i8]
%4 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.5, i64 0, i64 0))
br label %26
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %26
15: ; preds = %8
%16 = load i8*, i8** %9
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %18, %15
%19 = phi i32 [ 0, %15 ], [ %22, %18 ]
%20 = call i32* @fgets(i8* %4, i32 81, i32* %11)
%21 = icmp eq i32* %20, null
%22 = add nuw nsw i32 %19, 1
br i1 %21, label %23, label %18
23: ; preds = %18
%24 = call i32 @fclose(i32* %11)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %19)
br label %26
26: ; preds = %23, %13, %6
%27 = phi i32* [ @EXIT_FAILURE, %6 ], [ @EXIT_FAILURE, %13 ], [ @EXIT_SUCCESS, %23 ]
%28 = load i32, i32* %27
ret i32 %28
}