#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 */
scalar_t__ check_syslog_date(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
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 *, char *);
int /*<<< orphan*/ parseSendmailFromBytesLine(char *, int /*<<< orphan*/);
int /*<<< orphan*/ parseSendmailToLine(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ *strstr(char *, char *);
void readSendmailLogFile(char *fn) {
  FILE *fp;
  char buf[1024];
  if ((fp = fopen(fn, "r")) == NULL) {
    fprintf(stderr, "fopen: %s: %s\n", fn, strerror(errno));
    exit(-1);
  }
  while ((fgets(buf, 1024, fp)) != NULL) {
    if ((check_syslog_date(buf, strlen(buf))) > 0) {
      if ((strstr(buf, " from=")) != NULL)
        parseSendmailFromBytesLine(buf, strlen(buf));
      else if ((strstr(buf, " to=")) != NULL)
        parseSendmailToLine(buf, strlen(buf));
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<readSendmailLogFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    122b <readSendmailLogFile+0x7b>
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x41c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x418(%rbp)
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x41c(%rbp),%edi
mov    -0x418(%rbp),%rdx
mov    %rax,%rcx
lea    0xde6(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
jmp    1230 <readSendmailLogFile+0x80>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     131f <readSendmailLogFile+0x16f>
lea    -0x410(%rbp),%rax
mov    %rax,-0x428(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x428(%rbp),%rdi
mov    %eax,%esi
call   10d0 <check_syslog_date@plt>
cmp    $0x0,%rax
jle    131a <readSendmailLogFile+0x16a>
lea    -0x410(%rbp),%rdi
lea    0xd82(%rip),%rsi
call   10c0 <strstr@plt>
cmp    $0x0,%rax
je     12cb <readSendmailLogFile+0x11b>
lea    -0x410(%rbp),%rax
mov    %rax,-0x430(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x430(%rbp),%rdi
mov    %eax,%esi
call   1070 <parseSendmailFromBytesLine@plt>
jmp    1315 <readSendmailLogFile+0x165>
lea    -0x410(%rbp),%rdi
lea    0xd3f(%rip),%rsi
call   10c0 <strstr@plt>
cmp    $0x0,%rax
je     1310 <readSendmailLogFile+0x160>
lea    -0x410(%rbp),%rax
mov    %rax,-0x438(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x438(%rbp),%rdi
mov    %eax,%esi
call   1090 <parseSendmailToLine@plt>
jmp    1315 <readSendmailLogFile+0x165>
jmp    131a <readSendmailLogFile+0x16a>
jmp    1230 <readSendmailLogFile+0x80>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readSendmailLogFile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rbx
lea    0xe37(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1297 <readSendmailLogFile+0xe7>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     127f <readSendmailLogFile+0xcf>
mov    %rsp,%rbx
lea    0xe14(%rip),%r15
lea    0xe14(%rip),%r12
jmp    1234 <readSendmailLogFile+0x84>
cs nopw 0x0(%rax,%rax,1)
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <parseSendmailFromBytesLine@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     127f <readSendmailLogFile+0xcf>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   10d0 <check_syslog_date@plt>
test   %rax,%rax
jle    121f <readSendmailLogFile+0x6f>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10c0 <strstr@plt>
mov    %rbx,%rdi
test   %rax,%rax
jne    1210 <readSendmailLogFile+0x60>
mov    %r12,%rsi
call   10c0 <strstr@plt>
test   %rax,%rax
je     121f <readSendmailLogFile+0x6f>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1090 <parseSendmailToLine@plt>
jmp    121f <readSendmailLogFile+0x6f>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d42(%rip),%rax
mov    (%rax),%ebp
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd4d(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"fopen: %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [7 x i8] c" from=\00"
@.str.3 = [5 x i8] c" to=\00"
define void @readSendmailLogFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [1024 x i8]
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %3
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %2
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %10, i8* %12)
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %1
br label %16
16: ; preds = %47, %15
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%18 = load i32*, i32** %3
%19 = call i32* @fgets(i8* %17, i32 1024, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %48
21: ; preds = %16
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
%25 = call i64 @check_syslog_date(i8* %22, i32 %24)
%26 = icmp sgt i64 %25, 0
br i1 %26, label %27, label %47
27: ; preds = %21
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%29 = call i32* @strstr(i8* %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = call i32 @parseSendmailFromBytesLine(i8* %32, i32 %34)
br label %46
36: ; preds = %27
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%38 = call i32* @strstr(i8* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%39 = icmp ne i32* %38, null
br i1 %39, label %40, label %45
40: ; preds = %36
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%43 = call i32 @strlen(i8* %42)
%44 = call i32 @parseSendmailToLine(i8* %41, i32 %43)
br label %45
45: ; preds = %40, %36
br label %46
46: ; preds = %45, %31
br label %47
47: ; preds = %46, %21
br label %16
48: ; preds = %16
%49 = load i32*, i32** %3
%50 = call i32 @fclose(i32* %49)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"fopen: %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [7 x i8] c" from=\00"
@.str.3 = [5 x i8] c" to=\00"
define void @readSendmailLogFile(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = call i32* @fgets(i8* %3, i32 1024, i32* %4)
%8 = icmp eq i32* %7, null
br i1 %8, label %34, label %15
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %12)
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %6, %31
%16 = call i32 @strlen(i8* %3)
%17 = call i64 @check_syslog_date(i8* %3, i32 %16)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %31
19: ; preds = %15
%20 = call i32* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = call i32 @strlen(i8* %3)
%24 = call i32 @parseSendmailFromBytesLine(i8* %3, i32 %23)
br label %31
25: ; preds = %19
%26 = call i32* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = call i32 @strlen(i8* %3)
%30 = call i32 @parseSendmailToLine(i8* %3, i32 %29)
br label %31
31: ; preds = %22, %28, %25, %15
%32 = call i32* @fgets(i8* %3, i32 1024, i32* %4)
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %15
34: ; preds = %31, %6
%35 = call i32 @fclose(i32* %4)
ret void
}