#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*/ sendMessage(char *);
int /*<<< orphan*/ sperror(char *);
void reSendMessages(int year, int month, int day, int from, int to) {
  int number = 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) {
      number++;
      if (number >= from && number <= to) {
        sendMessage(line);
      }
    }
    if (line) {
      free(line);
    }
    fclose(messageFile);
  } else {
    sperror("reSendMessages():fopen");
  }
  free(filename);
}


x86 assembly (clang, -O0):
<reSendMessages>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%edi
call   1070 <calculateFileName@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1249 <reSendMessages+0xd9>
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1090 <getline@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
je     1227 <reSendMessages+0xb7>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     1222 <reSendMessages+0xb2>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1222 <reSendMessages+0xb2>
mov    -0x30(%rbp),%rdi
call   1060 <sendMessage@plt>
jmp    11db <reSendMessages+0x6b>
cmpq   $0x0,-0x30(%rbp)
je     123b <reSendMessages+0xcb>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1255 <reSendMessages+0xe5>
lea    0xdb2(%rip),%rdi
call   1050 <sperror@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reSendMessages>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%ebp
mov    %ecx,%r15d
mov    %edx,%ecx
mov    %esi,%edx
mov    %edi,%esi
xor    %edi,%edi
call   1070 <calculateFileName@plt>
mov    %rax,%r14
lea    0xe65(%rip),%rsi
mov    %rax,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     123c <reSendMessages+0xcc>
mov    %rax,%rbx
mov    %r14,0x10(%rsp)
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     121f <reSendMessages+0xaf>
mov    $0x1,%r14d
mov    %rsp,%r12
lea    0x8(%rsp),%r13
jmp    1207 <reSendMessages+0x97>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1090 <getline@plt>
add    $0x1,%r14d
cmp    $0xffffffff,%eax
je     121f <reSendMessages+0xaf>
lea    -0x1(%r14),%eax
cmp    %ebp,%eax
jge    11f0 <reSendMessages+0x80>
cmp    %r15d,%r14d
jl     11f0 <reSendMessages+0x80>
mov    (%rsp),%rdi
call   1060 <sendMessage@plt>
jmp    11f0 <reSendMessages+0x80>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     122d <reSendMessages+0xbd>
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x10(%rsp),%r14
jmp    1248 <reSendMessages+0xd8>
lea    0xdbf(%rip),%rdi
call   1050 <sperror@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [23 x i8] c"reSendMessages():fopen\00"
define void @reSendMessages(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = tail call i8* @calculateFileName(i32* null, i32 %0, i32 %1, i32 %2)
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %35, label %11
11: ; preds = %5
%12 = bitcast i8** %6 to i8*
store i8* null, i8** %6
%13 = bitcast i64* %7 to i8*
store i64 0, i64* %7
%14 = call i32 @getline(i8** %6, i64* %7, i32* %9)
%15 = icmp eq i32 %14, -1
br i1 %15, label %28, label %16
16: ; preds = %11, %25
%17 = phi i32 [ %18, %25 ], [ 0, %11 ]
%18 = add nuw nsw i32 %17, 1
%19 = icmp sge i32 %18, %3
%20 = icmp slt i32 %17, %4
%21 = and i1 %20, %19
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i8*, i8** %6
%24 = call i32 @sendMessage(i8* %23)
br label %25
25: ; preds = %22, %16
%26 = call i32 @getline(i8** %6, i64* %7, i32* %9)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %16
28: ; preds = %25, %11
%29 = load i8*, i8** %6
%30 = icmp eq i8* %29, null
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = call i32 @free(i8* %29)
br label %33
33: ; preds = %31, %28
%34 = call i32 @fclose(i32* %9)
br label %37
35: ; preds = %5
%36 = tail call i32 @sperror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %33
%38 = call i32 @free(i8* %8)
ret void
}