#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 /*<<< orphan*/ isspace(char);
size_t strlen(char *);
scalar_t__ strncmp(char *, char *, size_t);
long long strtoll(char *, int /*<<< orphan*/ *, int);
int sysfsparser_linelookup_numeric(char *line, char *pattern,
                                   long long *value) {
  char *p;
  size_t len = strlen(pattern);
  if (!*line || (len + 1 > strlen(line)))
    return 0;
  p = line + len;
  if (strncmp(line, pattern, len) || !isspace(*p))
    return 0;
  *value = strtoll(p, NULL, 10);
  return 1;
}


x86 assembly (clang, -O0):
<sysfsparser_linelookup_numeric>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1193 <sysfsparser_linelookup_numeric+0x53>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jbe    119f <sysfsparser_linelookup_numeric+0x5f>
movl   $0x0,-0x4(%rbp)
jmp    120a <sysfsparser_linelookup_numeric+0xca>
mov    -0x10(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11db <sysfsparser_linelookup_numeric+0x9b>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%eax
jne    11e7 <sysfsparser_linelookup_numeric+0xa7>
movl   $0x0,-0x4(%rbp)
jmp    120a <sysfsparser_linelookup_numeric+0xca>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtoll@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysfsparser_linelookup_numeric>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
xor    %r15d,%r15d
cmpb   $0x0,(%rbx)
je     11b2 <sysfsparser_linelookup_numeric+0x72>
mov    %rax,%r12
lea    0x1(%rax),%r13
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %rax,%r13
ja     11b2 <sysfsparser_linelookup_numeric+0x72>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11b2 <sysfsparser_linelookup_numeric+0x72>
add    %r12,%rbx
movsbl (%rbx),%edi
call   1050 <isspace@plt>
test   %eax,%eax
je     11b2 <sysfsparser_linelookup_numeric+0x72>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtoll@plt>
mov    %rax,(%r14)
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sysfsparser_linelookup_numeric(i8* %0, i8* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64* %2, i64** %7
%10 = load i8*, i8** %6
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %9
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %3
%16 = load i64, i64* %9
%17 = add i64 %16, 1
%18 = load i8*, i8** %5
%19 = call i64 @strlen(i8* %18)
%20 = icmp ugt i64 %17, %19
br i1 %20, label %21, label %22
21: ; preds = %15, %3
store i32 0, i32* %4
br label %41
22: ; preds = %15
%23 = load i8*, i8** %5
%24 = load i64, i64* %9
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8* %25, i8** %8
%26 = load i8*, i8** %5
%27 = load i8*, i8** %6
%28 = load i64, i64* %9
%29 = call i64 @strncmp(i8* %26, i8* %27, i64 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %22
%32 = load i8*, i8** %8
%33 = load i8, i8* %32
%34 = call i32 @isspace(i8 signext %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %31, %22
store i32 0, i32* %4
br label %41
37: ; preds = %31
%38 = load i8*, i8** %8
%39 = call i64 @strtoll(i8* %38, i32* null, i32 10)
%40 = load i64*, i64** %7
store i64 %39, i64* %40
store i32 1, i32* %4
br label %41
41: ; preds = %37, %36, %21
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
define i32 @sysfsparser_linelookup_numeric(i8* %0, i8* %1, i64* nocapture writeonly %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %21, label %7
7: ; preds = %3
%8 = add i64 %4, 1
%9 = tail call i64 @strlen(i8* %0)
%10 = icmp ugt i64 %8, %9
br i1 %10, label %21, label %11
11: ; preds = %7
%12 = getelementptr inbounds i8, i8* %0, i64 %4
%13 = tail call i64 @strncmp(i8* %0, i8* %1, i64 %4)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = load i8, i8* %12
%17 = tail call i32 @isspace(i8 signext %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = tail call i64 @strtoll(i8* nocapture %12, i32* null, i32 10)
store i64 %20, i64* %2
br label %21
21: ; preds = %11, %15, %3, %7, %19
%22 = phi i32 [ 1, %19 ], [ 0, %7 ], [ 0, %3 ], [ 0, %15 ], [ 0, %11 ]
ret i32 %22
}