#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 */
scalar_t__ calloc(int, int);
scalar_t__ get_protocol(char const *);
char *index(char const *, char);
size_t strlen(scalar_t__);
int /*<<< orphan*/ strncpy(char *, char const *, int);
const char *get_host(const char *url) {
  size_t proto_len = 0;
  if (get_protocol(url))
    proto_len = strlen(get_protocol(url));
  url = url + proto_len;
  const char *first_slash = index(url, '/');
  if (!first_slash) {
    return url;
  } else {
    char *host = (char *)calloc(1024, sizeof(char));
    strncpy(host, url, first_slash - url);
    return host;
  }
}


x86 assembly (clang, -O0):
<get_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <get_protocol@plt>
cmp    $0x0,%rax
je     118c <get_host+0x3c>
mov    -0x10(%rbp),%rdi
call   1070 <get_protocol@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <index@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c2 <get_host+0x72>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f7 <get_host+0xa7>
mov    $0x400,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_host>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1070 <get_protocol@plt>
test   %rax,%rax
je     1174 <get_host+0x24>
mov    %rbx,%rdi
call   1070 <get_protocol@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
jmp    1176 <get_host+0x26>
xor    %eax,%eax
add    %rax,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <index@plt>
test   %rax,%rax
je     11b4 <get_host+0x64>
mov    %rax,%r14
mov    $0x400,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
sub    %ebx,%r14d
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <strncpy@plt>
mov    %r15,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @get_host(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i64 0, i64* %4
%7 = load i8*, i8** %3
%8 = call i64 @get_protocol(i8* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i64 @get_protocol(i8* %11)
%13 = call i64 @strlen(i64 %12)
store i64 %13, i64* %4
br label %14
14: ; preds = %10, %1
%15 = load i8*, i8** %3
%16 = load i64, i64* %4
%17 = getelementptr inbounds i8, i8* %15, i64 %16
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = call i8* @index(i8* %18, i8 signext 47)
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = icmp ne i8* %20, null
br i1 %21, label %24, label %22
22: ; preds = %14
%23 = load i8*, i8** %3
store i8* %23, i8** %2
br label %37
24: ; preds = %14
%25 = call i64 @calloc(i32 1024, i32 1)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %6
%27 = load i8*, i8** %6
%28 = load i8*, i8** %3
%29 = load i8*, i8** %5
%30 = load i8*, i8** %3
%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)
%36 = load i8*, i8** %6
store i8* %36, i8** %2
br label %37
37: ; preds = %24, %22
%38 = load i8*, i8** %2
ret i8* %38
}

LLVM IR (-O2):
define i8* @get_host(i8* %0) {
%2 = tail call i64 @get_protocol(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call i64 @get_protocol(i8* %0)
%6 = tail call i64 @strlen(i64 %5)
br label %7
7: ; preds = %4, %1
%8 = phi i64 [ %6, %4 ], [ 0, %1 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = tail call i8* @index(i8* %9, i8 signext 47)
%11 = icmp eq i8* %10, null
br i1 %11, label %20, label %12
12: ; preds = %7
%13 = tail call i64 @calloc(i32 1024, i32 1)
%14 = inttoptr i64 %13 to i8*
%15 = ptrtoint i8* %10 to i64
%16 = ptrtoint i8* %9 to i64
%17 = sub i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = tail call i32 @strncpy(i8* %14, i8* %9, i32 %18)
br label %20
20: ; preds = %7, %12
%21 = phi i8* [ %14, %12 ], [ %9, %7 ]
ret i8* %21
}