#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 scalar_t__ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ isnumeric(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int tokenize_host_port(char *token, char *host, uint16_t *port) {
  char *p = strstr(token, ":");
  int len;
  if (p == NULL)
    return -1;
  if (!isnumeric(p + 1))
    return -1;
  len = p - token;
  strncpy(host, token, len);
  host[len] = 0;
  *port = (uint16_t)strtol(p + 1, NULL, 0);
  return 0;
}


x86 assembly (clang, -O0):
<tokenize_host_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117f <tokenize_host_port+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ef <tokenize_host_port+0xaf>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1050 <isnumeric@plt>
cmp    $0x0,%eax
jne    11a1 <tokenize_host_port+0x61>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ef <tokenize_host_port+0xaf>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenize_host_port>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    $0xffffffff,%r12d
test   %rax,%rax
je     11a6 <tokenize_host_port+0x66>
mov    %rax,%rbp
lea    0x1(%rax),%r13
mov    %r13,%rdi
call   1060 <isnumeric@plt>
test   %eax,%eax
je     11a6 <tokenize_host_port+0x66>
sub    %rbx,%rbp
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,(%r15,%rax,1)
xor    %r12d,%r12d
mov    %r13,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,(%r14)
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c":\00"
define i32 @tokenize_host_port(i8* %0, i8* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64* %2, i64** %7
%10 = load i8*, i8** %5
%11 = call i8* @strstr(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %8
%12 = load i8*, i8** %8
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %40
15: ; preds = %3
%16 = load i8*, i8** %8
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = call i32 @isnumeric(i8* %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %15
store i32 -1, i32* %4
br label %40
21: ; preds = %15
%22 = load i8*, i8** %8
%23 = load i8*, i8** %5
%24 = ptrtoint i8* %22 to i64
%25 = ptrtoint i8* %23 to i64
%26 = sub i64 %24, %25
%27 = trunc i64 %26 to i32
store i32 %27, i32* %9
%28 = load i8*, i8** %6
%29 = load i8*, i8** %5
%30 = load i32, i32* %9
%31 = call i32 @strncpy(i8* %28, i8* %29, i32 %30)
%32 = load i8*, i8** %6
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 0, i8* %35
%36 = load i8*, i8** %8
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = call i64 @strtol(i8* %37, i32* null, i32 0)
%39 = load i64*, i64** %7
store i64 %38, i64* %39
store i32 0, i32* %4
br label %40
40: ; preds = %21, %20, %14
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
define i32 @tokenize_host_port(i8* %0, i8* %1, i64* nocapture writeonly %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 58)
%5 = icmp eq i8* %4, null
br i1 %5, label %20, label %6
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %4, i64 1
%8 = tail call i32 @isnumeric(i8* %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %20, label %10
10: ; preds = %6
%11 = ptrtoint i8* %4 to i64
%12 = ptrtoint i8* %0 to i64
%13 = sub i64 %11, %12
%14 = trunc i64 %13 to i32
%15 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %14)
%16 = shl i64 %13, 32
%17 = ashr exact i64 %16, 32
%18 = getelementptr inbounds i8, i8* %1, i64 %17
store i8 0, i8* %18
%19 = tail call i64 @strtol(i8* nocapture %7, i32* null, i32 0)
store i64 %19, i64* %2
br label %20
20: ; preds = %6, %3, %10
%21 = phi i32 [ 0, %10 ], [ -1, %3 ], [ -1, %6 ]
ret i32 %21
}