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

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
char *strstr(char const *, char *);
const char *irc_target_host(const char *target) {
  static char buffer[128];
  const char *split = strstr(target, "!");
  if (!split)
    split = target;
  size_t length = strlen(split);
  if (length > sizeof(buffer) - 1)
    length = sizeof(buffer) - 1;
  memcpy(buffer, target, length);
  buffer[length] = '\0';
  return buffer;
}


x86 assembly (clang, -O0):
<irc_target_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1163 <irc_target_host+0x33>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x7f,-0x18(%rbp)
jbe    1183 <irc_target_host+0x53>
movq   $0x7f,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0x2ebe(%rip),%rdi
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rcx
lea    0x2eae(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2ea3(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<irc_target_host>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x21,%esi
call   1040 <strchr@plt>
test   %rax,%rax
cmove  %r14,%rax
mov    %rax,%rdi
call   1030 <strlen@plt>
cmp    $0x7f,%rax
mov    $0x7f,%ebx
cmovb  %rax,%rbx
lea    0x2eeb(%rip),%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
movb   $0x0,(%rbx,%r15,1)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@irc_target_host.buffer = internal global [128 x i8] zeroinitializer
@.str = [2 x i8] c"!\00"
define i8* @irc_target_host(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i8* @strstr(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = load i8*, i8** %2
store i8* %10, i8** %3
br label %11
11: ; preds = %9, %1
%12 = load i8*, i8** %3
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %4
%14 = load i64, i64* %4
%15 = icmp ugt i64 %14, 127
br i1 %15, label %16, label %17
16: ; preds = %11
store i64 127, i64* %4
br label %17
17: ; preds = %16, %11
%18 = load i8*, i8** %2
%19 = load i64, i64* %4
%20 = call i32 @memcpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_target_host.buffer, i64 0, i64 0), i8* %18, i64 %19)
%21 = load i64, i64* %4
%22 = getelementptr inbounds [128 x i8], [128 x i8]* @irc_target_host.buffer, i64 0, i64 %21
store i8 0, i8* %22
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_target_host.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@irc_target_host.buffer = internal global [128 x i8] zeroinitializer
define i8* @irc_target_host(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 33)
%3 = icmp eq i8* %2, null
%4 = select i1 %3, i8* %0, i8* %2
%5 = tail call i64 @strlen(i8* dereferenceable(1) %4)
%6 = icmp ult i64 %5, 127
%7 = select i1 %6, i64 %5, i64 127
%8 = tail call i32 @memcpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_target_host.buffer, i64 0, i64 0), i8* %0, i64 %7)
%9 = getelementptr inbounds [128 x i8], [128 x i8]* @irc_target_host.buffer, i64 0, i64 %7
store i8 0, i8* %9
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_target_host.buffer, i64 0, i64 0)
}