#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*/ time_t;
typedef int /*<<< orphan*/ t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  char *path = argv[1];
  if (path == NULL) {
    printf("File not specified\n");
    exit(1);
  }
  char buffer[1024];
  FILE *file = fopen(path, "r");
  char t[20];
  time_t timeval;
  timeval = time(NULL);
  snprintf(t, sizeof(t), "%.24s", ctime(&timeval));
  if (file == NULL)
    perror("Error opening file");
  else {
    int count = 0;
    while (feof(file) == 0) {
      fgets(buffer, 1024, file);
      printf("%s", buffer);
      count++;
    }
    printf("\n\nfile: %s (%d lines) - %s\n", path, count, t);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d8 <main+0x48>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x428(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0x444(%rbp)
lea    -0x440(%rbp),%rax
mov    %rax,-0x450(%rbp)
lea    -0x444(%rbp),%rdi
call   1030 <ctime@plt>
mov    -0x450(%rbp),%rdi
mov    %rax,%rcx
mov    $0x14,%esi
lea    0xde8(%rip),%rdx
call   1050 <snprintf@plt>
cmpq   $0x0,-0x428(%rbp)
jne    1252 <main+0xc2>
lea    0xdd4(%rip),%rdi
call   10a0 <perror@plt>
jmp    12d2 <main+0x142>
movl   $0x0,-0x448(%rbp)
mov    -0x428(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
jne    12b3 <main+0x123>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
lea    -0x420(%rbp),%rsi
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x448(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x448(%rbp)
jmp    125c <main+0xcc>
mov    -0x18(%rbp),%rsi
mov    -0x448(%rbp),%edx
lea    -0x440(%rbp),%rcx
lea    0xd67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x430,%rsp
mov    0x8(%rsi),%r14
test   %r14,%r14
je     1286 <main+0xe6>
lea    0xe3c(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r15
xor    %ebx,%ebx
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <ctime@plt>
lea    0xe15(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x14,%esi
mov    %rax,%rcx
call   1060 <snprintf@plt>
test   %r15,%r15
je     1278 <main+0xd8>
mov    %r15,%rdi
call   1080 <feof@plt>
test   %rax,%rax
jne    124d <main+0xad>
lea    0x30(%rsp),%r12
lea    0xdfe(%rip),%r13
xor    %ebx,%ebx
nop
mov    %r12,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebx
mov    %r15,%rdi
call   1080 <feof@plt>
test   %rax,%rax
je     1220 <main+0x80>
lea    0xdca(%rip),%rdi
lea    0x10(%rsp),%rcx
mov    %r14,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xd89(%rip),%rdi
call   10b0 <perror@plt>
jmp    1265 <main+0xc5>
lea    0xdad(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"File not specified\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%.24s\00"
@.str.3 = [19 x i8] c"Error opening file\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [28 x i8] c"\0A\0Afile: %s (%d lines) - %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [1024 x i8]
%8 = alloca i32*
%9 = alloca [20 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8*, i8** %6
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %8
%23 = call i32 @time(i32* null)
store i32 %23, i32* %10
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%25 = call i8* @ctime(i32* %10)
%26 = call i32 @snprintf(i8* %24, i32 20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = load i32*, i32** %8
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %31
29: ; preds = %20
%30 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %49
31: ; preds = %20
store i32 0, i32* %11
br label %32
32: ; preds = %36, %31
%33 = load i32*, i32** %8
%34 = call i64 @feof(i32* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %44
36: ; preds = %32
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%38 = load i32*, i32** %8
%39 = call i32 @fgets(i8* %37, i32 1024, i32* %38)
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %40)
%42 = load i32, i32* %11
%43 = add nsw i32 %42, 1
store i32 %43, i32* %11
br label %32
44: ; preds = %32
%45 = load i8*, i8** %6
%46 = load i32, i32* %11
%47 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %45, i32 %46, i8* %47)
br label %49
49: ; preds = %44, %29
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%.24s\00"
@.str.3 = [19 x i8] c"Error opening file\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [28 x i8] c"\0A\0Afile: %s (%d lines) - %s\0A\00"
@str = [19 x i8] c"File not specified\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [20 x i8]
%5 = alloca i32
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%14 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%16 = bitcast i32* %5 to i8*
%17 = tail call i32 @time(i32* null)
store i32 %17, i32* %5
%18 = call i8* @ctime(i32* %5)
%19 = call i32 @snprintf(i8* %15, i32 20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = icmp eq i32* %14, null
br i1 %20, label %24, label %21
21: ; preds = %12
%22 = call i64 @feof(i32* %14)
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %33
24: ; preds = %12
%25 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %36
26: ; preds = %21, %26
%27 = phi i32 [ %30, %26 ], [ 0, %21 ]
%28 = call i32 @fgets(i8* %13, i32 1024, i32* %14)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %13)
%30 = add nuw nsw i32 %27, 1
%31 = call i64 @feof(i32* %14)
%32 = icmp eq i64 %31, 0
br i1 %32, label %26, label %33
33: ; preds = %26, %21
%34 = phi i32 [ 0, %21 ], [ %30, %26 ]
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %7, i32 %34, i8* %15)
br label %36
36: ; preds = %33, %24
ret i32 0
}