#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int atoi(char *);
char *create_string(char *);
char *strchr(char *, char);
int strlcpy(char *, char const *, int);
int strspn(char *, char *);
int is_telnet_dev(const char *dev, char **host_ref, int *port_ref) {
  char buf[1024];
  char *p;
  int n;
  assert(dev != NULL);
  if (strlcpy(buf, dev, sizeof(buf)) >= sizeof(buf)) {
    return (0);
  }
  if (!(p = strchr(buf, ':'))) {
    return (0);
  }
  if ((n = strspn(p + 1, "0123456789")) == 0) {
    return (0);
  }
  if (p[n + 1] != '\0') {
    return (0);
  }
  *p++ = '\0';
  if (host_ref) {
    *host_ref = create_string(buf);
  }
  if (port_ref) {
    *port_ref = atoi(p);
  }
  return (1);
}


x86 assembly (clang, -O0):
<is_telnet_dev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x400,%edx
call   1070 <strlcpy@plt>
cltq
cmp    $0x400,%rax
jb     11b8 <is_telnet_dev+0x58>
movl   $0x0,-0x4(%rbp)
jmp    12a3 <is_telnet_dev+0x143>
lea    -0x420(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
jne    11e6 <is_telnet_dev+0x86>
movl   $0x0,-0x4(%rbp)
jmp    12a3 <is_telnet_dev+0x143>
mov    -0x428(%rbp),%rdi
add    $0x1,%rdi
lea    0xe08(%rip),%rsi
call   1040 <strspn@plt>
mov    %eax,-0x42c(%rbp)
cmp    $0x0,%eax
jne    1218 <is_telnet_dev+0xb8>
movl   $0x0,-0x4(%rbp)
jmp    12a3 <is_telnet_dev+0x143>
mov    -0x428(%rbp),%rax
mov    -0x42c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1244 <is_telnet_dev+0xe4>
movl   $0x0,-0x4(%rbp)
jmp    12a3 <is_telnet_dev+0x143>
mov    -0x428(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x428(%rbp)
movb   $0x0,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     127d <is_telnet_dev+0x11d>
lea    -0x420(%rbp),%rdi
call   1060 <create_string@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     129c <is_telnet_dev+0x13c>
mov    -0x428(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_telnet_dev>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1070 <strlcpy@plt>
xor    %ebp,%ebp
cmp    $0x3ff,%eax
ja     11fd <is_telnet_dev+0x9d>
mov    %rsp,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11fd <is_telnet_dev+0x9d>
mov    %rax,%rbx
lea    0x1(%rax),%r15
lea    0xe41(%rip),%rsi
mov    %r15,%rdi
call   1040 <strspn@plt>
test   %eax,%eax
je     11fd <is_telnet_dev+0x9d>
cltq
cmpb   $0x0,0x1(%rax,%rbx,1)
jne    11fd <is_telnet_dev+0x9d>
movb   $0x0,(%rbx)
test   %r12,%r12
je     11e8 <is_telnet_dev+0x88>
mov    %rsp,%rdi
call   1060 <create_string@plt>
mov    %rax,(%r12)
mov    $0x1,%ebp
test   %r14,%r14
je     11fd <is_telnet_dev+0x9d>
mov    %r15,%rdi
call   1080 <atoi@plt>
mov    %eax,(%r14)
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"0123456789\00"
define i32 @is_telnet_dev(i8* %0, i8** writeonly %1, i32* writeonly %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = icmp ne i8* %0, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = call i32 @strlcpy(i8* %5, i8* %0, i32 1024)
%10 = icmp ugt i32 %9, 1023
br i1 %10, label %32, label %11
11: ; preds = %3
%12 = call i8* @strchr(i8* %5, i8 signext 58)
%13 = icmp eq i8* %12, null
br i1 %13, label %32, label %14
14: ; preds = %11
%15 = getelementptr inbounds i8, i8* %12, i64 1
%16 = call i32 @strspn(i8* %15, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %32, label %18
18: ; preds = %14
%19 = add nsw i32 %16, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %12, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %18
store i8 0, i8* %12
%25 = icmp eq i8** %1, null
br i1 %25, label %28, label %26
26: ; preds = %24
%27 = call i8* @create_string(i8* %5)
store i8* %27, i8** %1
br label %28
28: ; preds = %26, %24
%29 = icmp eq i32* %2, null
br i1 %29, label %32, label %30
30: ; preds = %28
%31 = call i32 @atoi(i8* %15)
store i32 %31, i32* %2
br label %32
32: ; preds = %28, %30, %18, %14, %11, %3
%33 = phi i32 [ 0, %3 ], [ 0, %11 ], [ 0, %14 ], [ 0, %18 ], [ 1, %30 ], [ 1, %28 ]
ret i32 %33
}