#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*/ nick;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
char *strchr(char const *, char);
int /*<<< orphan*/ strncpy(char *, char const *, int);
const char *irc_protocol_get_nick_from_host(const char *host) {
  static char nick[128];
  char *pos;
  if (!host)
    return NULL;
  nick[0] = '\0';
  if (host) {
    if (host[0] == ':')
      host++;
    pos = strchr(host, '!');
    if (pos && (pos - host < (int)sizeof(nick))) {
      strncpy(nick, host, pos - host);
      nick[pos - host] = '\0';
    } else
      snprintf(nick, sizeof(nick), "%s", host);
  }
  return nick;
}


x86 assembly (clang, -O0):
<irc_protocol_get_nick_from_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1154 <irc_protocol_get_nick_from_host+0x24>
movq   $0x0,-0x8(%rbp)
jmp    121a <irc_protocol_get_nick_from_host+0xea>
movb   $0x0,0x2ef5(%rip)
cmpq   $0x0,-0x10(%rbp)
je     120f <irc_protocol_get_nick_from_host+0xdf>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1182 <irc_protocol_get_nick_from_host+0x52>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x21,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ee <irc_protocol_get_nick_from_host+0xbe>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x80,%rax
jge    11ee <irc_protocol_get_nick_from_host+0xbe>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
lea    0x2e82(%rip),%rdi
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rax,%rcx
lea    0x2e6b(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
jmp    120a <irc_protocol_get_nick_from_host+0xda>
mov    -0x10(%rbp),%rcx
lea    0x2e57(%rip),%rdi
mov    $0x80,%esi
lea    0xdfb(%rip),%rdx
call   1050 <snprintf@plt>
jmp    120f <irc_protocol_get_nick_from_host+0xdf>
lea    0x2e3a(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<irc_protocol_get_nick_from_host>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     11a6 <irc_protocol_get_nick_from_host+0x76>
movb   $0x0,0x2f0f(%rip)
xor    %ebx,%ebx
cmpb   $0x3a,(%rdi)
sete   %bl
add    %rdi,%rbx
mov    %rbx,%rdi
mov    $0x21,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1186 <irc_protocol_get_nick_from_host+0x56>
mov    %rax,%r15
sub    %rbx,%r15
cmp    $0x7f,%r15
jg     1186 <irc_protocol_get_nick_from_host+0x56>
lea    0x2edf(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%r14,1)
jmp    11a9 <irc_protocol_get_nick_from_host+0x79>
lea    0x2ec3(%rip),%r14
lea    0xe6c(%rip),%rdx
mov    %r14,%rdi
mov    $0x80,%esi
mov    %rbx,%rcx
call   1050 <snprintf@plt>
jmp    11a9 <irc_protocol_get_nick_from_host+0x79>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@irc_protocol_get_nick_from_host.nick = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"%s\00"
define i8* @irc_protocol_get_nick_from_host(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
store i8* null, i8** %2
br label %52
8: ; preds = %1
store i8 0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_protocol_get_nick_from_host.nick, i64 0, i64 0)
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %51
11: ; preds = %8
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 58
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %3
br label %20
20: ; preds = %17, %11
%21 = load i8*, i8** %3
%22 = call i8* @strchr(i8* %21, i8 signext 33)
store i8* %22, i8** %4
%23 = load i8*, i8** %4
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %47
25: ; preds = %20
%26 = load i8*, i8** %4
%27 = load i8*, i8** %3
%28 = ptrtoint i8* %26 to i64
%29 = ptrtoint i8* %27 to i64
%30 = sub i64 %28, %29
%31 = icmp slt i64 %30, 128
br i1 %31, label %32, label %47
32: ; preds = %25
%33 = load i8*, i8** %3
%34 = load i8*, i8** %4
%35 = load i8*, i8** %3
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = trunc i64 %38 to i32
%40 = call i32 @strncpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_protocol_get_nick_from_host.nick, i64 0, i64 0), i8* %33, i32 %39)
%41 = load i8*, i8** %4
%42 = load i8*, i8** %3
%43 = ptrtoint i8* %41 to i64
%44 = ptrtoint i8* %42 to i64
%45 = sub i64 %43, %44
%46 = getelementptr inbounds [128 x i8], [128 x i8]* @irc_protocol_get_nick_from_host.nick, i64 0, i64 %45
store i8 0, i8* %46
br label %50
47: ; preds = %25, %20
%48 = load i8*, i8** %3
%49 = call i32 @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_protocol_get_nick_from_host.nick, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %47, %32
br label %51
51: ; preds = %50, %8
store i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_protocol_get_nick_from_host.nick, i64 0, i64 0), i8** %2
br label %52
52: ; preds = %51, %7
%53 = load i8*, i8** %2
ret i8* %53
}

LLVM IR (-O2):
@irc_protocol_get_nick_from_host.nick = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"%s\00"
define i8* @irc_protocol_get_nick_from_host(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %21, label %3
3: ; preds = %1
store i8 0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_protocol_get_nick_from_host.nick, i64 0, i64 0)
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 58
%6 = zext i1 %5 to i64
%7 = getelementptr i8, i8* %0, i64 %6
%8 = tail call i8* @strchr(i8* %7, i8 signext 33)
%9 = icmp eq i8* %8, null
br i1 %9, label %19, label %10
10: ; preds = %3
%11 = ptrtoint i8* %8 to i64
%12 = ptrtoint i8* %7 to i64
%13 = sub i64 %11, %12
%14 = icmp slt i64 %13, 128
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = trunc i64 %13 to i32
%17 = tail call i32 @strncpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_protocol_get_nick_from_host.nick, i64 0, i64 0), i8* %7, i32 %16)
%18 = getelementptr inbounds [128 x i8], [128 x i8]* @irc_protocol_get_nick_from_host.nick, i64 0, i64 %13
store i8 0, i8* %18
br label %21
19: ; preds = %10, %3
%20 = tail call i32 @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_protocol_get_nick_from_host.nick, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %21
21: ; preds = %19, %15, %1
%22 = phi i8* [ null, %1 ], [ getelementptr inbounds ([128 x i8], [128 x i8]* @irc_protocol_get_nick_from_host.nick, i64 0, i64 0), %15 ], [ getelementptr inbounds ([128 x i8], [128 x i8]* @irc_protocol_get_nick_from_host.nick, i64 0, i64 0), %19 ]
ret i8* %22
}