#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 */
unsigned int cpu_to_le32(unsigned int);
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 cpu_to_le32(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     1149 <read_num_le+0x29>
movl   $0x0,-0x4(%rbp)
jmp    11ac <read_num_le+0x8c>
mov    0x2e90(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x1,%al
mov    0x2e6e(%rip),%rcx
cmpq   $0x0,(%rcx)
mov    %al,-0x29(%rbp)
jne    118f <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),%edi
call   1030 <cpu_to_le32@plt>
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
cmpl   $0x0,(%rsi)
je     1133 <read_num_le+0x13>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rsi,%rbx
mov    0x2ea3(%rip),%r14
movq   $0x0,(%r14)
mov    %rsp,%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    $0xffffffff,%ecx
cmpq   $0x0,(%r14)
jne    1163 <read_num_le+0x43>
mov    (%rsp),%rcx
xor    %edx,%edx
cmp    (%rcx),%dl
sbb    %ecx,%ecx
mov    %ecx,(%rbx)
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <cpu_to_le32@plt>

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 %29
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
%28 = call i32 @cpu_to_le32(i32 %27)
store i32 %28, i32* %3
br label %29
29: ; preds = %22, %11
%30 = load i32, i32* %3
ret i32 %30
}

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 %19
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
%18 = tail call i32 @cpu_to_le32(i32 %8)
br label %19
19: ; preds = %2, %16
%20 = phi i32 [ %18, %16 ], [ 0, %2 ]
ret i32 %20
}