#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 */
scalar_t__ isspace(char const);
int /*<<< orphan*/ strlen(char const *);
char *strstr(char const *, char const *);
unsigned int strtoul(char const *, int /*<<< orphan*/ *, int /*<<< orphan*/);
unsigned int read_value(const char *buffer, const char *prefix) {
  buffer = strstr(buffer, prefix);
  if (buffer != NULL) {
    buffer += strlen(prefix);
    while (isspace(*buffer)) {
      buffer++;
    }
    return (*buffer != '\0') ? strtoul(buffer, NULL, 0) : 0;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<read_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e8 <read_value+0xa8>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11ac <read_value+0x6c>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1185 <read_value+0x45>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d3 <read_value+0x93>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
jmp    11dd <read_value+0x9d>
xor    %eax,%eax
mov    %eax,-0x1c(%rbp)
jmp    11dd <read_value+0x9d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ef <read_value+0xaf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_value>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1060 <strstr@plt>
test   %rax,%rax
je     119a <read_value+0x5a>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbx
add    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1040 <isspace@plt>
test   %rax,%rax
jne    1170 <read_value+0x30>
cmpb   $0x0,(%rbx)
je     119a <read_value+0x5a>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <strtoul@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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