#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;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long);
int /*<<< orphan*/ stderr;
long strtol(char const *, char **, int);
int kira_num2fdpid(const char *str) {
  long num;
  bool intvl = false;
  char *ep = NULL;
  if (*str == '-')
    goto fail;
  if (*str == '+') {
    str++;
    intvl = true;
  }
  if (*str == '\0')
    goto fail;
  if (*str < '0' || *str > '9')
    goto success;
  num = strtol(str, &ep, 10);
  if (num <= 1 || num >= INT_MAX || *ep != '\0') {
    fprintf(stderr, "Fatal: value must be between 2 and %d inclusive\n",
            INT_MAX);
    goto fail;
  }
  if (intvl)
    num = -num;
out:
  return num;
success:
  num = 0;
  goto out;
fail:
  num = -1;
  goto out;
}


x86 assembly (clang, -O0):
<kira_num2fdpid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1150 <kira_num2fdpid+0x30>
jmp    1246 <kira_num2fdpid+0x126>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    1173 <kira_num2fdpid+0x53>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1188 <kira_num2fdpid+0x68>
jmp    1246 <kira_num2fdpid+0x126>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     11a8 <kira_num2fdpid+0x88>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jle    11ad <kira_num2fdpid+0x8d>
jmp    1239 <kira_num2fdpid+0x119>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x1,-0x10(%rbp)
jle    11f2 <kira_num2fdpid+0xd2>
mov    -0x10(%rbp),%rax
mov    0x2e0f(%rip),%rcx
cmp    (%rcx),%rax
jge    11f2 <kira_num2fdpid+0xd2>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1216 <kira_num2fdpid+0xf6>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
mov    0x2de6(%rip),%rax
mov    (%rax),%rdx
lea    0xdf4(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1246 <kira_num2fdpid+0x126>
cmpl   $0x0,-0x14(%rbp)
je     122a <kira_num2fdpid+0x10a>
xor    %eax,%eax
sub    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    122f <kira_num2fdpid+0x10f>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret
movq   $0x0,-0x10(%rbp)
jmp    122f <kira_num2fdpid+0x10f>
movq   $0xffffffffffffffff,-0x10(%rbp)
ff
jmp    122f <kira_num2fdpid+0x10f>

x86 assembly (clang, -O2):
<kira_num2fdpid>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
mov    (%rdi),%bl
mov    $0xffffffff,%eax
cmp    $0x2d,%bl
je     11a1 <kira_num2fdpid+0x81>
xor    %ecx,%ecx
cmp    $0x2b,%bl
sete   %cl
mov    (%rdi,%rcx,1),%dl
test   %dl,%dl
je     11a1 <kira_num2fdpid+0x81>
add    $0xc6,%dl
xor    %eax,%eax
cmp    $0xf6,%dl
jb     11a1 <kira_num2fdpid+0x81>
add    %rcx,%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rcx
mov    0x2e79(%rip),%rax
mov    (%rax),%rdx
cmp    $0x2,%rcx
jl     1187 <kira_num2fdpid+0x67>
cmp    %rdx,%rcx
jge    1187 <kira_num2fdpid+0x67>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     11a7 <kira_num2fdpid+0x87>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    %ecx,%eax
neg    %eax
cmp    $0x2b,%bl
cmovne %ecx,%eax
jmp    11a1 <kira_num2fdpid+0x81>

LLVM IR (-O0):
@INT_MAX = global i64 0
@stderr = global i32 0
@.str = [49 x i8] c"Fatal: value must be between 2 and %d inclusive\0A\00"
define i32 @kira_num2fdpid(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %4
store i8* null, i8** %5
%6 = load i8*, i8** %2
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 45
br i1 %9, label %10, label %11
10: ; preds = %1
br label %65
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 43
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i8*, i8** %2
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %2
store i32 1, i32* %4
br label %19
19: ; preds = %16, %11
%20 = load i8*, i8** %2
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
br label %65
25: ; preds = %19
%26 = load i8*, i8** %2
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp slt i32 %28, 48
br i1 %29, label %35, label %30
30: ; preds = %25
%31 = load i8*, i8** %2
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp sgt i32 %33, 57
br i1 %34, label %35, label %36
35: ; preds = %30, %25
br label %64
36: ; preds = %30
%37 = load i8*, i8** %2
%38 = call i64 @strtol(i8* %37, i8** %5, i32 10)
store i64 %38, i64* %3
%39 = load i64, i64* %3
%40 = icmp sle i64 %39, 1
br i1 %40, label %50, label %41
41: ; preds = %36
%42 = load i64, i64* %3
%43 = load i64, i64* @INT_MAX
%44 = icmp sge i64 %42, %43
br i1 %44, label %50, label %45
45: ; preds = %41
%46 = load i8*, i8** %5
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %45, %41, %36
%51 = load i32, i32* @stderr
%52 = load i64, i64* @INT_MAX
%53 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i64 %52)
br label %65
54: ; preds = %45
%55 = load i32, i32* %4
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %54
%58 = load i64, i64* %3
%59 = sub nsw i64 0, %58
store i64 %59, i64* %3
br label %60
60: ; preds = %57, %54
br label %61
61: ; preds = %65, %64, %60
%62 = load i64, i64* %3
%63 = trunc i64 %62 to i32
ret i32 %63
64: ; preds = %35
store i64 0, i64* %3
br label %61
65: ; preds = %50, %24, %10
store i64 -1, i64* %3
br label %61
}

LLVM IR (-O2):
@INT_MAX = global i64 0
@stderr = global i32 0
@.str = [49 x i8] c"Fatal: value must be between 2 and %d inclusive\0A\00"
define i32 @kira_num2fdpid(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 45
br i1 %5, label %32, label %6
6: ; preds = %1
%7 = icmp eq i8 %4, 43
%8 = zext i1 %7 to i64
%9 = getelementptr i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %32, label %12
12: ; preds = %6
%13 = add i8 %10, -58
%14 = icmp ult i8 %13, -10
br i1 %14, label %32, label %15
15: ; preds = %12
%16 = call i64 @strtol(i8* %9, i8** %2, i32 10)
%17 = icmp sgt i64 %16, 1
%18 = load i64, i64* @INT_MAX
%19 = icmp slt i64 %16, %18
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = load i8*, i8** %2
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %21, %15
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i64 %18)
br label %32
28: ; preds = %21
%29 = sub nsw i64 0, %16
%30 = select i1 %7, i64 %29, i64 %16
%31 = trunc i64 %30 to i32
br label %32
32: ; preds = %28, %25, %1, %6, %12
%33 = phi i32 [ %31, %28 ], [ 0, %12 ], [ -1, %6 ], [ -1, %1 ], [ -1, %25 ]
ret i32 %33
}