#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 */
int /*<<< orphan*/ isdigit(char);
char *str2cstr(unsigned long);
int string_length(unsigned long);
unsigned long string_to_f(unsigned long);
unsigned long string_to_i(unsigned long);
unsigned long int string_to_num(unsigned long int self) {
  int i, len;
  char *ptr;
  ptr = str2cstr(self);
  len = string_length(self);
  if ((ptr[0] == '+') || (ptr[0] == '-'))
    i = 1;
  else
    i = 0;
  for (; i < len; i++) {
    if (ptr[i] == '.')
      return string_to_f(self);
    else if (!isdigit(ptr[i]))
      return string_to_i(self);
  }
  return string_to_i(self);
}


x86 assembly (clang, -O0):
<string_to_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <str2cstr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <string_length@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
je     1195 <string_to_num+0x45>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11a1 <string_to_num+0x51>
movl   $0x1,-0x14(%rbp)
jmp    11a8 <string_to_num+0x58>
movl   $0x0,-0x14(%rbp)
jmp    11ad <string_to_num+0x5d>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1224 <string_to_num+0xd4>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    11e0 <string_to_num+0x90>
mov    -0x10(%rbp),%rdi
call   1050 <string_to_f@plt>
mov    %rax,-0x8(%rbp)
jmp    1231 <string_to_num+0xe1>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    120c <string_to_num+0xbc>
mov    -0x10(%rbp),%rdi
call   1040 <string_to_i@plt>
mov    %rax,-0x8(%rbp)
jmp    1231 <string_to_num+0xe1>
jmp    1211 <string_to_num+0xc1>
jmp    1216 <string_to_num+0xc6>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ad <string_to_num+0x5d>
mov    -0x10(%rbp),%rdi
call   1040 <string_to_i@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_to_num>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1070 <str2cstr@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1060 <string_length@plt>
mov    (%r15),%cl
add    $0xd5,%cl
xor    %ebx,%ebx
test   $0xfd,%cl
sete   %bl
cmp    %ebx,%eax
jle    119e <string_to_num+0x4e>
mov    %eax,%r12d
movzbl (%r15,%rbx,1),%eax
cmp    $0x2e,%al
je     11b1 <string_to_num+0x61>
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     119e <string_to_num+0x4e>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1180 <string_to_num+0x30>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <string_to_i@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <string_to_f@plt>

LLVM IR (-O0):
define i64 @string_to_num(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i64 %0, i64* %3
%7 = load i64, i64* %3
%8 = call i8* @str2cstr(i64 %7)
store i8* %8, i8** %6
%9 = load i64, i64* %3
%10 = call i32 @string_length(i64 %9)
store i32 %10, i32* %5
%11 = load i8*, i8** %6
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 43
br i1 %15, label %22, label %16
16: ; preds = %1
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 45
br i1 %21, label %22, label %23
22: ; preds = %16, %1
store i32 1, i32* %4
br label %24
23: ; preds = %16
store i32 0, i32* %4
br label %24
24: ; preds = %23, %22
br label %25
25: ; preds = %53, %24
%26 = load i32, i32* %4
%27 = load i32, i32* %5
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %56
29: ; preds = %25
%30 = load i8*, i8** %6
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 46
br i1 %36, label %37, label %40
37: ; preds = %29
%38 = load i64, i64* %3
%39 = call i64 @string_to_f(i64 %38)
store i64 %39, i64* %2
br label %59
40: ; preds = %29
%41 = load i8*, i8** %6
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = call i32 @isdigit(i8 signext %45)
%47 = icmp ne i32 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %40
%49 = load i64, i64* %3
%50 = call i64 @string_to_i(i64 %49)
store i64 %50, i64* %2
br label %59
51: ; preds = %40
br label %52
52: ; preds = %51
br label %53
53: ; preds = %52
%54 = load i32, i32* %4
%55 = add nsw i32 %54, 1
store i32 %55, i32* %4
br label %25
56: ; preds = %25
%57 = load i64, i64* %3
%58 = call i64 @string_to_i(i64 %57)
store i64 %58, i64* %2
br label %59
59: ; preds = %56, %48, %37
%60 = load i64, i64* %2
ret i64 %60
}

LLVM IR (-O2):
define i64 @string_to_num(i64 %0) {
%2 = tail call i8* @str2cstr(i64 %0)
%3 = tail call i32 @string_length(i64 %0)
%4 = load i8, i8* %2
%5 = icmp eq i8 %4, 43
%6 = icmp eq i8 %4, 45
%7 = or i1 %5, %6
%8 = zext i1 %7 to i32
%9 = icmp sgt i32 %3, %8
br i1 %9, label %10, label %28
10: ; preds = %1
%11 = zext i1 %7 to i64
%12 = zext i32 %3 to i64
br label %15
13: ; preds = %22
%14 = icmp eq i64 %25, %12
br i1 %14, label %28, label %15
15: ; preds = %10, %13
%16 = phi i64 [ %11, %10 ], [ %25, %13 ]
%17 = getelementptr inbounds i8, i8* %2, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 46
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = tail call i64 @string_to_f(i64 %0)
br label %30
22: ; preds = %15
%23 = tail call i32 @isdigit(i8 signext %18)
%24 = icmp eq i32 %23, 0
%25 = add nuw nsw i64 %16, 1
br i1 %24, label %26, label %13
26: ; preds = %22
%27 = tail call i64 @string_to_i(i64 %0)
br label %30
28: ; preds = %13, %1
%29 = tail call i64 @string_to_i(i64 %0)
br label %30
30: ; preds = %28, %26, %20
%31 = phi i64 [ %21, %20 ], [ %27, %26 ], [ %29, %28 ]
ret i64 %31
}