#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);
void parse_addr(char *addr, char **host, char **port) {
  char *p;
  p = strchr(addr, ':');
  if (p) {
    *p++ = 0;
    *host = *addr ? addr : NULL;
    *port = *p ? p : NULL;
  } else {
    *host = NULL;
    *port = addr;
  }
}


x86 assembly (clang, -O0):
<parse_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11be <parse_addr+0xae>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1170 <parse_addr+0x60>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    117b <parse_addr+0x6b>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    117b <parse_addr+0x6b>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a3 <parse_addr+0x93>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11ae <parse_addr+0x9e>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    11ae <parse_addr+0x9e>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    11d4 <parse_addr+0xc4>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_addr>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1150 <parse_addr+0x40>
mov    %rax,%rcx
add    $0x1,%rcx
movb   $0x0,(%rax)
xor    %edx,%edx
cmpb   $0x0,(%rbx)
cmove  %rdx,%rbx
mov    %rbx,(%r15)
cmpb   $0x0,0x1(%rax)
cmove  %rdx,%rcx
mov    %rcx,%rbx
jmp    1157 <parse_addr+0x47>
movq   $0x0,(%r15)
mov    %rbx,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @parse_addr(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* @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 %35
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 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = load i8*, i8** %4
br label %22
21: ; preds = %12
br label %22
22: ; preds = %21, %19
%23 = phi i8* [ %20, %19 ], [ null, %21 ]
%24 = load i8**, i8*** %5
store i8* %23, i8** %24
%25 = load i8*, i8** %7
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = load i8*, i8** %7
br label %32
31: ; preds = %22
br label %32
32: ; preds = %31, %29
%33 = phi i8* [ %30, %29 ], [ null, %31 ]
%34 = load i8**, i8*** %6
store i8* %33, i8** %34
br label %39
35: ; preds = %3
%36 = load i8**, i8*** %5
store i8* null, i8** %36
%37 = load i8*, i8** %4
%38 = load i8**, i8*** %6
store i8* %37, i8** %38
br label %39
39: ; preds = %35, %32
ret void
}

LLVM IR (-O2):
define void @parse_addr(i8* %0, i8** nocapture writeonly %1, i8** 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 = getelementptr inbounds i8, i8* %4, i64 1
store i8 0, i8* %4
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 0
%10 = select i1 %9, i8* null, i8* %0
store i8* %10, i8** %1
%11 = load i8, i8* %7
%12 = icmp eq i8 %11, 0
%13 = select i1 %12, i8* null, i8* %7
br label %15
14: ; preds = %3
store i8* null, i8** %1
br label %15
15: ; preds = %14, %6
%16 = phi i8* [ %0, %14 ], [ %13, %6 ]
store i8* %16, i8** %2
ret void
}