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

/* Variables and functions */
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
scalar_t__ log_are_strs_in_line(char const ***, char *);
double log_get_line_timestamp(char *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int /*<<< orphan*/ system(char *);
int log_cnt_matches_after_timestamp(double search_after_timestamp,
                                    double *log_last_timestamp,
                                    const char **find_str_arr[]) {
  FILE *log;
  bool is_popen = true;
  char line[(512)];
  int ret = 0;
  int match_cnt = 0;
  double cur_timestamp = 0.0;
  log = popen("dmesg", "re");
  if (!log) {
    log = popen("/bin/dmesg", "re");
    if (!log) {
      system("dmesg > klog-i2c-test");
      log = fopen("klog-i2c-test", "r");
      is_popen = false;
      if (!log) {
        do {
          if (errno)
            fprintf(stderr,
                    "Error "
                    "#%d "
                    "failed to open kernel log for reading\n"
                    " err#:%d:%s\n",
                    209, errno, strerror(errno));
          else
            fprintf(stderr,
                    "Error "
                    "#%d "
                    "failed to open kernel log for reading\n",
                    209);
        } while (0);
        return errno;
      }
    }
  }
  while (!feof(log)) {
    if (!fgets(line, sizeof(line), log))
      break;
    cur_timestamp = log_get_line_timestamp(line);
    if (cur_timestamp <= search_after_timestamp)
      continue;
    if (log_are_strs_in_line(find_str_arr, line))
      ++match_cnt;
  }
  *log_last_timestamp = cur_timestamp;
  if (is_popen)
    pclose(log);
  else
    fclose(log);
  log = NULL;
  return (ret < 0) ? ret : match_cnt;
}


x86 assembly (clang, -O0):
<log_cnt_matches_after_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
movl   $0x1,-0x2c(%rbp)
movl   $0x0,-0x234(%rbp)
movl   $0x0,-0x238(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x240(%rbp)
ff
lea    0xe13(%rip),%rdi
lea    0xe04(%rip),%rsi
call   10b0 <popen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    130b <log_cnt_matches_after_timestamp+0x15b>
lea    0xdec(%rip),%rdi
lea    0xde2(%rip),%rsi
call   10b0 <popen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1306 <log_cnt_matches_after_timestamp+0x156>
lea    0xdd5(%rip),%rdi
call   1060 <system@plt>
lea    0xdd1(%rip),%rdi
lea    0xdd8(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1301 <log_cnt_matches_after_timestamp+0x151>
jmp    126c <log_cnt_matches_after_timestamp+0xbc>
mov    0x2d65(%rip),%rax
cmpl   $0x0,(%rax)
je     12cf <log_cnt_matches_after_timestamp+0x11f>
mov    0x2d5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x248(%rbp)
mov    0x2d46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x244(%rbp)
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x248(%rbp),%edi
mov    -0x244(%rbp),%ecx
mov    %rax,%r8
lea    0xd68(%rip),%rsi
mov    $0xd1,%edx
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    12eb <log_cnt_matches_after_timestamp+0x13b>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
lea    0xd84(%rip),%rsi
mov    $0xd1,%edx
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    12f0 <log_cnt_matches_after_timestamp+0x140>
mov    0x2ce1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    141b <log_cnt_matches_after_timestamp+0x26b>
jmp    1306 <log_cnt_matches_after_timestamp+0x156>
jmp    130b <log_cnt_matches_after_timestamp+0x15b>
jmp    1310 <log_cnt_matches_after_timestamp+0x160>
mov    -0x28(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    132e <log_cnt_matches_after_timestamp+0x17e>
jmp    13af <log_cnt_matches_after_timestamp+0x1ff>
lea    -0x230(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x200,%esi
call   1080 <fgets@plt>
cmp    $0x0,%eax
jne    1351 <log_cnt_matches_after_timestamp+0x1a1>
jmp    13af <log_cnt_matches_after_timestamp+0x1ff>
lea    -0x230(%rbp),%rdi
call   1030 <log_get_line_timestamp@plt>
movsd  %xmm0,-0x240(%rbp)
ff
movsd  -0x240(%rbp),%xmm1
ff
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1381 <log_cnt_matches_after_timestamp+0x1d1>
jmp    1310 <log_cnt_matches_after_timestamp+0x160>
mov    -0x20(%rbp),%rdi
lea    -0x230(%rbp),%rsi
call   1040 <log_are_strs_in_line@plt>
cmp    $0x0,%rax
je     13aa <log_cnt_matches_after_timestamp+0x1fa>
mov    -0x238(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x238(%rbp)
jmp    1310 <log_cnt_matches_after_timestamp+0x160>
movsd  -0x240(%rbp),%xmm0
ff
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
cmpl   $0x0,-0x2c(%rbp)
je     13d7 <log_cnt_matches_after_timestamp+0x227>
mov    -0x28(%rbp),%rdi
call   1070 <pclose@plt>
jmp    13e0 <log_cnt_matches_after_timestamp+0x230>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x28(%rbp)
cmpl   $0x0,-0x234(%rbp)
jge    1406 <log_cnt_matches_after_timestamp+0x256>
mov    -0x234(%rbp),%eax
mov    %eax,-0x24c(%rbp)
jmp    1412 <log_cnt_matches_after_timestamp+0x262>
mov    -0x238(%rbp),%eax
mov    %eax,-0x24c(%rbp)
mov    -0x24c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_cnt_matches_after_timestamp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
movsd  %xmm0,0x8(%rsp)
lea    0xe34(%rip),%rdi
lea    0xe25(%rip),%rsi
call   10b0 <popen@plt>
xor    %r12d,%r12d
test   %rax,%rax
jne    1204 <log_cnt_matches_after_timestamp+0x54>
lea    0xe14(%rip),%rdi
lea    0xe0a(%rip),%rsi
call   10b0 <popen@plt>
test   %rax,%rax
je     12fc <log_cnt_matches_after_timestamp+0x14c>
mov    %rax,%rbx
xor    %r13d,%r13d
mov    %rbx,%rdi
call   10a0 <feof@plt>
xorpd  %xmm0,%xmm0
test   %eax,%eax
jne    12ce <log_cnt_matches_after_timestamp+0x11e>
lea    0x10(%rsp),%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
xorpd  %xmm0,%xmm0
test   %eax,%eax
je     12ce <log_cnt_matches_after_timestamp+0x11e>
xor    %r12d,%r12d
lea    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
call   1030 <log_get_line_timestamp@plt>
movapd %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
movsd  %xmm1,(%rsp)
ucomisd %xmm1,%xmm0
jb     128f <log_cnt_matches_after_timestamp+0xdf>
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    12c9 <log_cnt_matches_after_timestamp+0x119>
mov    %rbp,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %eax,%eax
jne    1250 <log_cnt_matches_after_timestamp+0xa0>
jmp    12c9 <log_cnt_matches_after_timestamp+0x119>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1040 <log_are_strs_in_line@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%r12d
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    12c9 <log_cnt_matches_after_timestamp+0x119>
mov    %rbp,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %eax,%eax
movsd  (%rsp),%xmm0
jne    1250 <log_cnt_matches_after_timestamp+0xa0>
jmp    12ce <log_cnt_matches_after_timestamp+0x11e>
movsd  (%rsp),%xmm0
movsd  %xmm0,(%r14)
mov    %rbx,%rdi
test   %r13b,%r13b
je     12e2 <log_cnt_matches_after_timestamp+0x132>
call   1050 <fclose@plt>
jmp    12e7 <log_cnt_matches_after_timestamp+0x137>
call   1070 <pclose@plt>
mov    %r12d,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd0b(%rip),%rdi
call   1060 <system@plt>
lea    0xd07(%rip),%rdi
lea    0xd0e(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     132b <log_cnt_matches_after_timestamp+0x17b>
mov    %rax,%rbx
mov    $0x1,%r13b
jmp    120a <log_cnt_matches_after_timestamp+0x5a>
mov    0x2ca6(%rip),%r14
mov    (%r14),%ebp
mov    0x2ca4(%rip),%rax
mov    (%rax),%ebx
test   %ebp,%ebp
je     136b <log_cnt_matches_after_timestamp+0x1bb>
mov    %ebp,%edi
call   10d0 <strerror@plt>
lea    0xcd6(%rip),%rsi
mov    %ebx,%edi
mov    $0xd1,%edx
mov    %ebp,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%r14),%r12d
jmp    12e7 <log_cnt_matches_after_timestamp+0x137>
lea    0xcf1(%rip),%rsi
mov    %ebx,%edi
mov    $0xd1,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%r14),%r12d
jmp    12e7 <log_cnt_matches_after_timestamp+0x137>

LLVM IR (-O0):
@.str = [6 x i8] c"dmesg\00"
@.str.1 = [3 x i8] c"re\00"
@.str.2 = [11 x i8] c"/bin/dmesg\00"
@.str.3 = [22 x i8] c"dmesg > klog-i2c-test\00"
@.str.4 = [14 x i8] c"klog-i2c-test\00"
@.str.5 = [2 x i8] c"r\00"
@errno = global i32 0
@stderr = global i32 0
@.str.6 = [61 x i8] c"Error #%d failed to open kernel log for reading\0A err#:%d:%s\0A\00"
@.str.7 = [49 x i8] c"Error #%d failed to open kernel log for reading\0A\00"
define i32 @log_cnt_matches_after_timestamp(double %0, double* %1, i8*** %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca double*
%7 = alloca i8***
%8 = alloca i32*
%9 = alloca i32
%10 = alloca [512 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
store double %0, double* %5
store double* %1, double** %6
store i8*** %2, i8**** %7
store i32 1, i32* %9
store i32 0, i32* %11
store i32 0, i32* %12
store double 0.000000e+00, double* %13
%14 = call i32* @popen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %8
%15 = load i32*, i32** %8
%16 = icmp ne i32* %15, null
br i1 %16, label %44, label %17
17: ; preds = %3
%18 = call i32* @popen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %8
%19 = load i32*, i32** %8
%20 = icmp ne i32* %19, null
br i1 %20, label %43, label %21
21: ; preds = %17
%22 = call i32 @system(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %23, i32** %8
store i32 0, i32* %9
%24 = load i32*, i32** %8
%25 = icmp ne i32* %24, null
br i1 %25, label %42, label %26
26: ; preds = %21
br label %27
27: ; preds = %26
%28 = load i32, i32* @errno
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.6, i64 0, i64 0), i32 209, i32 %32, i8* %34)
br label %39
36: ; preds = %27
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0), i32 209)
br label %39
39: ; preds = %36, %30
br label %40
40: ; preds = %39
%41 = load i32, i32* @errno
store i32 %41, i32* %4
br label %92
42: ; preds = %21
br label %43
43: ; preds = %42, %17
br label %44
44: ; preds = %43, %3
br label %45
45: ; preds = %71, %62, %44
%46 = load i32*, i32** %8
%47 = call i32 @feof(i32* %46)
%48 = icmp ne i32 %47, 0
%49 = xor i1 %48, true
br i1 %49, label %50, label %72
50: ; preds = %45
%51 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%52 = load i32*, i32** %8
%53 = call i32 @fgets(i8* %51, i32 512, i32* %52)
%54 = icmp ne i32 %53, 0
br i1 %54, label %56, label %55
55: ; preds = %50
br label %72
56: ; preds = %50
%57 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%58 = call double @log_get_line_timestamp(i8* %57)
store double %58, double* %13
%59 = load double, double* %13
%60 = load double, double* %5
%61 = fcmp ole double %59, %60
br i1 %61, label %62, label %63
62: ; preds = %56
br label %45
63: ; preds = %56
%64 = load i8***, i8**** %7
%65 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%66 = call i64 @log_are_strs_in_line(i8*** %64, i8* %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %63
%69 = load i32, i32* %12
%70 = add nsw i32 %69, 1
store i32 %70, i32* %12
br label %71
71: ; preds = %68, %63
br label %45
72: ; preds = %55, %45
%73 = load double, double* %13
%74 = load double*, double** %6
store double %73, double* %74
%75 = load i32, i32* %9
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %72
%78 = load i32*, i32** %8
%79 = call i32 @pclose(i32* %78)
br label %83
80: ; preds = %72
%81 = load i32*, i32** %8
%82 = call i32 @fclose(i32* %81)
br label %83
83: ; preds = %80, %77
store i32* null, i32** %8
%84 = load i32, i32* %11
%85 = icmp slt i32 %84, 0
br i1 %85, label %86, label %88
86: ; preds = %83
%87 = load i32, i32* %11
br label %90
88: ; preds = %83
%89 = load i32, i32* %12
br label %90
90: ; preds = %88, %86
%91 = phi i32 [ %87, %86 ], [ %89, %88 ]
store i32 %91, i32* %4
br label %92
92: ; preds = %90, %40
%93 = load i32, i32* %4
ret i32 %93
}

LLVM IR (-O2):
@.str = [6 x i8] c"dmesg\00"
@.str.1 = [3 x i8] c"re\00"
@.str.2 = [11 x i8] c"/bin/dmesg\00"
@.str.3 = [22 x i8] c"dmesg > klog-i2c-test\00"
@.str.4 = [14 x i8] c"klog-i2c-test\00"
@.str.5 = [2 x i8] c"r\00"
@errno = global i32 0
@stderr = global i32 0
@.str.6 = [61 x i8] c"Error #%d failed to open kernel log for reading\0A err#:%d:%s\0A\00"
@.str.7 = [49 x i8] c"Error #%d failed to open kernel log for reading\0A\00"
define i32 @log_cnt_matches_after_timestamp(double %0, double* nocapture writeonly %1, i8*** %2) {
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @popen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %26
8: ; preds = %3
%9 = tail call i32* @popen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %26
11: ; preds = %8
%12 = tail call i32 @system(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = load i32, i32* @errno
%17 = icmp eq i32 %16, 0
%18 = load i32, i32* @stderr
br i1 %17, label %22, label %19
19: ; preds = %15
%20 = tail call i8* @strerror(i32 %16)
%21 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.6, i64 0, i64 0), i32 209, i32 %16, i8* %20)
br label %24
22: ; preds = %15
%23 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0), i32 209)
br label %24
24: ; preds = %22, %19
%25 = load i32, i32* @errno
br label %62
26: ; preds = %8, %11, %3
%27 = phi i32* [ %6, %3 ], [ %9, %8 ], [ %13, %11 ]
%28 = phi i1 [ false, %3 ], [ false, %8 ], [ true, %11 ]
%29 = call i32 @feof(i32* %27)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %55
31: ; preds = %26
%32 = call i32 @fgets(i8* %5, i32 512, i32* %27)
%33 = icmp eq i32 %32, 0
br i1 %33, label %55, label %37
34: ; preds = %48
%35 = call i32 @fgets(i8* %5, i32 512, i32* %27)
%36 = icmp eq i32 %35, 0
br i1 %36, label %55, label %37
37: ; preds = %31, %34
%38 = phi i32 [ %52, %34 ], [ 0, %31 ]
br label %45
39: ; preds = %45
%40 = call i32 @feof(i32* %27)
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %55
42: ; preds = %39
%43 = call i32 @fgets(i8* %5, i32 512, i32* %27)
%44 = icmp eq i32 %43, 0
br i1 %44, label %55, label %45
45: ; preds = %37, %42
%46 = call double @log_get_line_timestamp(i8* %5)
%47 = fcmp ugt double %46, %0
br i1 %47, label %48, label %39
48: ; preds = %45
%49 = call i64 @log_are_strs_in_line(i8*** %2, i8* %5)
%50 = icmp ne i64 %49, 0
%51 = zext i1 %50 to i32
%52 = add nuw nsw i32 %38, %51
%53 = call i32 @feof(i32* %27)
%54 = icmp eq i32 %53, 0
br i1 %54, label %34, label %55
55: ; preds = %48, %34, %42, %39, %31, %26
%56 = phi i32 [ 0, %26 ], [ 0, %31 ], [ %38, %39 ], [ %38, %42 ], [ %52, %34 ], [ %52, %48 ]
%57 = phi double [ 0.000000e+00, %26 ], [ 0.000000e+00, %31 ], [ %46, %39 ], [ %46, %42 ], [ %46, %34 ], [ %46, %48 ]
store double %57, double* %1
br i1 %28, label %60, label %58
58: ; preds = %55
%59 = call i32 @pclose(i32* %27)
br label %62
60: ; preds = %55
%61 = call i32 @fclose(i32* %27)
br label %62
62: ; preds = %58, %60, %24
%63 = phi i32 [ %25, %24 ], [ %56, %60 ], [ %56, %58 ]
ret i32 %63
}