#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 *malloc(scalar_t__);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *strrchr(char *, char);
void splitHostPort(char *hostPort, char **hostPart, char **portPart) {
  char *ptr = strrchr(hostPort, ':');
  if (ptr != 0) {
    *ptr++ = '\0';
    *hostPart = malloc(strlen(hostPort) + 1);
    strcpy(*hostPart, hostPort);
  } else {
    ptr = hostPort;
  }
  *portPart = malloc(strlen(ptr) + 1);
  strcpy(*portPart, ptr);
}


x86 assembly (clang, -O0):
<splitHostPort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b7 <splitHostPort+0x77>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11bf <splitHostPort+0x7f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<splitHostPort>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x3a,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     118c <splitHostPort+0x4c>
mov    %rax,%r12
add    $0x1,%r12
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,(%r15)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
define void @splitHostPort(i8* %0, i8** %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8** %2, i8*** %6
%8 = load i8*, i8** %4
%9 = call i8* @strrchr(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 %24
12: ; preds = %3
%13 = load i8*, i8** %7
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %7
store i8 0, i8* %13
%15 = load i8*, i8** %4
%16 = call i64 @strlen(i8* %15)
%17 = add nsw i64 %16, 1
%18 = call i8* @malloc(i64 %17)
%19 = load i8**, i8*** %5
store i8* %18, i8** %19
%20 = load i8**, i8*** %5
%21 = load i8*, i8** %20
%22 = load i8*, i8** %4
%23 = call i32 @strcpy(i8* %21, i8* %22)
br label %26
24: ; preds = %3
%25 = load i8*, i8** %4
store i8* %25, i8** %7
br label %26
26: ; preds = %24, %12
%27 = load i8*, i8** %7
%28 = call i64 @strlen(i8* %27)
%29 = add nsw i64 %28, 1
%30 = call i8* @malloc(i64 %29)
%31 = load i8**, i8*** %6
store i8* %30, i8** %31
%32 = load i8**, i8*** %6
%33 = load i8*, i8** %32
%34 = load i8*, i8** %7
%35 = call i32 @strcpy(i8* %33, i8* %34)
ret void
}

LLVM IR (-O2):
define void @splitHostPort(i8* %0, i8** nocapture writeonly %1, i8** nocapture writeonly %2) {
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 58)
%5 = icmp eq i8* %4, null
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %4, i64 1
store i8 0, i8* %4
%8 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%9 = add nsw i64 %8, 1
%10 = tail call i8* @malloc(i64 %9)
store i8* %10, i8** %1
%11 = tail call i32 @strcpy(i8* %10, i8* %0)
br label %12
12: ; preds = %3, %6
%13 = phi i8* [ %7, %6 ], [ %0, %3 ]
%14 = tail call i64 @strlen(i8* dereferenceable(1) %13)
%15 = add nsw i64 %14, 1
%16 = tail call i8* @malloc(i64 %15)
store i8* %16, i8** %2
%17 = tail call i32 @strcpy(i8* %16, i8* %13)
ret void
}