#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;
int *malloc(int);
int strtoul(char const *, char **, int /*<<< orphan*/);
int *parse_gpr(const char *argv) {
  int *gpr = malloc(sizeof(*gpr));
  char *endptr;
  if (!argv)
    return NULL;
  errno = 0;
  *gpr = strtoul(argv, &endptr, 0);
  if (errno || *endptr != '\0' || *gpr > 32)
    return NULL;
  return gpr;
}


x86 assembly (clang, -O0):
<parse_gpr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x4,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1152 <parse_gpr+0x32>
movq   $0x0,-0x8(%rbp)
jmp    11ba <parse_gpr+0x9a>
mov    0x2e87(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2e62(%rip),%rax
cmpq   $0x0,(%rax)
jne    11a5 <parse_gpr+0x85>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a5 <parse_gpr+0x85>
mov    -0x18(%rbp),%rax
cmpl   $0x20,(%rax)
jle    11b2 <parse_gpr+0x92>
movq   $0x0,-0x8(%rbp)
jmp    11ba <parse_gpr+0x9a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_gpr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x4,%edi
call   1030 <malloc@plt>
test   %rbx,%rbx
je     117f <parse_gpr+0x5f>
mov    %rax,%r15
mov    0x2e9c(%rip),%r12
movq   $0x0,(%r12)
mov    %rsp,%rsi
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %eax,(%r15)
cmpq   $0x0,(%r12)
jne    1182 <parse_gpr+0x62>
mov    (%rsp),%rcx
xor    %edx,%edx
cmp    $0x21,%eax
cmovge %rdx,%r15
cmpb   $0x0,(%rcx)
cmovne %rdx,%r15
mov    %r15,%r14
jmp    1182 <parse_gpr+0x62>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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