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

/* 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_address_from_host(const char *host) {
  static char address[256];
  char host2[256], *pos_space, *pos;
  const char *ptr_host;
  address[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)
      snprintf(address, sizeof(address), "%s", pos + 1);
    else
      snprintf(address, sizeof(address), "%s", ptr_host);
  }
  return address;
}


x86 assembly (clang, -O0):
<irc_message_get_address_from_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,0x2f0a(%rip)
cmpq   $0x0,-0x8(%rbp)
je     1295 <irc_message_get_address_from_host+0x165>
mov    -0x8(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     11fe <irc_message_get_address_from_host+0xce>
mov    -0x118(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x100,%rax
jge    11d4 <irc_message_get_address_from_host+0xa4>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x118(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x118(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
movb   $0x0,-0x110(%rbp,%rax,1)
jmp    11f0 <irc_message_get_address_from_host+0xc0>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x100,%esi
lea    0xe15(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1223 <irc_message_get_address_from_host+0xf3>
mov    -0x128(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rdi
mov    $0x21,%esi
call   1040 <strchr@plt>
mov    %rax,-0x120(%rbp)
cmpq   $0x0,-0x120(%rbp)
je     1271 <irc_message_get_address_from_host+0x141>
mov    -0x120(%rbp),%rcx
add    $0x1,%rcx
lea    0x2df5(%rip),%rdi
mov    $0x100,%esi
lea    0xd99(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1290 <irc_message_get_address_from_host+0x160>
mov    -0x128(%rbp),%rcx
lea    0x2dd1(%rip),%rdi
mov    $0x100,%esi
lea    0xd75(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1295 <irc_message_get_address_from_host+0x165>
lea    0x2db4(%rip),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<irc_message_get_address_from_host>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
movb   $0x0,0x2f0b(%rip)
test   %rdi,%rdi
je     11e4 <irc_message_get_address_from_host+0xb4>
mov    %rdi,%r12
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11a7 <irc_message_get_address_from_host+0x77>
mov    %rax,%r14
sub    %r12,%r14
cmp    $0xff,%r14
jg     118a <irc_message_get_address_from_host+0x5a>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%rsp,%r14,1)
mov    %r15,%r12
jmp    11a7 <irc_message_get_address_from_host+0x77>
mov    %rsp,%r14
lea    0xe6c(%rip),%rdx
mov    %r14,%rdi
mov    $0x100,%esi
mov    %r12,%rcx
call   1050 <snprintf@plt>
mov    %r14,%r12
xor    %ebx,%ebx
cmpb   $0x3a,(%r12)
sete   %bl
add    %r12,%rbx
mov    %rbx,%rdi
mov    $0x21,%esi
call   1040 <strchr@plt>
lea    0x1(%rax),%rcx
test   %rax,%rax
cmove  %rbx,%rcx
lea    0x2e7d(%rip),%rdi
lea    0xe26(%rip),%rdx
mov    $0x100,%esi
call   1050 <snprintf@plt>
lea    0x2e65(%rip),%rax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@irc_message_get_address_from_host.address = internal global [256 x i8] zeroinitializer
@.str = [3 x i8] c"%s\00"
define i8* @irc_message_get_address_from_host(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
store i8 0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @irc_message_get_address_from_host.address, i64 0, i64 0)
%4 = icmp eq i8* %0, null
br i1 %4, label %30, label %5
5: ; preds = %1
%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, 256
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 [256 x i8], [256 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 256, 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
%27 = getelementptr inbounds i8, i8* %25, i64 1
%28 = select i1 %26, i8* %24, i8* %27
%29 = call i32 @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @irc_message_get_address_from_host.address, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %19, %1
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @irc_message_get_address_from_host.address, i64 0, i64 0)
}