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

/* Variables and functions */
char *calculateFileName(int /*<<< orphan*/ *, int, int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int getInitialSeqNumber(int year, int month, int day) {
  int result = 0;
  char *filename = calculateFileName(NULL, year, month, day);
  FILE *messageFile = fopen(filename, "r");
  if (messageFile) {
    char *line = NULL;
    size_t len = 0;
    ssize_t read = 0;
    while ((read = getline(&line, &len, messageFile)) != -1) {
      result++;
    }
    if (line) {
      free(line);
    }
    fclose(messageFile);
  } else {
    char errorMessage[2000];
    sprintf(errorMessage, "... error opening the file: %s - fopen", filename);
    perror(errorMessage);
  }
  free(filename);
  return result;
}


x86 assembly (clang, -O0):
<getInitialSeqNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%edi
call   1050 <calculateFileName@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1224 <getInitialSeqNumber+0xb4>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     1202 <getInitialSeqNumber+0x92>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11d7 <getInitialSeqNumber+0x67>
cmpq   $0x0,-0x28(%rbp)
je     1216 <getInitialSeqNumber+0xa6>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1247 <getInitialSeqNumber+0xd7>
lea    -0x810(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdcc(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x810(%rbp),%rdi
call   1070 <perror@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%eax
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getInitialSeqNumber>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7e0,%rsp
mov    %edx,%ecx
mov    %esi,%edx
mov    %edi,%esi
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <calculateFileName@plt>
mov    %rax,%r14
lea    0xe67(%rip),%rsi
mov    %rax,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1218 <getInitialSeqNumber+0xa8>
mov    %rax,%r15
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    $0xffffffff,%ebx
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%r13
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1080 <getline@plt>
add    $0x1,%ebx
cmp    $0xffffffff,%eax
jne    11d0 <getInitialSeqNumber+0x60>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     11f5 <getInitialSeqNumber+0x85>
call   1030 <free@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x7e0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xde3(%rip),%rsi
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rdx
call   1090 <sprintf@plt>
mov    %r15,%rdi
call   1070 <perror@plt>
jmp    11fd <getInitialSeqNumber+0x8d>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [39 x i8] c"... error opening the file: %s - fopen\00"
define i32 @getInitialSeqNumber(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca [2000 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = call i8* @calculateFileName(i32* null, i32 %14, i32 %15, i32 %16)
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %9
%20 = load i32*, i32** %9
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %39
22: ; preds = %3
store i8* null, i8** %10
store i64 0, i64* %11
store i32 0, i32* %12
br label %23
23: ; preds = %27, %22
%24 = load i32*, i32** %9
%25 = call i32 @getline(i8** %10, i64* %11, i32* %24)
store i32 %25, i32* %12
%26 = icmp ne i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %23
30: ; preds = %23
%31 = load i8*, i8** %10
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i8*, i8** %10
%35 = call i32 @free(i8* %34)
br label %36
36: ; preds = %33, %30
%37 = load i32*, i32** %9
%38 = call i32 @fclose(i32* %37)
br label %45
39: ; preds = %3
%40 = getelementptr inbounds [2000 x i8], [2000 x i8]* %13, i64 0, i64 0
%41 = load i8*, i8** %8
%42 = call i32 @sprintf(i8* %40, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %41)
%43 = getelementptr inbounds [2000 x i8], [2000 x i8]* %13, i64 0, i64 0
%44 = call i32 @perror(i8* %43)
br label %45
45: ; preds = %39, %36
%46 = load i8*, i8** %8
%47 = call i32 @free(i8* %46)
%48 = load i32, i32* %7
ret i32 %48
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [39 x i8] c"... error opening the file: %s - fopen\00"
define i32 @getInitialSeqNumber(i32 %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [2000 x i8]
%7 = tail call i8* @calculateFileName(i32* null, i32 %0, i32 %1, i32 %2)
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %25, label %10
10: ; preds = %3
%11 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%12 = bitcast i64* %5 to i8*
store i64 0, i64* %5
br label %13
13: ; preds = %13, %10
%14 = phi i32 [ 0, %10 ], [ %17, %13 ]
%15 = call i32 @getline(i8** %4, i64* %5, i32* %8)
%16 = icmp eq i32 %15, -1
%17 = add nuw nsw i32 %14, 1
br i1 %16, label %18, label %13
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = icmp eq i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @free(i8* %19)
br label %23
23: ; preds = %21, %18
%24 = call i32 @fclose(i32* %8)
br label %29
25: ; preds = %3
%26 = getelementptr inbounds [2000 x i8], [2000 x i8]* %6, i64 0, i64 0
%27 = call i32 @sprintf(i8* %26, i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%28 = call i32 @perror(i8* %26)
br label %29
29: ; preds = %25, %23
%30 = phi i32 [ %14, %23 ], [ 0, %25 ]
%31 = call i32 @free(i8* %7)
ret i32 %30
}