#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);
char *strchr(char const *, char);
scalar_t__ strtoul(char const *, char **, int);
int get_str_value(const char *str, unsigned *val) {
  char *endptr = NULL;
  const char *s = strchr(str, ':');
  ;
  ;
  if (s == NULL)
    return -1;
  *val = (unsigned)strtoul(s + 1, &endptr, 10);
  if (endptr != NULL && *endptr != '\0' && !isspace(*endptr))
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<get_str_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1171 <get_str_value+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <get_str_value+0xa2>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     11cb <get_str_value+0x9b>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11cb <get_str_value+0x9b>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
jne    11cb <get_str_value+0x9b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <get_str_value+0xa2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_str_value>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
movq   $0x0,(%rsp)
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     1187 <get_str_value+0x57>
add    $0x1,%rax
mov    %rsp,%rsi
mov    %rax,%rdi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %eax,(%r14)
mov    (%rsp),%rax
test   %rax,%rax
je     1185 <get_str_value+0x55>
mov    (%rax),%al
test   %al,%al
je     1185 <get_str_value+0x55>
movsbl %al,%edi
call   1040 <isspace@plt>
test   %eax,%eax
je     1187 <get_str_value+0x57>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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