#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 */
typedef int /*<<< orphan*/ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ atoi(char *);
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
int /*<<< orphan*/ zfree(char *);
char *zstrdup(char const *);
int parseipandport(const char *addr, char *ip, size_t len, uint16_t *port) {
  char *temp = zstrdup(addr);
  char *sep = strchr(temp, ':');
  if (sep) {
    *sep = 0;
    strncpy(ip, temp, len);
    sep++;
    *port = atoi(sep);
  } else {
    strncpy(ip, temp, len);
    *port = 0;
  }
  zfree(temp);
  return 0;
}


x86 assembly (clang, -O0):
<parseipandport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <zstrdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11cc <parseipandport+0x7c>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    11e7 <parseipandport+0x97>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
call   1060 <zfree@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseipandport>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
call   1070 <zstrdup@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     119e <parseipandport+0x4e>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1030 <strncpy@plt>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1050 <atoi@plt>
jmp    11ae <parseipandport+0x5e>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1030 <strncpy@plt>
xor    %eax,%eax
mov    %eax,(%r14)
mov    %r13,%rdi
call   1060 <zfree@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @parseipandport(i8* %0, i8* %1, i64 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32* %3, i32** %8
%11 = load i8*, i8** %5
%12 = call i8* @zstrdup(i8* %11)
store i8* %12, i8** %9
%13 = load i8*, i8** %9
%14 = call i8* @strchr(i8* %13, i8 signext 58)
store i8* %14, i8** %10
%15 = load i8*, i8** %10
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %28
17: ; preds = %4
%18 = load i8*, i8** %10
store i8 0, i8* %18
%19 = load i8*, i8** %6
%20 = load i8*, i8** %9
%21 = load i64, i64* %7
%22 = call i32 @strncpy(i8* %19, i8* %20, i64 %21)
%23 = load i8*, i8** %10
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %10
%25 = load i8*, i8** %10
%26 = call i32 @atoi(i8* %25)
%27 = load i32*, i32** %8
store i32 %26, i32* %27
br label %34
28: ; preds = %4
%29 = load i8*, i8** %6
%30 = load i8*, i8** %9
%31 = load i64, i64* %7
%32 = call i32 @strncpy(i8* %29, i8* %30, i64 %31)
%33 = load i32*, i32** %8
store i32 0, i32* %33
br label %34
34: ; preds = %28, %17
%35 = load i8*, i8** %9
%36 = call i32 @zfree(i8* %35)
ret i32 0
}

LLVM IR (-O2):
define i32 @parseipandport(i8* %0, i8* %1, i64 %2, i32* nocapture writeonly %3) {
%5 = tail call i8* @zstrdup(i8* %0)
%6 = tail call i8* @strchr(i8* dereferenceable(1) %5, i8 signext 58)
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %4
store i8 0, i8* %6
%9 = tail call i32 @strncpy(i8* %1, i8* %5, i64 %2)
%10 = getelementptr inbounds i8, i8* %6, i64 1
%11 = tail call i32 @atoi(i8* %10)
br label %14
12: ; preds = %4
%13 = tail call i32 @strncpy(i8* %1, i8* %5, i64 %2)
br label %14
14: ; preds = %12, %8
%15 = phi i32 [ 0, %12 ], [ %11, %8 ]
store i32 %15, i32* %3
%16 = tail call i32 @zfree(i8* %5)
ret i32 0
}