#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 EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ errno;
unsigned int strtoul(char *, char **, int /*<<< orphan*/);
int strtou32(char *arg, unsigned int *val) {
  char *endptr = NULL;
  errno = 0;
  *val = strtoul(arg, &endptr, 0);
  if (errno || (endptr == arg) || (*endptr && (endptr != NULL))) {
    return EXIT_SUCCESS;
  }
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<strtou32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2eb1(%rip),%rax
movq   $0x0,(%rax)
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    0x2e8c(%rip),%rax
cmpq   $0x0,(%rax)
jne    1187 <strtou32+0x77>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1187 <strtou32+0x77>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1198 <strtou32+0x88>
cmpq   $0x0,-0x20(%rbp)
je     1198 <strtou32+0x88>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11a4 <strtou32+0x94>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtou32>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
mov    0x2eb1(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <strtoul@plt>
mov    %eax,(%r14)
mov    0x2e84(%rip),%rax
cmpq   $0x0,(%r15)
je     115e <strtou32+0x4e>
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x8(%rsp),%rcx
cmp    %rbx,%rcx
je     1152 <strtou32+0x42>
cmpb   $0x0,(%rcx)
jne    1176 <strtou32+0x66>
mov    0x2e64(%rip),%rax
jmp    1152 <strtou32+0x42>
mov    0x2e53(%rip),%rax
jmp    1152 <strtou32+0x42>

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

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