#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*/ could_be_hostname(char *, char *);
int /*<<< orphan*/ could_be_servicename(char *, char *);
int strlen(char *);
scalar_t__ strncasecmp(char *, char *, int);
char *strrchr(char *, char);
bool scan_tcp_address(char *s, char **server_s, char **server_e, char **port_s,
                      char **port_e) {
  char *p;
  *server_s = s + (strncasecmp(s, "tcp://", 6) == 0
                       ? 6
                       : (strncasecmp(s, "tcp:", 4) == 0 ? 4 : 0));
  if ((p = strrchr(*server_s, ':')) == NULL) {
    *server_e = *server_s + strlen(*server_s);
    if (!could_be_hostname(*server_s, *server_e))
      return false;
    *port_s = NULL;
    *port_e = NULL;
  } else {
    if (!could_be_hostname(*server_s, *server_e = p))
      return false;
    *port_s = p + 1;
    *port_e = p + strlen(p);
    if (!could_be_servicename(*port_s, *port_e))
      return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<scan_tcp_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe81(%rip),%rsi
mov    $0x6,%edx
call   1060 <strncasecmp@plt>
cmp    $0x0,%rax
jne    11a0 <scan_tcp_address+0x50>
mov    $0x6,%eax
mov    %eax,-0x44(%rbp)
jmp    11c9 <scan_tcp_address+0x79>
mov    -0x10(%rbp),%rdi
lea    0xe5c(%rip),%rsi
mov    $0x4,%edx
call   1060 <strncasecmp@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x4,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%rcx
mov    -0x44(%rbp),%eax
cltq
add    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    $0x3a,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1265 <scan_tcp_address+0x115>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    -0x50(%rbp),%rcx
cltq
add    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
call   1070 <could_be_hostname@plt>
cmp    $0x0,%eax
jne    124a <scan_tcp_address+0xfa>
movl   $0x0,-0x4(%rbp)
jmp    12f5 <scan_tcp_address+0x1a5>
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movq   $0x0,(%rax)
jmp    12ee <scan_tcp_address+0x19e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    %rsi,(%rax)
call   1070 <could_be_hostname@plt>
cmp    $0x0,%eax
jne    1291 <scan_tcp_address+0x141>
movl   $0x0,-0x4(%rbp)
jmp    12f5 <scan_tcp_address+0x1a5>
mov    -0x38(%rbp),%rcx
add    $0x1,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x58(%rbp),%rcx
cltq
add    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
call   1050 <could_be_servicename@plt>
cmp    $0x0,%eax
jne    12e9 <scan_tcp_address+0x199>
movl   $0x0,-0x4(%rbp)
jmp    12f5 <scan_tcp_address+0x1a5>
jmp    12ee <scan_tcp_address+0x19e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_tcp_address>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbx
lea    0xe8f(%rip),%rsi
mov    $0x6,%edx
call   1060 <strncasecmp@plt>
test   %rax,%rax
je     11a2 <scan_tcp_address+0x52>
lea    0xe80(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1060 <strncasecmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
shl    $0x2,%rcx
jmp    11a7 <scan_tcp_address+0x57>
mov    $0x6,%ecx
add    %rcx,%rbx
mov    %rbx,0x0(%r13)
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     11fe <scan_tcp_address+0xae>
mov    %rax,%rbp
mov    %rax,(%r12)
mov    %rbx,%rdi
mov    %rax,%rsi
call   1070 <could_be_hostname@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     1234 <scan_tcp_address+0xe4>
lea    0x1(%rbp),%rax
mov    %rax,(%r15)
mov    %rbp,%rdi
call   1030 <strlen@plt>
movslq %eax,%rsi
add    %rbp,%rsi
mov    %rsi,(%r14)
mov    (%r15),%rdi
call   1050 <could_be_servicename@plt>
test   %eax,%eax
jne    122b <scan_tcp_address+0xdb>
jmp    1234 <scan_tcp_address+0xe4>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%rsi
add    %rbx,%rsi
mov    %rsi,(%r12)
mov    0x0(%r13),%rdi
call   1070 <could_be_hostname@plt>
test   %eax,%eax
je     1232 <scan_tcp_address+0xe2>
movq   $0x0,(%r15)
movq   $0x0,(%r14)
mov    $0x1,%ebx
jmp    1234 <scan_tcp_address+0xe4>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"tcp://\00"
@.str.1 = [5 x i8] c"tcp:\00"
define i32 @scan_tcp_address(i8* %0, i8** %1, i8** %2, i8** %3, i8** %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca i8**
%11 = alloca i8**
%12 = alloca i8*
store i8* %0, i8** %7
store i8** %1, i8*** %8
store i8** %2, i8*** %9
store i8** %3, i8*** %10
store i8** %4, i8*** %11
%13 = load i8*, i8** %7
%14 = load i8*, i8** %7
%15 = call i64 @strncasecmp(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %5
br label %24
18: ; preds = %5
%19 = load i8*, i8** %7
%20 = call i64 @strncasecmp(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%21 = icmp eq i64 %20, 0
%22 = zext i1 %21 to i64
%23 = select i1 %21, i32 4, i32 0
br label %24
24: ; preds = %18, %17
%25 = phi i32 [ 6, %17 ], [ %23, %18 ]
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %13, i64 %26
%28 = load i8**, i8*** %8
store i8* %27, i8** %28
%29 = load i8**, i8*** %8
%30 = load i8*, i8** %29
%31 = call i8* @strrchr(i8* %30, i8 signext 58)
store i8* %31, i8** %12
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %52
33: ; preds = %24
%34 = load i8**, i8*** %8
%35 = load i8*, i8** %34
%36 = load i8**, i8*** %8
%37 = load i8*, i8** %36
%38 = call i32 @strlen(i8* %37)
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %35, i64 %39
%41 = load i8**, i8*** %9
store i8* %40, i8** %41
%42 = load i8**, i8*** %8
%43 = load i8*, i8** %42
%44 = load i8**, i8*** %9
%45 = load i8*, i8** %44
%46 = call i32 @could_be_hostname(i8* %43, i8* %45)
%47 = icmp ne i32 %46, 0
br i1 %47, label %49, label %48
48: ; preds = %33
store i32 0, i32* %6
br label %79
49: ; preds = %33
%50 = load i8**, i8*** %10
store i8* null, i8** %50
%51 = load i8**, i8*** %11
store i8* null, i8** %51
br label %78
52: ; preds = %24
%53 = load i8**, i8*** %8
%54 = load i8*, i8** %53
%55 = load i8*, i8** %12
%56 = load i8**, i8*** %9
store i8* %55, i8** %56
%57 = call i32 @could_be_hostname(i8* %54, i8* %55)
%58 = icmp ne i32 %57, 0
br i1 %58, label %60, label %59
59: ; preds = %52
store i32 0, i32* %6
br label %79
60: ; preds = %52
%61 = load i8*, i8** %12
%62 = getelementptr inbounds i8, i8* %61, i64 1
%63 = load i8**, i8*** %10
store i8* %62, i8** %63
%64 = load i8*, i8** %12
%65 = load i8*, i8** %12
%66 = call i32 @strlen(i8* %65)
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %64, i64 %67
%69 = load i8**, i8*** %11
store i8* %68, i8** %69
%70 = load i8**, i8*** %10
%71 = load i8*, i8** %70
%72 = load i8**, i8*** %11
%73 = load i8*, i8** %72
%74 = call i32 @could_be_servicename(i8* %71, i8* %73)
%75 = icmp ne i32 %74, 0
br i1 %75, label %77, label %76
76: ; preds = %60
store i32 0, i32* %6
br label %79
77: ; preds = %60
br label %78
78: ; preds = %77, %49
store i32 1, i32* %6
br label %79
79: ; preds = %78, %76, %59, %48
%80 = load i32, i32* %6
ret i32 %80
}

LLVM IR (-O2):
@.str = [7 x i8] c"tcp://\00"
@.str.1 = [5 x i8] c"tcp:\00"
define i32 @scan_tcp_address(i8* %0, i8** nocapture %1, i8** nocapture writeonly %2, i8** nocapture %3, i8** nocapture writeonly %4) {
%6 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%7 = icmp eq i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i64 4, i64 0
br label %12
12: ; preds = %5, %8
%13 = phi i64 [ %11, %8 ], [ 6, %5 ]
%14 = getelementptr inbounds i8, i8* %0, i64 %13
store i8* %14, i8** %1
%15 = tail call i8* @strrchr(i8* dereferenceable(1) %14, i8 signext 58)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %25
17: ; preds = %12
%18 = tail call i32 @strlen(i8* %14)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %14, i64 %19
store i8* %20, i8** %2
%21 = load i8*, i8** %1
%22 = tail call i32 @could_be_hostname(i8* %21, i8* %20)
%23 = icmp eq i32 %22, 0
br i1 %23, label %37, label %24
24: ; preds = %17
store i8* null, i8** %3
store i8* null, i8** %4
br label %36
25: ; preds = %12
store i8* %15, i8** %2
%26 = tail call i32 @could_be_hostname(i8* %14, i8* %15)
%27 = icmp eq i32 %26, 0
br i1 %27, label %37, label %28
28: ; preds = %25
%29 = getelementptr inbounds i8, i8* %15, i64 1
store i8* %29, i8** %3
%30 = tail call i32 @strlen(i8* %15)
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %15, i64 %31
store i8* %32, i8** %4
%33 = load i8*, i8** %3
%34 = tail call i32 @could_be_servicename(i8* %33, i8* %32)
%35 = icmp eq i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %28, %24
br label %37
37: ; preds = %28, %25, %17, %36
%38 = phi i32 [ 1, %36 ], [ 0, %17 ], [ 0, %25 ], [ 0, %28 ]
ret i32 %38
}