#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 EINVAL;
unsigned int strtoul(char *, char **, int /*<<< orphan*/);
int parse_opt_uint(char *param, void *arg) {
  char *tail;
  if (param == NULL || param[0] == '\0')
    return -EINVAL;
  *(unsigned int *)arg = strtoul(param, &tail, 0);
  if (tail[0] != '\0')
    return -EINVAL;
  return 0;
}


x86 assembly (clang, -O0):
<parse_opt_uint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     113b <parse_opt_uint+0x2b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    114e <parse_opt_uint+0x3e>
xor    %eax,%eax
mov    0x2e9c(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    118f <parse_opt_uint+0x7f>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoul@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1188 <parse_opt_uint+0x78>
xor    %eax,%eax
mov    0x2e62(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    118f <parse_opt_uint+0x7f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_opt_uint>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1139 <parse_opt_uint+0x29>
cmpb   $0x0,(%rdi)
je     1139 <parse_opt_uint+0x29>
mov    %rsi,%r14
mov    %rsp,%rsi
xor    %ebx,%ebx
xor    %edx,%edx
call   1030 <strtoul@plt>
mov    %eax,(%r14)
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     1144 <parse_opt_uint+0x34>
mov    0x2ea0(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@EINVAL = global i32 0
define i32 @parse_opt_uint(i8* %0, i8* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp eq i8* %0, null
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6, %2
%10 = load i32, i32* @EINVAL
%11 = sub nsw i32 0, %10
br label %21
12: ; preds = %6
%13 = call i32 @strtoul(i8* %0, i8** %3, i32 0)
%14 = bitcast i8* %1 to i32*
store i32 %13, i32* %14
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %12
%19 = load i32, i32* @EINVAL
%20 = sub nsw i32 0, %19
br label %21
21: ; preds = %12, %18, %9
%22 = phi i32 [ %11, %9 ], [ %20, %18 ], [ 0, %12 ]
ret i32 %22
}