#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 strtol(char const *, char **, int /*<<< orphan*/);
int _parse_unsigned(char const *string) {
  char *p;
  long l;
  if (string == NULL)
    return -1;
  l = strtol(string, &p, 0);
  if (string[0] == '\0' || *p != '\0')
    return -1;
  return l;
}


x86 assembly (clang, -O0):
<_parse_unsigned>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1133 <_parse_unsigned+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    1179 <_parse_unsigned+0x69>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1166 <_parse_unsigned+0x56>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1172 <_parse_unsigned+0x62>
movl   $0xffffffff,-0x4(%rbp)
jmp    1179 <_parse_unsigned+0x69>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_parse_unsigned>:
push   %rbp
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     113b <_parse_unsigned+0x2b>
mov    %rdi,%rbx
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
cmpb   $0x0,(%rbx)
je     113b <_parse_unsigned+0x2b>
mov    (%rsp),%rcx
xor    %edx,%edx
cmp    (%rcx),%dl
sbb    %ebp,%ebp
or     %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @_parse_unsigned(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %15, label %5
5: ; preds = %1
%6 = call i64 @strtol(i8* %0, i8** %2, i32 0)
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %5
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
%13 = trunc i64 %6 to i32
%14 = select i1 %12, i32 %13, i32 -1
br label %15
15: ; preds = %9, %5, %1
%16 = phi i32 [ -1, %1 ], [ -1, %5 ], [ %14, %9 ]
ret i32 %16
}