#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *, int *, int *,
                          int *, int *, char *);
scalar_t__ malloc(int const);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, char *, char *, char *, int);
char *strstr(char *, char *);
int readlog(char logname[]) {
  FILE *log;
  int c;
  if ((log = fopen(logname, "r")) == NULL) {
    perror("\nError when opening logfile");
    return 0;
  } else {
    const int max_process_string_size = 60;
    const int max_message_string_size = 600;
    char month[4];
    int day;
    int time[3] = {0, 0, 0};
    char *process_name = (char *)malloc(max_process_string_size * sizeof(char));
    char *message = (char *)malloc(max_message_string_size * sizeof(char));
    int done = 0;
    for (c = 0; c < max_message_string_size; c++) {
      message[c] = 0;
    }
    for (c = 0; c < max_process_string_size; c++) {
      process_name[c] = 0;
    }
    do {
      int ch;
      char *temp;
      int row_has_ended = 0;
      int i = 0;
      fscanf(log, "%s %d %d:%d:%d %s", month, &day, &time[0], &time[1],
             &time[2], process_name);
      do {
        ch = fgetc(log);
        message[i] = (char)ch;
        i++;
        if (ch == '\n') {
          row_has_ended = 1;
        }
        if (ch == EOF) {
          row_has_ended = 1;
          done = 1;
        }
      } while (!row_has_ended);
      if ((temp = strstr(message, "fail")) != NULL) {
        int seconds = time[2] + time[1] * 60 + time[0] * 60 * 60;
        message[i] = '\0';
        printf("%d %s: %s %s; %d seconds from midnight \n", day, month,
               process_name, message, seconds);
      }
    } while (!done);
    free(process_name);
    free(message);
    fclose(log);
    return 1;
  }
}


