#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 qword_get(char **, char *, int);
unsigned int strtoul(char *, char **, int /*<<< orphan*/);
int qword_get_uint(char **bpp, unsigned int *anint) {
  char buf[50];
  char *ep;
  unsigned int rv;
  int len = qword_get(bpp, buf, 50);
  if (len < 0)
    return -1;
  if (len == 0)
    return -1;
  rv = strtoul(buf, &ep, 0);
  if (*ep)
    return -1;
  *anint = rv;
  return 0;
}


x86 assembly (clang, -O0):
<qword_get_uint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x32,%edx
call   1030 <qword_get@plt>
mov    %eax,-0x60(%rbp)
cmpl   $0x0,-0x60(%rbp)
jge    115b <qword_get_uint+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <qword_get_uint+0x8c>
cmpl   $0x0,-0x60(%rbp)
jne    1171 <qword_get_uint+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <qword_get_uint+0x8c>
lea    -0x50(%rbp),%rdi
lea    -0x58(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x58(%rbp),%rax
cmpb   $0x0,(%rax)
je     119c <qword_get_uint+0x7c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <qword_get_uint+0x8c>
mov    -0x5c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qword_get_uint>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
lea    0x10(%rsp),%rsi
mov    $0x32,%edx
call   1030 <qword_get@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
jle    1160 <qword_get_uint+0x40>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    1160 <qword_get_uint+0x40>
mov    %eax,(%rbx)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @qword_get_uint(i8** %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca [50 x i8]
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8** %0, i8*** %4
store i32* %1, i32** %5
%10 = load i8**, i8*** %4
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%12 = call i32 @qword_get(i8** %10, i8* %11, i32 50)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %30
16: ; preds = %2
%17 = load i32, i32* %9
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 -1, i32* %3
br label %30
20: ; preds = %16
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%22 = call i32 @strtoul(i8* %21, i8** %7, i32 0)
store i32 %22, i32* %8
%23 = load i8*, i8** %7
%24 = load i8, i8* %23
%25 = icmp ne i8 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %20
store i32 -1, i32* %3
br label %30
27: ; preds = %20
%28 = load i32, i32* %8
%29 = load i32*, i32** %5
store i32 %28, i32* %29
store i32 0, i32* %3
br label %30
30: ; preds = %27, %26, %19, %15
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
define i32 @qword_get_uint(i8** %0, i32* nocapture writeonly %1) {
%3 = alloca [50 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%6 = bitcast i8** %4 to i8*
%7 = call i32 @qword_get(i8** %0, i8* %5, i32 50)
%8 = icmp slt i32 %7, 1
br i1 %8, label %15, label %9
9: ; preds = %2
%10 = call i32 @strtoul(i8* %5, i8** %4, i32 0)
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9
store i32 %10, i32* %1
br label %15
15: ; preds = %9, %2, %14
%16 = phi i32 [ 0, %14 ], [ -1, %2 ], [ -1, %9 ]
ret i32 %16
}