#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 atoi(char *);
char *strchr(char *, char);
char *strdup(char *);
int splithp(char *arg, char **host, int *port) {
  char *tmp = strchr(arg, ':');
  if (!tmp)
    return (1);
  *tmp = 0;
  if (port)
    *port = atoi(tmp + 1);
  if (host) {
    if (arg == tmp)
      *host = strdup("localhost");
    else
      *host = strdup(arg);
  }
  *tmp = ':';
  return (0);
}


x86 assembly (clang, -O0):
<splithp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    116d <splithp+0x3d>
movl   $0x1,-0x4(%rbp)
jmp    11ee <splithp+0xbe>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     1194 <splithp+0x64>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     11e0 <splithp+0xb0>
mov    -0x10(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    11c8 <splithp+0x98>
lea    0xe4c(%rip),%rdi
call   1050 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    11db <splithp+0xab>
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    11e0 <splithp+0xb0>
mov    -0x28(%rbp),%rax
movb   $0x3a,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<splithp>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1177 <splithp+0x47>
mov    %rax,%rbx
movb   $0x0,(%rax)
test   %r12,%r12
je     1168 <splithp+0x38>
lea    0x1(%rbx),%rdi
call   1040 <atoi@plt>
mov    %eax,(%r12)
test   %r14,%r14
je     118d <splithp+0x5d>
cmp    %r15,%rbx
je     117e <splithp+0x4e>
mov    %r15,%rdi
jmp    1185 <splithp+0x55>
mov    $0x1,%eax
jmp    1192 <splithp+0x62>
lea    0xe7b(%rip),%rdi
call   1050 <strdup@plt>
mov    %rax,(%r14)
movb   $0x3a,(%rbx)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"localhost\00"
define i32 @splithp(i8* %0, i8** writeonly %1, i32* writeonly %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%5 = icmp eq i8* %4, null
br i1 %5, label %22, label %6
6: ; preds = %3
store i8 0, i8* %4
%7 = icmp eq i32* %2, null
br i1 %7, label %11, label %8
8: ; preds = %6
%9 = getelementptr inbounds i8, i8* %4, i64 1
%10 = tail call i32 @atoi(i8* %9)
store i32 %10, i32* %2
br label %11
11: ; preds = %8, %6
%12 = icmp eq i8** %1, null
br i1 %12, label %21, label %13
13: ; preds = %11
%14 = icmp eq i8* %4, %0
br i1 %14, label %15, label %17
15: ; preds = %13
%16 = tail call dereferenceable_or_null(10) i8* @strdup(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %19
17: ; preds = %13
%18 = tail call i8* @strdup(i8* %0)
br label %19
19: ; preds = %17, %15
%20 = phi i8* [ %16, %15 ], [ %18, %17 ]
store i8* %20, i8** %1
br label %21
21: ; preds = %19, %11
store i8 58, i8* %4
br label %22
22: ; preds = %3, %21
%23 = phi i32 [ 0, %21 ], [ 1, %3 ]
ret i32 %23
}