#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(size_t);
size_t strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
char *build_host_port(const char *host, const char *port) {
  size_t host_len = strlen(host);
  size_t port_len = strlen(port);
  size_t result_len = host_len + port_len + 2;
  char *result = malloc(result_len * sizeof(char));
  if (result == NULL) {
    return NULL;
  }
  strncpy(result, host, host_len);
  result[host_len] = ':';
  strncpy(result + host_len + 1, port, port_len);
  result[host_len + port_len + 1] = '\0';
  return result;
}


x86 assembly (clang, -O0):
<build_host_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
shl    $0x0,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1193 <build_host_port+0x63>
movq   $0x0,-0x8(%rbp)
jmp    11e2 <build_host_port+0xb2>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x3a,(%rax,%rcx,1)
mov    -0x38(%rbp),%rdi
add    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    -0x28(%rbp),%rcx
movb   $0x0,0x1(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_host_port>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %rax,%r13
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
lea    (%rax,%r13,1),%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     119a <build_host_port+0x6a>
mov    %r12,%rbp
add    %r13,%rbp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1030 <strncpy@plt>
movb   $0x3a,(%rbx,%r13,1)
lea    (%rbx,%r13,1),%rdi
add    $0x1,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1030 <strncpy@plt>
movb   $0x0,0x1(%rbp,%rbx,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @build_host_port(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %6
%12 = load i8*, i8** %5
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %7
%14 = load i64, i64* %6
%15 = load i64, i64* %7
%16 = add i64 %14, %15
%17 = add i64 %16, 2
store i64 %17, i64* %8
%18 = load i64, i64* %8
%19 = mul i64 %18, 1
%20 = call i8* @malloc(i64 %19)
store i8* %20, i8** %9
%21 = load i8*, i8** %9
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %2
store i8* null, i8** %3
br label %46
24: ; preds = %2
%25 = load i8*, i8** %9
%26 = load i8*, i8** %4
%27 = load i64, i64* %6
%28 = call i32 @strncpy(i8* %25, i8* %26, i64 %27)
%29 = load i8*, i8** %9
%30 = load i64, i64* %6
%31 = getelementptr inbounds i8, i8* %29, i64 %30
store i8 58, i8* %31
%32 = load i8*, i8** %9
%33 = load i64, i64* %6
%34 = getelementptr inbounds i8, i8* %32, i64 %33
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8*, i8** %5
%37 = load i64, i64* %7
%38 = call i32 @strncpy(i8* %35, i8* %36, i64 %37)
%39 = load i8*, i8** %9
%40 = load i64, i64* %6
%41 = load i64, i64* %7
%42 = add i64 %40, %41
%43 = add i64 %42, 1
%44 = getelementptr inbounds i8, i8* %39, i64 %43
store i8 0, i8* %44
%45 = load i8*, i8** %9
store i8* %45, i8** %3
br label %46
46: ; preds = %24, %23
%47 = load i8*, i8** %3
ret i8* %47
}

LLVM IR (-O2):
define i8* @build_host_port(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = add i64 %4, %3
%6 = add i64 %5, 2
%7 = tail call i8* @malloc(i64 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %16, label %9
9: ; preds = %2
%10 = tail call i32 @strncpy(i8* %7, i8* %0, i64 %3)
%11 = getelementptr inbounds i8, i8* %7, i64 %3
store i8 58, i8* %11
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = tail call i32 @strncpy(i8* %12, i8* %1, i64 %4)
%14 = add i64 %5, 1
%15 = getelementptr inbounds i8, i8* %7, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %2, %9
ret i8* %7
}