#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;
typedef int /*<<< orphan*/ host2;

/* 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_message_get_nick_from_host(const char *host) {
  static char nick[128];
  char host2[128], *pos_space, *pos;
  const char *ptr_host;
  if (!host)
    return NULL;
  nick[0] = '\0';
  if (host) {
    ptr_host = host;
    pos_space = strchr(host, ' ');
    if (pos_space) {
      if (pos_space - host < (int)sizeof(host2)) {
        strncpy(host2, host, pos_space - host);
        host2[pos_space - host] = '\0';
      } else
        snprintf(host2, sizeof(host2), "%s", host);
      ptr_host = host2;
    }
    if (ptr_host[0] == ':')
      ptr_host++;
    pos = strchr(ptr_host, '!');
    if (pos && (pos - ptr_host < (int)sizeof(nick))) {
      strncpy(nick, ptr_host, pos - ptr_host);
      nick[pos - ptr_host] = '\0';
    } else {
      snprintf(nick, sizeof(nick), "%s", ptr_host);
    }
  }
  return nick;
}


x86 assembly (clang, -O0):
<irc_message_get_nick_from_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1157 <irc_message_get_nick_from_host+0x27>
movq   $0x0,-0x8(%rbp)
jmp    12f4 <irc_message_get_nick_from_host+0x1c4>
movb   $0x0,0x2ef2(%rip)
cmpq   $0x0,-0x10(%rbp)
je     12e9 <irc_message_get_nick_from_host+0x1b9>
mov    -0x10(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
je     1216 <irc_message_get_nick_from_host+0xe6>
mov    -0x98(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x80,%rax
jge    11ec <irc_message_get_nick_from_host+0xbc>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x98(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x98(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
movb   $0x0,-0x90(%rbp,%rax,1)
jmp    1208 <irc_message_get_nick_from_host+0xd8>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x80,%esi
lea    0xdfd(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0xa8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    123b <irc_message_get_nick_from_host+0x10b>
mov    -0xa8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xa8(%rbp)
mov    -0xa8(%rbp),%rdi
mov    $0x21,%esi
call   1040 <strchr@plt>
mov    %rax,-0xa0(%rbp)
cmpq   $0x0,-0xa0(%rbp)
je     12c5 <irc_message_get_nick_from_host+0x195>
mov    -0xa0(%rbp),%rax
mov    -0xa8(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x80,%rax
jge    12c5 <irc_message_get_nick_from_host+0x195>
mov    -0xa8(%rbp),%rsi
mov    -0xa0(%rbp),%rax
mov    -0xa8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
lea    0x2db1(%rip),%rdi
call   1030 <strncpy@plt>
mov    -0xa0(%rbp),%rcx
mov    -0xa8(%rbp),%rax
sub    %rax,%rcx
lea    0x2d94(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
jmp    12e4 <irc_message_get_nick_from_host+0x1b4>
mov    -0xa8(%rbp),%rcx
lea    0x2d7d(%rip),%rdi
mov    $0x80,%esi
lea    0xd21(%rip),%rdx
call   1050 <snprintf@plt>
jmp    12e9 <irc_message_get_nick_from_host+0x1b9>
lea    0x2d60(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<irc_message_get_nick_from_host>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
test   %rdi,%rdi
je     117f <irc_message_get_nick_from_host+0x4f>
mov    %rdi,%r14
movb   $0x0,0x2f05(%rip)
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11a4 <irc_message_get_nick_from_host+0x74>
mov    %rax,%rbx
sub    %r14,%rbx
cmp    $0x7f,%rbx
jg     1187 <irc_message_get_nick_from_host+0x57>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%rsp,%rbx,1)
mov    %r15,%r14
jmp    11a4 <irc_message_get_nick_from_host+0x74>
xor    %r14d,%r14d
jmp    1208 <irc_message_get_nick_from_host+0xd8>
mov    %rsp,%rbx
lea    0xe6f(%rip),%rdx
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r14,%rcx
call   1050 <snprintf@plt>
mov    %rbx,%r14
xor    %ebx,%ebx
cmpb   $0x3a,(%r14)
sete   %bl
add    %r14,%rbx
mov    %rbx,%rdi
mov    $0x21,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11ea <irc_message_get_nick_from_host+0xba>
mov    %rax,%r15
sub    %rbx,%r15
cmp    $0x7f,%r15
jg     11ea <irc_message_get_nick_from_host+0xba>
lea    0x2e7b(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%r14,1)
jmp    1208 <irc_message_get_nick_from_host+0xd8>
lea    0x2e5f(%rip),%r14
lea    0xe08(%rip),%rdx
mov    %r14,%rdi
mov    $0x80,%esi
mov    %rbx,%rcx
call   1050 <snprintf@plt>
mov    %r14,%rax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@irc_message_get_nick_from_host.nick = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"%s\00"
define i8* @irc_message_get_nick_from_host(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [128 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store i8* null, i8** %2
br label %90
11: ; preds = %1
store i8 0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_message_get_nick_from_host.nick, i64 0, i64 0)
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %89
14: ; preds = %11
%15 = load i8*, i8** %3
store i8* %15, i8** %7
%16 = load i8*, i8** %3
%17 = call i8* @strchr(i8* %16, i8 signext 32)
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %49
20: ; preds = %14
%21 = load i8*, i8** %5
%22 = load i8*, i8** %3
%23 = ptrtoint i8* %21 to i64
%24 = ptrtoint i8* %22 to i64
%25 = sub i64 %23, %24
%26 = icmp slt i64 %25, 128
br i1 %26, label %27, label %43
27: ; preds = %20
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%29 = load i8*, i8** %3
%30 = load i8*, i8** %5
%31 = load i8*, i8** %3
%32 = ptrtoint i8* %30 to i64
%33 = ptrtoint i8* %31 to i64
%34 = sub i64 %32, %33
%35 = trunc i64 %34 to i32
%36 = call i32 @strncpy(i8* %28, i8* %29, i32 %35)
%37 = load i8*, i8** %5
%38 = load i8*, i8** %3
%39 = ptrtoint i8* %37 to i64
%40 = ptrtoint i8* %38 to i64
%41 = sub i64 %39, %40
%42 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 %41
store i8 0, i8* %42
br label %47
43: ; preds = %20
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%45 = load i8*, i8** %3
%46 = call i32 @snprintf(i8* %44, i32 128, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %43, %27
%48 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
store i8* %48, i8** %7
br label %49
49: ; preds = %47, %14
%50 = load i8*, i8** %7
%51 = getelementptr inbounds i8, i8* %50, i64 0
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 58
br i1 %54, label %55, label %58
55: ; preds = %49
%56 = load i8*, i8** %7
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %7
br label %58
58: ; preds = %55, %49
%59 = load i8*, i8** %7
%60 = call i8* @strchr(i8* %59, i8 signext 33)
store i8* %60, i8** %6
%61 = load i8*, i8** %6
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %85
63: ; preds = %58
%64 = load i8*, i8** %6
%65 = load i8*, i8** %7
%66 = ptrtoint i8* %64 to i64
%67 = ptrtoint i8* %65 to i64
%68 = sub i64 %66, %67
%69 = icmp slt i64 %68, 128
br i1 %69, label %70, label %85
70: ; preds = %63
%71 = load i8*, i8** %7
%72 = load i8*, i8** %6
%73 = load i8*, i8** %7
%74 = ptrtoint i8* %72 to i64
%75 = ptrtoint i8* %73 to i64
%76 = sub i64 %74, %75
%77 = trunc i64 %76 to i32
%78 = call i32 @strncpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_message_get_nick_from_host.nick, i64 0, i64 0), i8* %71, i32 %77)
%79 = load i8*, i8** %6
%80 = load i8*, i8** %7
%81 = ptrtoint i8* %79 to i64
%82 = ptrtoint i8* %80 to i64
%83 = sub i64 %81, %82
%84 = getelementptr inbounds [128 x i8], [128 x i8]* @irc_message_get_nick_from_host.nick, i64 0, i64 %83
store i8 0, i8* %84
br label %88
85: ; preds = %63, %58
%86 = load i8*, i8** %7
%87 = call i32 @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_message_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* %86)
br label %88
88: ; preds = %85, %70
br label %89
89: ; preds = %88, %11
store i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_message_get_nick_from_host.nick, i64 0, i64 0), i8** %2
br label %90
90: ; preds = %89, %10
%91 = load i8*, i8** %2
ret i8* %91
}

LLVM IR (-O2):
@irc_message_get_nick_from_host.nick = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"%s\00"
define i8* @irc_message_get_nick_from_host(i8* %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %38, label %5
5: ; preds = %1
store i8 0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_message_get_nick_from_host.nick, i64 0, i64 0)
%6 = tail call i8* @strchr(i8* %0, i8 signext 32)
%7 = icmp eq i8* %6, null
br i1 %7, label %19, label %8
8: ; preds = %5
%9 = ptrtoint i8* %6 to i64
%10 = ptrtoint i8* %0 to i64
%11 = sub i64 %9, %10
%12 = icmp slt i64 %11, 128
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = trunc i64 %11 to i32
%15 = call i32 @strncpy(i8* %3, i8* %0, i32 %14)
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %11
store i8 0, i8* %16
br label %19
17: ; preds = %8
%18 = call i32 @snprintf(i8* %3, i32 128, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %19
19: ; preds = %13, %17, %5
%20 = phi i8* [ %0, %5 ], [ %3, %17 ], [ %3, %13 ]
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 58
%23 = zext i1 %22 to i64
%24 = getelementptr i8, i8* %20, i64 %23
%25 = call i8* @strchr(i8* %24, i8 signext 33)
%26 = icmp eq i8* %25, null
br i1 %26, label %36, label %27
27: ; preds = %19
%28 = ptrtoint i8* %25 to i64
%29 = ptrtoint i8* %24 to i64
%30 = sub i64 %28, %29
%31 = icmp slt i64 %30, 128
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = trunc i64 %30 to i32
%34 = call i32 @strncpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_message_get_nick_from_host.nick, i64 0, i64 0), i8* %24, i32 %33)
%35 = getelementptr inbounds [128 x i8], [128 x i8]* @irc_message_get_nick_from_host.nick, i64 0, i64 %30
store i8 0, i8* %35
br label %38
36: ; preds = %27, %19
%37 = call i32 @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_message_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* %24)
br label %38
38: ; preds = %36, %32, %1
%39 = phi i8* [ null, %1 ], [ getelementptr inbounds ([128 x i8], [128 x i8]* @irc_message_get_nick_from_host.nick, i64 0, i64 0), %32 ], [ getelementptr inbounds ([128 x i8], [128 x i8]* @irc_message_get_nick_from_host.nick, i64 0, i64 0), %36 ]
ret i8* %39
}