#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 *calloc(int, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *gethost(const char *ep) {
  const char *p;
  for (p = ep; *p != ':'; p++)
    ;
  char *host = calloc(p - ep + 1, sizeof(char));
  if (host) {
    strncpy(host, ep, p - ep);
  }
  return host;
}


x86 assembly (clang, -O0):
<gethost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     115a <gethost+0x3a>
jmp    1149 <gethost+0x29>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1134 <gethost+0x14>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119e <gethost+0x7e>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethost>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
cmpb   $0x3a,(%r14,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1130 <gethost+0x10>
mov    %ebx,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     1160 <gethost+0x40>
add    $0xffffffffffffffff,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @gethost(i8* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %6, %2 ]
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 58
%6 = getelementptr inbounds i8, i8* %3, i64 1
br i1 %5, label %7, label %2
7: ; preds = %2
%8 = ptrtoint i8* %3 to i64
%9 = ptrtoint i8* %0 to i64
%10 = sub i64 %8, %9
%11 = trunc i64 %10 to i32
%12 = add i32 %11, 1
%13 = tail call i8* @calloc(i32 %12, i32 1)
%14 = icmp eq i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %7
%16 = tail call i32 @strncpy(i8* %13, i8* %0, i32 %11)
br label %17
17: ; preds = %15, %7
ret i8* %13
}