#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 */
char *memchr(char const *, char, int);
int /*<<< orphan*/ strncasecmp(char const *, char *, int);
int tcp_match(char const *s, char const *e) {
  char const *col;
  if (e - s >= 3 && !strncasecmp(s, "tcp", 3) && (e - s == 3 || s[3] == ':'))
    return true;
  if ((col = memchr(s, ':', e - s)) == NULL)
    col = e;
  if (memchr(s, '.', col - s) == NULL || memchr(s, '/', col - s) != NULL)
    return false;
  return true;
}


x86 assembly (clang, -O0):
<tcp_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x3,%rax
jl     1195 <tcp_match+0x75>
mov    -0x10(%rbp),%rdi
lea    0xeb0(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%eax
jne    1195 <tcp_match+0x75>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x3,%rax
je     1189 <tcp_match+0x69>
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x3a,%eax
jne    1195 <tcp_match+0x75>
movl   $0x1,-0x4(%rbp)
jmp    1223 <tcp_match+0x103>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    $0x3a,%esi
call   1030 <memchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11c6 <tcp_match+0xa6>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    $0x2e,%esi
call   1030 <memchr@plt>
cmp    $0x0,%rax
je     1210 <tcp_match+0xf0>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    $0x2f,%esi
call   1030 <memchr@plt>
cmp    $0x0,%rax
je     121c <tcp_match+0xfc>
movl   $0x0,-0x4(%rbp)
jmp    1223 <tcp_match+0x103>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcp_match>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rbx
sub    %rdi,%rbx
cmp    $0x3,%rbx
jl     114f <tcp_match+0x2f>
lea    0xec2(%rip),%rsi
mov    %r14,%rdi
mov    $0x3,%edx
call   1040 <strncasecmp@plt>
test   %eax,%eax
je     119e <tcp_match+0x7e>
mov    %r14,%rdi
mov    $0x3a,%esi
mov    %ebx,%edx
call   1030 <memchr@plt>
test   %rax,%rax
cmovne %eax,%r15d
sub    %r14d,%r15d
mov    %r14,%rdi
mov    $0x2e,%esi
mov    %r15d,%edx
call   1030 <memchr@plt>
test   %rax,%rax
je     119a <tcp_match+0x7a>
mov    %r14,%rdi
mov    $0x2f,%esi
mov    %r15d,%edx
call   1030 <memchr@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    11b0 <tcp_match+0x90>
xor    %eax,%eax
jmp    11b0 <tcp_match+0x90>
mov    $0x1,%eax
cmp    $0x3,%rbx
je     11b0 <tcp_match+0x90>
cmpb   $0x3a,0x3(%r14)
jne    114f <tcp_match+0x2f>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"tcp\00"
define i32 @tcp_match(i8* %0, i8* %1) {
%3 = ptrtoint i8* %1 to i64
%4 = ptrtoint i8* %0 to i64
%5 = sub i64 %3, %4
%6 = icmp sgt i64 %5, 2
br i1 %6, label %7, label %16
7: ; preds = %2
%8 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = icmp eq i64 %5, 3
br i1 %11, label %30, label %12
12: ; preds = %10
%13 = getelementptr inbounds i8, i8* %0, i64 3
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 58
br i1 %15, label %30, label %16
16: ; preds = %12, %7, %2
%17 = trunc i64 %5 to i32
%18 = tail call i8* @memchr(i8* %0, i8 signext 58, i32 %17)
%19 = icmp eq i8* %18, null
%20 = select i1 %19, i8* %1, i8* %18
%21 = ptrtoint i8* %20 to i64
%22 = sub i64 %21, %4
%23 = trunc i64 %22 to i32
%24 = tail call i8* @memchr(i8* %0, i8 signext 46, i32 %23)
%25 = icmp eq i8* %24, null
br i1 %25, label %30, label %26
26: ; preds = %16
%27 = tail call i8* @memchr(i8* %0, i8 signext 47, i32 %23)
%28 = icmp eq i8* %27, null
%29 = zext i1 %28 to i32
br label %30
30: ; preds = %26, %16, %10, %12
%31 = phi i32 [ 1, %12 ], [ 1, %10 ], [ 0, %16 ], [ %29, %26 ]
ret i32 %31
}