#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 */
int EBADMSG;
int ERANGE;
int /*<<< orphan*/ strlen(char *);
char *strstr(char *, char *);
unsigned long strtoul(char *, char **, int);
int parse_pm_stats_count(char *src, char *tag) {
  char *pos;
  unsigned long value;
  char *endptr;
  pos = strstr(src, tag);
  if (pos == NULL)
    return -EBADMSG;
  pos += strlen(tag);
  value = strtoul(pos, &endptr, 10);
  if (endptr == pos || *endptr != '\n')
    return -EBADMSG;
  if (value == (~0UL) || value > ((int)(~0U >> 1)))
    return -ERANGE;
  return (int)value;
}


x86 assembly (clang, -O0):
<parse_pm_stats_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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    116f <parse_pm_stats_count+0x3f>
xor    %eax,%eax
mov    0x2e83(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1202 <parse_pm_stats_count+0xd2>
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    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     11bc <parse_pm_stats_count+0x8c>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     11cf <parse_pm_stats_count+0x9f>
xor    %eax,%eax
mov    0x2e23(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1202 <parse_pm_stats_count+0xd2>
cmpq   $0xffffffffffffffff,-0x28(%rbp)
je     11e8 <parse_pm_stats_count+0xb8>
cmpq   $0x7fffffff,-0x28(%rbp)
7f
jbe    11fb <parse_pm_stats_count+0xcb>
xor    %eax,%eax
mov    0x2def(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1202 <parse_pm_stats_count+0xd2>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_pm_stats_count>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1050 <strstr@plt>
test   %rax,%rax
je     1180 <parse_pm_stats_count+0x50>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    (%rsp),%rcx
cmp    %rbx,%rcx
je     1180 <parse_pm_stats_count+0x50>
cmpb   $0xa,(%rcx)
jne    1180 <parse_pm_stats_count+0x50>
test   $0xffffffff80000000,%rax
je     118b <parse_pm_stats_count+0x5b>
mov    0x2e62(%rip),%rcx
jmp    1187 <parse_pm_stats_count+0x57>
mov    0x2e61(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EBADMSG = global i32 0
@ERANGE = global i32 0
define i32 @parse_pm_stats_count(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i8* @strstr(i8* %9, i8* %10)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @EBADMSG
%16 = sub nsw i32 0, %15
store i32 %16, i32* %3
br label %48
17: ; preds = %2
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = load i8*, i8** %6
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8, i8* %20, i64 %21
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = call i64 @strtoul(i8* %23, i8** %8, i32 10)
store i64 %24, i64* %7
%25 = load i8*, i8** %8
%26 = load i8*, i8** %6
%27 = icmp eq i8* %25, %26
br i1 %27, label %33, label %28
28: ; preds = %17
%29 = load i8*, i8** %8
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 10
br i1 %32, label %33, label %36
33: ; preds = %28, %17
%34 = load i32, i32* @EBADMSG
%35 = sub nsw i32 0, %34
store i32 %35, i32* %3
br label %48
36: ; preds = %28
%37 = load i64, i64* %7
%38 = icmp eq i64 %37, -1
br i1 %38, label %42, label %39
39: ; preds = %36
%40 = load i64, i64* %7
%41 = icmp ugt i64 %40, 2147483647
br i1 %41, label %42, label %45
42: ; preds = %39, %36
%43 = load i32, i32* @ERANGE
%44 = sub nsw i32 0, %43
store i32 %44, i32* %3
br label %48
45: ; preds = %39
%46 = load i64, i64* %7
%47 = trunc i64 %46 to i32
store i32 %47, i32* %3
br label %48
48: ; preds = %45, %42, %33, %14
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@EBADMSG = global i32 0
@ERANGE = global i32 0
define i32 @parse_pm_stats_count(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @EBADMSG
%9 = sub nsw i32 0, %8
br label %30
10: ; preds = %2
%11 = tail call i32 @strlen(i8* %1)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %5, i64 %12
%14 = call i64 @strtoul(i8* %13, i8** %3, i32 10)
%15 = load i8*, i8** %3
%16 = icmp eq i8* %15, %13
br i1 %16, label %20, label %17
17: ; preds = %10
%18 = load i8, i8* %15
%19 = icmp eq i8 %18, 10
br i1 %19, label %23, label %20
20: ; preds = %17, %10
%21 = load i32, i32* @EBADMSG
%22 = sub nsw i32 0, %21
br label %30
23: ; preds = %17
%24 = icmp ugt i64 %14, 2147483647
br i1 %24, label %25, label %28
25: ; preds = %23
%26 = load i32, i32* @ERANGE
%27 = sub nsw i32 0, %26
br label %30
28: ; preds = %23
%29 = trunc i64 %14 to i32
br label %30
30: ; preds = %28, %25, %20, %7
%31 = phi i32 [ %9, %7 ], [ %22, %20 ], [ %27, %25 ], [ %29, %28 ]
ret i32 %31
}