#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*/ memcpy(char *, char *, int);
char *strchr(char *, char);
int strtonum(char *, int, int, int /*<<< orphan*/ *);
int parse_host_port(char *hostport, char *host, int hostLen, int *port) {
  char *portStr;
  portStr = strchr(hostport, ':');
  if (portStr == NULL)
    return 1;
  if ((portStr - hostport + 1) > hostLen)
    return 2;
  memcpy(host, hostport, portStr - hostport);
  host[portStr - hostport] = '\x00';
  portStr++;
  *port = strtonum(portStr, 1, 65535, NULL);
  if (*port == 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<parse_host_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1170 <parse_host_port+0x40>
movl   $0x1,-0x4(%rbp)
jmp    1210 <parse_host_port+0xe0>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
movslq -0x1c(%rbp),%rcx
cmp    %rcx,%rax
jle    1198 <parse_host_port+0x68>
movl   $0x2,-0x4(%rbp)
jmp    1210 <parse_host_port+0xe0>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x1,%esi
mov    $0xffff,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <strtonum@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1209 <parse_host_port+0xd9>
movl   $0x1,-0x4(%rbp)
jmp    1210 <parse_host_port+0xe0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_host_port>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11a3 <parse_host_port+0x73>
mov    %rax,%r13
mov    %rax,%rbx
sub    %r12,%rbx
movslq %ebp,%rcx
mov    $0x2,%eax
cmp    %rcx,%rbx
jge    11a8 <parse_host_port+0x78>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
movb   $0x0,(%r15,%rbx,1)
add    $0x1,%r13
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0xffff,%edx
xor    %ecx,%ecx
call   1050 <strtonum@plt>
mov    %eax,%ecx
mov    %eax,(%r14)
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
jmp    11a8 <parse_host_port+0x78>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @parse_host_port(i8* %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%11 = load i8*, i8** %6
%12 = call i8* @strchr(i8* %11, i8 signext 58)
store i8* %12, i8** %10
%13 = load i8*, i8** %10
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %4
store i32 1, i32* %5
br label %54
16: ; preds = %4
%17 = load i8*, i8** %10
%18 = load i8*, i8** %6
%19 = ptrtoint i8* %17 to i64
%20 = ptrtoint i8* %18 to i64
%21 = sub i64 %19, %20
%22 = add nsw i64 %21, 1
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = icmp sgt i64 %22, %24
br i1 %25, label %26, label %27
26: ; preds = %16
store i32 2, i32* %5
br label %54
27: ; preds = %16
%28 = load i8*, i8** %7
%29 = load i8*, i8** %6
%30 = load i8*, i8** %10
%31 = load i8*, i8** %6
%32 = ptrtoint i8* %30 to i64
%33 = ptrtoint i8* %31 to i64
%34 = sub i64 %32, %33
%35 = trunc i64 %34 to i32
%36 = call i32 @memcpy(i8* %28, i8* %29, i32 %35)
%37 = load i8*, i8** %7
%38 = load i8*, i8** %10
%39 = load i8*, i8** %6
%40 = ptrtoint i8* %38 to i64
%41 = ptrtoint i8* %39 to i64
%42 = sub i64 %40, %41
%43 = getelementptr inbounds i8, i8* %37, i64 %42
store i8 0, i8* %43
%44 = load i8*, i8** %10
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %10
%46 = load i8*, i8** %10
%47 = call i32 @strtonum(i8* %46, i32 1, i32 65535, i32* null)
%48 = load i32*, i32** %9
store i32 %47, i32* %48
%49 = load i32*, i32** %9
%50 = load i32, i32* %49
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %27
store i32 1, i32* %5
br label %54
53: ; preds = %27
store i32 0, i32* %5
br label %54
54: ; preds = %53, %52, %26, %15
%55 = load i32, i32* %5
ret i32 %55
}

LLVM IR (-O2):
define i32 @parse_host_port(i8* %0, i8* %1, i32 %2, i32* nocapture writeonly %3) {
%5 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%6 = icmp eq i8* %5, null
br i1 %6, label %21, label %7
7: ; preds = %4
%8 = ptrtoint i8* %5 to i64
%9 = ptrtoint i8* %0 to i64
%10 = sub i64 %8, %9
%11 = sext i32 %2 to i64
%12 = icmp slt i64 %10, %11
br i1 %12, label %13, label %21
13: ; preds = %7
%14 = trunc i64 %10 to i32
%15 = tail call i32 @memcpy(i8* %1, i8* %0, i32 %14)
%16 = getelementptr inbounds i8, i8* %1, i64 %10
store i8 0, i8* %16
%17 = getelementptr inbounds i8, i8* %5, i64 1
%18 = tail call i32 @strtonum(i8* %17, i32 1, i32 65535, i32* null)
store i32 %18, i32* %3
%19 = icmp eq i32 %18, 0
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %13, %7, %4
%22 = phi i32 [ 1, %4 ], [ 2, %7 ], [ %20, %13 ]
ret i32 %22
}