#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 *, char);
char *strdup(char *);
int strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int split_host_port(char *input, int default_port, char **host, int *port) {
  char *p;
  *host = strdup(input);
  if ((p = strchr(*host, ':'))) {
    *port = strtol(p + 1, NULL, 0);
    *p = 0;
  } else {
    *port = default_port;
  }
  return 1;
}


x86 assembly (clang, -O0):
<split_host_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11a0 <split_host_port+0x70>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
jmp    11a9 <split_host_port+0x79>
mov    -0xc(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_host_port>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%rbx
mov    %rdx,%rbp
mov    %esi,%r14d
call   1050 <strdup@plt>
mov    %rax,0x0(%rbp)
mov    %rax,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1173 <split_host_port+0x43>
mov    %rax,%rbp
mov    %rax,%rdi
add    $0x1,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,(%rbx)
movb   $0x0,0x0(%rbp)
jmp    1176 <split_host_port+0x46>
mov    %r14d,(%rbx)
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @split_host_port(i8* %0, i32 %1, i8** %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
store i32* %3, i32** %8
%10 = load i8*, i8** %5
%11 = call i8* @strdup(i8* %10)
%12 = load i8**, i8*** %7
store i8* %11, i8** %12
%13 = load i8**, i8*** %7
%14 = load i8*, i8** %13
%15 = call i8* @strchr(i8* %14, i8 signext 58)
store i8* %15, i8** %9
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %23
17: ; preds = %4
%18 = load i8*, i8** %9
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = call i32 @strtol(i8* %19, i32* null, i32 0)
%21 = load i32*, i32** %8
store i32 %20, i32* %21
%22 = load i8*, i8** %9
store i8 0, i8* %22
br label %26
23: ; preds = %4
%24 = load i32, i32* %6
%25 = load i32*, i32** %8
store i32 %24, i32* %25
br label %26
26: ; preds = %23, %17
ret i32 1
}

LLVM IR (-O2):
define i32 @split_host_port(i8* nocapture %0, i32 %1, i8** nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = tail call i8* @strdup(i8* %0)
store i8* %5, i8** %2
%6 = tail call i8* @strchr(i8* dereferenceable(1) %5, i8 signext 58)
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %6, i64 1
%10 = tail call i32 @strtol(i8* nocapture %9, i32* null, i32 0)
store i32 %10, i32* %3
store i8 0, i8* %6
br label %12
11: ; preds = %4
store i32 %1, i32* %3
br label %12
12: ; preds = %11, %8
ret i32 1
}