#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 *strdup(char const *);
scalar_t__ strlen(char const *);
char *url_parse_host(const char *url) {
  char *host = NULL;
  char *ret = NULL;
  int l = (int)strlen(url);
  if (NULL == url) {
    return NULL;
  }
  if ('[' == url[0]) {
    if (']' != url[l - 1]) {
      return NULL;
    } else {
      ret = strdup(url);
      *ret++;
      ret[l - 1] = '\0';
      return ret;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<url_parse_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1161 <url_parse_host+0x41>
movq   $0x0,-0x8(%rbp)
jmp    11df <url_parse_host+0xbf>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x5b,%eax
cmp    %ecx,%eax
jne    11d7 <url_parse_host+0xb7>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x5d,%eax
cmp    %ecx,%eax
je     11a0 <url_parse_host+0x80>
movq   $0x0,-0x8(%rbp)
jmp    11df <url_parse_host+0xbf>
mov    -0x10(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11df <url_parse_host+0xbf>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<url_parse_host>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %rbx,%rbx
je     1157 <url_parse_host+0x37>
cmpb   $0x5b,(%rbx)
jne    1157 <url_parse_host+0x37>
add    $0xffffffff,%eax
movslq %eax,%r14
cmpb   $0x5d,(%rbx,%r14,1)
jne    1157 <url_parse_host+0x37>
mov    %rbx,%rdi
call   1040 <strdup@plt>
movb   $0x0,0x1(%rax,%r14,1)
add    $0x1,%rax
jmp    1159 <url_parse_host+0x39>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define noalias i8* @url_parse_host(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp eq i8* %0, null
br i1 %3, label %18, label %4
4: ; preds = %1
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 91
br i1 %6, label %7, label %18
7: ; preds = %4
%8 = shl i64 %2, 32
%9 = add i64 %8, -4294967296
%10 = ashr exact i64 %9, 32
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 93
br i1 %13, label %14, label %18
14: ; preds = %7
%15 = tail call i8* @strdup(i8* %0)
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = getelementptr inbounds i8, i8* %16, i64 %10
store i8 0, i8* %17
br label %18
18: ; preds = %4, %7, %1, %14
%19 = phi i8* [ %16, %14 ], [ null, %1 ], [ null, %7 ], [ null, %4 ]
ret i8* %19
}