#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 */
scalar_t__ errno;
unsigned int strtoul(char const *, char **, int /*<<< orphan*/);
unsigned int read_num_le(const char *str, int *rcp) {
  unsigned int ret;
  char *e;
  if (*rcp)
    return 0;
  errno = 0;
  ret = strtoul(str, &e, 0);
  *rcp = -(errno || *e);
  return (ret);
}


x86 assembly (clang, -O0):
<read_num_le>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
je     1139 <read_num_le+0x29>
movl   $0x0,-0x4(%rbp)
jmp    1197 <read_num_le+0x87>
mov    0x2ea0(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x1,%al
mov    0x2e7e(%rip),%rcx
cmpq   $0x0,(%rcx)
mov    %al,-0x29(%rbp)
jne    117f <read_num_le+0x6f>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
xor    %ecx,%ecx
sub    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_num_le>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
cmpl   $0x0,(%rsi)
jne    114d <read_num_le+0x3d>
mov    %rsi,%rbx
mov    0x2ebb(%rip),%r14
movq   $0x0,(%r14)
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <strtoul@plt>
mov    $0xffffffff,%ecx
cmpq   $0x0,(%r14)
jne    114b <read_num_le+0x3b>
mov    (%rsp),%rcx
xor    %edx,%edx
cmp    (%rcx),%dl
sbb    %ecx,%ecx
mov    %ecx,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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