x86 assembly (clang, -O0):
<readlog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11e5 <readlog+0x45>
lea    0xe2e(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    13cd <readlog+0x22d>
movl   $0x3c,-0x20(%rbp)
movl   $0x258,-0x24(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    $0x3c,%edi
call   1090 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    $0x258,%edi
call   1090 <malloc@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x258,-0x1c(%rbp)
jge    1254 <readlog+0xb4>
mov    -0x48(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    122d <readlog+0x8d>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3c,-0x1c(%rbp)
jge    127f <readlog+0xdf>
mov    -0x40(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    125b <readlog+0xbb>
jmp    1284 <readlog+0xe4>
movl   $0x0,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rdx
lea    -0x38(%rbp),%r8
lea    -0x38(%rbp),%r9
add    $0x4,%r9
lea    -0x38(%rbp),%r10
add    $0x8,%r10
mov    -0x40(%rbp),%rax
lea    0xd65(%rip),%rsi
lea    -0x2c(%rbp),%rcx
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1070 <fscanf@plt>
mov    -0x18(%rbp),%rdi
call   1080 <fgetc@plt>
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%eax
mov    %al,%dl
mov    -0x48(%rbp),%rax
movslq -0x60(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
cmpl   $0xa,-0x50(%rbp)
jne    1301 <readlog+0x161>
movl   $0x1,-0x5c(%rbp)
mov    -0x50(%rbp),%eax
mov    0x2cdd(%rip),%rcx
cmp    (%rcx),%eax
jne    1321 <readlog+0x181>
movl   $0x1,-0x5c(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1326 <readlog+0x186>
cmpl   $0x0,-0x5c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12cb <readlog+0x12b>
mov    -0x48(%rbp),%rdi
lea    0xcee(%rip),%rsi
call   10c0 <strstr@plt>
mov    %rax,-0x58(%rbp)
cmp    $0x0,%rax
je     1395 <readlog+0x1f5>
mov    -0x30(%rbp),%eax
imul   $0x3c,-0x34(%rbp),%ecx
add    %ecx,%eax
imul   $0x3c,-0x38(%rbp),%ecx
imul   $0x3c,%ecx,%ecx
add    %ecx,%eax
mov    %eax,-0x64(%rbp)
mov    -0x48(%rbp),%rax
movslq -0x60(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x2c(%rbp),%esi
lea    -0x28(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    -0x64(%rbp),%r9d
lea    0xca5(%rip),%rdi
call   1050 <printf@plt>
jmp    139a <readlog+0x1fa>
cmpl   $0x0,-0x4c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1284 <readlog+0xe4>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readlog>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe4b(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1313 <readlog+0x173>
mov    %rax,%r15
movl   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    $0x3c,%edi
call   1090 <malloc@plt>
mov    %rax,%rbp
mov    $0x258,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    $0x258,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
xorps  %xmm0,%xmm0
movups %xmm0,0x0(%rbp)
movups %xmm0,0x10(%rbp)
movups %xmm0,0x20(%rbp)
mov    %rbp,0x18(%rsp)
movups %xmm0,0x2c(%rbp)
mov    0x2dc9(%rip),%r13
mov    $0x1,%r12d
jmp    1238 <readlog+0x98>
nopw   0x0(%rax,%rax,1)
test   %ebp,%ebp
jne    12e5 <readlog+0x145>
mov    %r15,%rdi
lea    0xddc(%rip),%rsi
lea    0x24(%rsp),%rdx
lea    0x20(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
push   0x18(%rsp)
lea    0x18(%rsp),%rax
push   %rax
call   1070 <fscanf@plt>
add    $0x10,%rsp
xor    %r14d,%r14d
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %r15,%rdi
call   1080 <fgetc@plt>
mov    %al,(%rbx,%r14,1)
add    $0x1,%r14
mov    0x0(%r13),%ecx
cmp    %ecx,%eax
cmove  %r12d,%ebp
cmp    $0xa,%eax
je     1293 <readlog+0xf3>
cmp    %ecx,%eax
jne    1270 <readlog+0xd0>
mov    %rbx,%rdi
lea    0xd93(%rip),%rsi
call   10c0 <strstr@plt>
test   %rax,%rax
je     1230 <readlog+0x90>
imul   $0x3c,0xc(%rsp),%eax
add    0x10(%rsp),%eax
imul   $0xe10,0x8(%rsp),%r9d
add    %eax,%r9d
mov    %r14d,%eax
movb   $0x0,(%rbx,%rax,1)
mov    0x20(%rsp),%esi
lea    0xd67(%rip),%rdi
lea    0x24(%rsp),%rdx
mov    0x18(%rsp),%rcx
mov    %rbx,%r8
call   1050 <printf@plt>
jmp    1230 <readlog+0x90>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xce8(%rip),%rdi
call   10b0 <perror@plt>
xor    %eax,%eax
jmp    1304 <readlog+0x164>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [28 x i8] c"\0AError when opening logfile\00"
@.str.2 = [18 x i8] c"%s %d %d:%d:%d %s\00"
@EOF = global i32 0
@.str.3 = [5 x i8] c"fail\00"
@.str.4 = [41 x i8] c"%d %s: %s %s; %d seconds from midnight \0A\00"
define i32 @readlog(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4 x i8]
%9 = alloca i32
%10 = alloca [3 x i32]
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i8* %0, i8** %3
%19 = load i8*, i8** %3
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %4
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %1
%23 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %124
24: ; preds = %1
store i32 60, i32* %6
store i32 600, i32* %7
%25 = bitcast [3 x i32]* %10 to i8*
%26 = call i64 @malloc(i32 60)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %11
%28 = call i64 @malloc(i32 600)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %12
store i32 0, i32* %13
store i32 0, i32* %5
br label %30
30: ; preds = %38, %24
%31 = load i32, i32* %5
%32 = icmp slt i32 %31, 600
br i1 %32, label %33, label %41
33: ; preds = %30
%34 = load i8*, i8** %12
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 0, i8* %37
br label %38
38: ; preds = %33
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 1
store i32 %40, i32* %5
br label %30
41: ; preds = %30
store i32 0, i32* %5
br label %42
42: ; preds = %50, %41
%43 = load i32, i32* %5
%44 = icmp slt i32 %43, 60
br i1 %44, label %45, label %53
45: ; preds = %42
%46 = load i8*, i8** %11
%47 = load i32, i32* %5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 0, i8* %49
br label %50
50: ; preds = %45
%51 = load i32, i32* %5
%52 = add nsw i32 %51, 1
store i32 %52, i32* %5
br label %42
53: ; preds = %42
br label %54
54: ; preds = %113, %53
store i32 0, i32* %16
store i32 0, i32* %17
%55 = load i32*, i32** %4
%56 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%57 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 0
%58 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 1
%59 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 2
%60 = load i8*, i8** %11
%61 = call i32 @fscanf(i32* %55, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %56, i32* %9, i32* %57, i32* %58, i32* %59, i8* %60)
br label %62
62: ; preds = %82, %54
%63 = load i32*, i32** %4
%64 = call i32 @fgetc(i32* %63)
store i32 %64, i32* %14
%65 = load i32, i32* %14
%66 = trunc i32 %65 to i8
%67 = load i8*, i8** %12
%68 = load i32, i32* %17
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %67, i64 %69
store i8 %66, i8* %70
%71 = load i32, i32* %17
%72 = add nsw i32 %71, 1
store i32 %72, i32* %17
%73 = load i32, i32* %14
%74 = icmp eq i32 %73, 10
br i1 %74, label %75, label %76
75: ; preds = %62
store i32 1, i32* %16
br label %76
76: ; preds = %75, %62
%77 = load i32, i32* %14
%78 = load i32, i32* @EOF
%79 = icmp eq i32 %77, %78
br i1 %79, label %80, label %81
80: ; preds = %76
store i32 1, i32* %16
store i32 1, i32* %13
br label %81
81: ; preds = %80, %76
br label %82
82: ; preds = %81
%83 = load i32, i32* %16
%84 = icmp ne i32 %83, 0
%85 = xor i1 %84, true
br i1 %85, label %62, label %86
86: ; preds = %82
%87 = load i8*, i8** %12
%88 = call i8* @strstr(i8* %87, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* %88, i8** %15
%89 = icmp ne i8* %88, null
br i1 %89, label %90, label %112
90: ; preds = %86
%91 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 2
%92 = load i32, i32* %91
%93 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 1
%94 = load i32, i32* %93
%95 = mul nsw i32 %94, 60
%96 = add nsw i32 %92, %95
%97 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 0
%98 = load i32, i32* %97
%99 = mul nsw i32 %98, 60
%100 = mul nsw i32 %99, 60
%101 = add nsw i32 %96, %100
store i32 %101, i32* %18
%102 = load i8*, i8** %12
%103 = load i32, i32* %17
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds i8, i8* %102, i64 %104
store i8 0, i8* %105
%106 = load i32, i32* %9
%107 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%108 = load i8*, i8** %11
%109 = load i8*, i8** %12
%110 = load i32, i32* %18
%111 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %106, i8* %107, i8* %108, i8* %109, i32 %110)
br label %112
112: ; preds = %90, %86
br label %113
113: ; preds = %112
%114 = load i32, i32* %13
%115 = icmp ne i32 %114, 0
%116 = xor i1 %115, true
br i1 %116, label %54, label %117
117: ; preds = %113
%118 = load i8*, i8** %11
%119 = call i32 @free(i8* %118)
%120 = load i8*, i8** %12
%121 = call i32 @free(i8* %120)
%122 = load i32*, i32** %4
%123 = call i32 @fclose(i32* %122)
store i32 1, i32* %2
br label %124
124: ; preds = %117, %22
%125 = load i32, i32* %2
ret i32 %125
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [28 x i8] c"\0AError when opening logfile\00"
@.str.2 = [18 x i8] c"%s %d %d:%d:%d %s\00"
@EOF = global i32 0
@.str.3 = [5 x i8] c"fail\00"
@.str.4 = [41 x i8] c"%d %s: %s %s; %d seconds from midnight \0A\00"
define i32 @readlog(i8* nocapture %0) {
%2 = alloca [4 x i8]
%3 = alloca i32
%4 = alloca [3 x i32]
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %55
9: ; preds = %1
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%11 = bitcast i32* %3 to i8*
%12 = bitcast [3 x i32]* %4 to i8*
%13 = tail call i64 @malloc(i32 60)
%14 = tail call i64 @malloc(i32 600)
%15 = inttoptr i64 %14 to i8*
%16 = inttoptr i64 %13 to i8*
%17 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
%18 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 1
%19 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 2
br label %20
20: ; preds = %9, %49
%21 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %10, i32* %3, i32* %17, i32* %18, i32* %19, i8* %16)
br label %22
22: ; preds = %22, %20
%23 = phi i64 [ %28, %22 ], [ 0, %20 ]
%24 = phi i32 [ %32, %22 ], [ 0, %20 ]
%25 = call i32 @fgetc(i32* %5)
%26 = trunc i32 %25 to i8
%27 = getelementptr inbounds i8, i8* %15, i64 %23
store i8 %26, i8* %27
%28 = add nuw i64 %23, 1
%29 = icmp eq i32 %25, 10
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %25, %30
%32 = select i1 %31, i32 1, i32 %24
%33 = or i1 %29, %31
br i1 %33, label %34, label %22
34: ; preds = %22
%35 = call i8* @strstr(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%36 = icmp eq i8* %35, null
br i1 %36, label %49, label %37
37: ; preds = %34
%38 = load i32, i32* %19
%39 = load i32, i32* %18
%40 = mul nsw i32 %39, 60
%41 = add nsw i32 %40, %38
%42 = load i32, i32* %17
%43 = mul i32 %42, 3600
%44 = add nsw i32 %41, %43
%45 = and i64 %28, 4294967295
%46 = getelementptr inbounds i8, i8* %15, i64 %45
store i8 0, i8* %46
%47 = load i32, i32* %3
%48 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %47, i8* %10, i8* %16, i8* %15, i32 %44)
br label %49
49: ; preds = %37, %34
%50 = icmp eq i32 %32, 0
br i1 %50, label %20, label %51
51: ; preds = %49
%52 = call i32 @free(i8* %16)
%53 = call i32 @free(i8* %15)
%54 = call i32 @fclose(i32* %5)
br label %55
55: ; preds = %51, %7
%56 = phi i32 [ 0, %7 ], [ 1, %51 ]
ret i32 %56
}