#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 *strchr(char const *, char);
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
unsigned short strtoul(char const *, int /*<<< orphan*/, int /*<<< orphan*/);
void xnet_split_host(const char *ip, char *host, unsigned short *port) {
  const char *pos = 0;
  pos = strchr(ip, ':');
  if (pos != 0) {
    strncpy(host, ip, (pos - ip));
    *port = strtoul(pos + 1, 0, 0);
  } else {
    strcpy(host, ip);
  }
}


x86 assembly (clang, -O0):
<xnet_split_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b3 <xnet_split_host+0x73>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1060 <strtoul@plt>
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
jmp    11c0 <xnet_split_host+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xnet_split_host>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1193 <xnet_split_host+0x53>
mov    %rax,%rbx
mov    %ebx,%edx
sub    %r12d,%edx
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <strncpy@plt>
add    $0x1,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %ax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r15,%rdi
mov    %r12,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <strcpy@plt>

LLVM IR (-O0):
define void @xnet_split_host(i8* %0, i8* %1, i16* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i16*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i16* %2, i16** %6
store i8* null, i8** %7
%8 = load i8*, i8** %4
%9 = call i8* @strchr(i8* %8, i8 signext 58)
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %26
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = load i8*, i8** %4
%15 = load i8*, i8** %7
%16 = load i8*, i8** %4
%17 = ptrtoint i8* %15 to i64
%18 = ptrtoint i8* %16 to i64
%19 = sub i64 %17, %18
%20 = trunc i64 %19 to i32
%21 = call i32 @strncpy(i8* %13, i8* %14, i32 %20)
%22 = load i8*, i8** %7
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = call zeroext i16 @strtoul(i8* %23, i32 0, i32 0)
%25 = load i16*, i16** %6
store i16 %24, i16* %25
br label %30
26: ; preds = %3
%27 = load i8*, i8** %5
%28 = load i8*, i8** %4
%29 = call i32 @strcpy(i8* %27, i8* %28)
br label %30
30: ; preds = %26, %12
ret void
}

LLVM IR (-O2):
define void @xnet_split_host(i8* %0, i8* %1, i16* nocapture writeonly %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%5 = icmp eq i8* %4, null
br i1 %5, label %14, label %6
6: ; preds = %3
%7 = ptrtoint i8* %4 to i64
%8 = ptrtoint i8* %0 to i64
%9 = sub i64 %7, %8
%10 = trunc i64 %9 to i32
%11 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %10)
%12 = getelementptr inbounds i8, i8* %4, i64 1
%13 = tail call zeroext i16 @strtoul(i8* %12, i32 0, i32 0)
store i16 %13, i16* %2
br label %16
14: ; preds = %3
%15 = tail call i32 @strcpy(i8* %1, i8* %0)
br label %16
16: ; preds = %14, %6
ret void
}