#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 */

/* Variables and functions */
long long EBADMSG;
int EOF;
int sscanf(char *, char *, int *, int *, int *, long long *);
int /*<<< orphan*/ strlen(char *);
char *strstr(char *, char *);
signed long long parse_wakelock_stats_for_active_wl(char *src, char *wl_name) {
  char *pos;
  int value;
  char *endptr;
  int lock_count, expire_count, wakeup_count;
  signed long long active_time;
  pos = strstr(src, wl_name);
  if (pos == NULL)
    return -EBADMSG;
  pos += strlen(wl_name);
  value = sscanf(pos, "\t%d\t%d\t%d\t%lld", &lock_count, &expire_count,
                 &wakeup_count, &active_time);
  if ((value == EOF) || (value < 4))
    return -EBADMSG;
  return active_time;
}


x86 assembly (clang, -O0):
<parse_wakelock_stats_for_active_wl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1171 <parse_wakelock_stats_for_active_wl+0x41>
xor    %eax,%eax
mov    0x2e83(%rip),%rcx
sub    (%rcx),%rax
mov    %rax,-0x8(%rbp)
jmp    11e6 <parse_wakelock_stats_for_active_wl+0xb6>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe6b(%rip),%rsi
lea    -0x34(%rbp),%rdx
lea    -0x38(%rbp),%rcx
lea    -0x3c(%rbp),%r8
lea    -0x48(%rbp),%r9
call   1040 <sscanf@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e29(%rip),%rcx
cmp    (%rcx),%eax
je     11c9 <parse_wakelock_stats_for_active_wl+0x99>
cmpl   $0x4,-0x24(%rbp)
jge    11de <parse_wakelock_stats_for_active_wl+0xae>
xor    %eax,%eax
mov    0x2e16(%rip),%rcx
sub    (%rcx),%rax
mov    %rax,-0x8(%rbp)
jmp    11e6 <parse_wakelock_stats_for_active_wl+0xb6>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_wakelock_stats_for_active_wl>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
call   1050 <strstr@plt>
test   %rax,%rax
je     118b <parse_wakelock_stats_for_active_wl+0x5b>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbx
lea    0xea5(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %rsp,%r9
mov    %rbx,%rdi
call   1040 <sscanf@plt>
cmp    $0x4,%eax
jl     118b <parse_wakelock_stats_for_active_wl+0x5b>
mov    0x2e5f(%rip),%rcx
cmp    (%rcx),%eax
je     118b <parse_wakelock_stats_for_active_wl+0x5b>
mov    (%rsp),%rax
jmp    1197 <parse_wakelock_stats_for_active_wl+0x67>
mov    0x2e56(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EBADMSG = global i64 0
@.str = [15 x i8] c"\09%d\09%d\09%d\09%lld\00"
@EOF = global i32 0
define i64 @parse_wakelock_stats_for_active_wl(i8* %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%13 = load i8*, i8** %4
%14 = load i8*, i8** %5
%15 = call i8* @strstr(i8* %13, i8* %14)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i64, i64* @EBADMSG
%20 = sub nsw i64 0, %19
store i64 %20, i64* %3
br label %40
21: ; preds = %2
%22 = load i8*, i8** %5
%23 = call i32 @strlen(i8* %22)
%24 = load i8*, i8** %6
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8* %26, i8** %6
%27 = load i8*, i8** %6
%28 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32* %9, i32* %10, i32* %11, i64* %12)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %29, %30
br i1 %31, label %35, label %32
32: ; preds = %21
%33 = load i32, i32* %7
%34 = icmp slt i32 %33, 4
br i1 %34, label %35, label %38
35: ; preds = %32, %21
%36 = load i64, i64* @EBADMSG
%37 = sub nsw i64 0, %36
store i64 %37, i64* %3
br label %40
38: ; preds = %32
%39 = load i64, i64* %12
store i64 %39, i64* %3
br label %40
40: ; preds = %38, %35, %18
%41 = load i64, i64* %3
ret i64 %41
}

LLVM IR (-O2):
@EBADMSG = global i64 0
@.str = [15 x i8] c"\09%d\09%d\09%d\09%lld\00"
@EOF = global i32 0
define i64 @parse_wakelock_stats_for_active_wl(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i64* %6 to i8*
%11 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i64, i64* @EBADMSG
%15 = sub nsw i64 0, %14
br label %30
16: ; preds = %2
%17 = tail call i32 @strlen(i8* %1)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %11, i64 %18
%20 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4, i32* %5, i64* %6)
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
%23 = icmp slt i32 %20, 4
%24 = or i1 %23, %22
br i1 %24, label %25, label %28
25: ; preds = %16
%26 = load i64, i64* @EBADMSG
%27 = sub nsw i64 0, %26
br label %30
28: ; preds = %16
%29 = load i64, i64* %6
br label %30
30: ; preds = %28, %25, %13
%31 = phi i64 [ %15, %13 ], [ %27, %25 ], [ %29, %28 ]
ret i64 %31
}