#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*/ memcmp(char const *, char *, int);
int remote_number_to_port(int);
int strlen(char const *);
long strtol(char const *, char **, int);
int remote_number_string_to_port(const char *number) {
  char *end;
  long num;
  const char *temp = number;
  int len;
  len = strlen(number);
  if (len > 0 && number[len - 1] == ';')
    len--;
  if (len == 11 && !memcmp(number, "1555521", 7))
    temp += 7;
  num = strtol(temp, &end, 10);
  if (end == NULL || *end || (int)num != num)
    return -1;
  return remote_number_to_port((int)num);
}


x86 assembly (clang, -O0):
<remote_number_string_to_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jle    118d <remote_number_string_to_port+0x4d>
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3b,%eax
jne    118d <remote_number_string_to_port+0x4d>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0xb,-0x2c(%rbp)
jne    11c1 <remote_number_string_to_port+0x81>
mov    -0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
mov    $0x7,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%eax
jne    11c1 <remote_number_string_to_port+0x81>
mov    -0x28(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1202 <remote_number_string_to_port+0xc2>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1202 <remote_number_string_to_port+0xc2>
mov    -0x20(%rbp),%rax
cltq
cmp    -0x20(%rbp),%rax
je     120e <remote_number_string_to_port+0xce>
movl   $0xffffffff,-0x4(%rbp)
jmp    121c <remote_number_string_to_port+0xdc>
mov    -0x20(%rbp),%rax
mov    %eax,%edi
call   1030 <remote_number_to_port@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remote_number_string_to_port>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1040 <strlen@plt>
test   %eax,%eax
jle    117e <remote_number_string_to_port+0x3e>
lea    -0x1(%rax),%ecx
cmpb   $0x3b,(%rbx,%rcx,1)
cmove  %ecx,%eax
cmp    $0xb,%eax
jne    117e <remote_number_string_to_port+0x3e>
lea    0xe99(%rip),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
call   1050 <memcmp@plt>
lea    0x7(%rbx),%rcx
test   %eax,%eax
cmove  %rcx,%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    0x8(%rsp),%rcx
test   %rcx,%rcx
je     11bb <remote_number_string_to_port+0x7b>
cmpb   $0x0,(%rcx)
jne    11bb <remote_number_string_to_port+0x7b>
mov    %rax,%rcx
sub    $0xffffffff80000000,%rcx
shr    $0x20,%rcx
jne    11bb <remote_number_string_to_port+0x7b>
mov    %eax,%edi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <remote_number_to_port@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"1555521\00"
define i32 @remote_number_string_to_port(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
store i8* %8, i8** %6
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = load i32, i32* %7
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 59
br i1 %21, label %22, label %25
22: ; preds = %13
%23 = load i32, i32* %7
%24 = add nsw i32 %23, -1
store i32 %24, i32* %7
br label %25
25: ; preds = %22, %13, %1
%26 = load i32, i32* %7
%27 = icmp eq i32 %26, 11
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = load i8*, i8** %3
%30 = call i32 @memcmp(i8* %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%31 = icmp ne i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %28
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i64 7
store i8* %34, i8** %6
br label %35
35: ; preds = %32, %28, %25
%36 = load i8*, i8** %6
%37 = call i64 @strtol(i8* %36, i8** %4, i32 10)
store i64 %37, i64* %5
%38 = load i8*, i8** %4
%39 = icmp eq i8* %38, null
br i1 %39, label %51, label %40
40: ; preds = %35
%41 = load i8*, i8** %4
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 0
br i1 %44, label %51, label %45
45: ; preds = %40
%46 = load i64, i64* %5
%47 = trunc i64 %46 to i32
%48 = sext i32 %47 to i64
%49 = load i64, i64* %5
%50 = icmp ne i64 %48, %49
br i1 %50, label %51, label %52
51: ; preds = %45, %40, %35
store i32 -1, i32* %2
br label %56
52: ; preds = %45
%53 = load i64, i64* %5
%54 = trunc i64 %53 to i32
%55 = call i32 @remote_number_to_port(i32 %54)
store i32 %55, i32* %2
br label %56
56: ; preds = %52, %51
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
@.str = [8 x i8] c"1555521\00"
define i32 @remote_number_string_to_port(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %19
6: ; preds = %1
%7 = add nsw i32 %4, -1
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 59
%12 = select i1 %11, i32 %7, i32 %4
%13 = icmp eq i32 %12, 11
br i1 %13, label %14, label %19
14: ; preds = %6
%15 = tail call i32 @memcmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, i64 7, i64 0
%18 = getelementptr i8, i8* %0, i64 %17
br label %19
19: ; preds = %1, %14, %6
%20 = phi i8* [ %0, %6 ], [ %18, %14 ], [ %0, %1 ]
%21 = call i64 @strtol(i8* %20, i8** %2, i32 10)
%22 = load i8*, i8** %2
%23 = icmp eq i8* %22, null
br i1 %23, label %33, label %24
24: ; preds = %19
%25 = load i8, i8* %22
%26 = icmp eq i8 %25, 0
%27 = add i64 %21, 2147483648
%28 = icmp ult i64 %27, 4294967296
%29 = select i1 %26, i1 %28, i1 false
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = trunc i64 %21 to i32
%32 = tail call i32 @remote_number_to_port(i32 %31)
br label %33
33: ; preds = %19, %24, %30
%34 = phi i32 [ %32, %30 ], [ -1, %24 ], [ -1, %19 ]
ret i32 %34
}