#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 */
long INT_MAX;
long strtol(char const *, char **, int /*<<< orphan*/);
int parse_nat(const char *string) {
  long l;
  char *end;
  l = strtol(string, &end, 0);
  while (*end == ' ' || *end == '\t')
    end++;
  if (*end != '\0')
    return -1;
  if (l < 0 || l > INT_MAX)
    return -1;
  return (int)l;
}


x86 assembly (clang, -O0):
<parse_nat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x21(%rbp)
je     1154 <parse_nat+0x44>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1164 <parse_nat+0x54>
jmp    1175 <parse_nat+0x65>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112f <parse_nat+0x1f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1191 <parse_nat+0x81>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <parse_nat+0xb3>
cmpq   $0x0,-0x18(%rbp)
jl     11b0 <parse_nat+0xa0>
mov    -0x18(%rbp),%rax
mov    0x2e41(%rip),%rcx
cmp    (%rcx),%rax
jle    11bc <parse_nat+0xac>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <parse_nat+0xb3>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_nat>:
push   %rax
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    (%rsp),%rcx
jmp    1134 <parse_nat+0x24>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rcx
movzbl (%rcx),%edx
cmp    $0x9,%dl
je     1130 <parse_nat+0x20>
cmp    $0x20,%dl
je     1130 <parse_nat+0x20>
test   %dl,%dl
jne    1161 <parse_nat+0x51>
mov    0x2e9c(%rip),%rcx
cmp    (%rcx),%rax
mov    $0xffffffff,%edx
mov    %eax,%ecx
cmovg  %edx,%ecx
test   %rax,%rax
cmovs  %edx,%ecx
jmp    1166 <parse_nat+0x56>
mov    $0xffffffff,%ecx
mov    %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
@INT_MAX = global i64 0
define i32 @parse_nat(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strtol(i8* %6, i8** %5, i32 0)
store i64 %7, i64* %4
br label %8
8: ; preds = %20, %1
%9 = load i8*, i8** %5
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 32
br i1 %12, label %18, label %13
13: ; preds = %8
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 9
br label %18
18: ; preds = %13, %8
%19 = phi i1 [ true, %8 ], [ %17, %13 ]
br i1 %19, label %20, label %23
20: ; preds = %18
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %5
br label %8
23: ; preds = %18
%24 = load i8*, i8** %5
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 -1, i32* %2
br label %40
29: ; preds = %23
%30 = load i64, i64* %4
%31 = icmp slt i64 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %29
%33 = load i64, i64* %4
%34 = load i64, i64* @INT_MAX
%35 = icmp sgt i64 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %32, %29
store i32 -1, i32* %2
br label %40
37: ; preds = %32
%38 = load i64, i64* %4
%39 = trunc i64 %38 to i32
store i32 %39, i32* %2
br label %40
40: ; preds = %37, %36, %28
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
@INT_MAX = global i64 0
define i32 @parse_nat(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @strtol(i8* %0, i8** %2, i32 0)
%5 = load i8*, i8** %2
br label %6
6: ; preds = %9, %1
%7 = phi i8* [ %10, %9 ], [ %5, %1 ]
%8 = load i8, i8* %7
switch i8 %8, label %18 [
i8 32, label %9
i8 9, label %9
i8 0, label %11
]
9: ; preds = %6, %6
%10 = getelementptr inbounds i8, i8* %7, i64 1
br label %6
11: ; preds = %6
%12 = icmp slt i64 %4, 0
%13 = load i64, i64* @INT_MAX
%14 = icmp sgt i64 %4, %13
%15 = select i1 %12, i1 true, i1 %14
%16 = trunc i64 %4 to i32
%17 = select i1 %15, i32 -1, i32 %16
br label %18
18: ; preds = %6, %11
%19 = phi i32 [ %17, %11 ], [ -1, %6 ]
ret i32 %19
}