#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_nick(const char *target) {
  static char buffer[128];
  char *split = strstr(target, "!");
  size_t length = split ? (size_t)(split - target) : strlen(target);
  if (length > sizeof(buffer) - 1)
    length = sizeof(buffer) - 1;
  memcpy(buffer, target, length);
  buffer[length] = '\0';
  return buffer;
}


x86 assembly (clang, -O0):
<irc_target_nick>:
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)
je     116f <irc_target_nick+0x3f>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    117c <irc_target_nick+0x4c>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x7f,-0x18(%rbp)
jbe    1197 <irc_target_nick+0x67>
movq   $0x7f,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0x2eaa(%rip),%rdi
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rcx
lea    0x2e9a(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e8f(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<irc_target_nick>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x21,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     114c <irc_target_nick+0x1c>
sub    %r14,%rax
jmp    1154 <irc_target_nick+0x24>
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    $0x7f,%rax
mov    $0x7f,%ebx
cmovb  %rax,%rbx
lea    0x2ee8(%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_nick.buffer = internal global [128 x i8] zeroinitializer
@.str = [2 x i8] c"!\00"
define i8* @irc_target_nick(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 %9, label %15
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i8*, i8** %2
%12 = ptrtoint i8* %10 to i64
%13 = ptrtoint i8* %11 to i64
%14 = sub i64 %12, %13
br label %18
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = call i64 @strlen(i8* %16)
br label %18
18: ; preds = %15, %9
%19 = phi i64 [ %14, %9 ], [ %17, %15 ]
store i64 %19, i64* %4
%20 = load i64, i64* %4
%21 = icmp ugt i64 %20, 127
br i1 %21, label %22, label %23
22: ; preds = %18
store i64 127, i64* %4
br label %23
23: ; preds = %22, %18
%24 = load i8*, i8** %2
%25 = load i64, i64* %4
%26 = call i32 @memcpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_target_nick.buffer, i64 0, i64 0), i8* %24, i64 %25)
%27 = load i64, i64* %4
%28 = getelementptr inbounds [128 x i8], [128 x i8]* @irc_target_nick.buffer, i64 0, i64 %27
store i8 0, i8* %28
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_target_nick.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@irc_target_nick.buffer = internal global [128 x i8] zeroinitializer
define i8* @irc_target_nick(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 33)
%3 = icmp eq i8* %2, null
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = ptrtoint i8* %2 to i64
%6 = ptrtoint i8* %0 to i64
%7 = sub i64 %5, %6
br label %10
8: ; preds = %1
%9 = tail call i64 @strlen(i8* dereferenceable(1) %0)
br label %10
10: ; preds = %8, %4
%11 = phi i64 [ %7, %4 ], [ %9, %8 ]
%12 = icmp ult i64 %11, 127
%13 = select i1 %12, i64 %11, i64 127
%14 = tail call i32 @memcpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_target_nick.buffer, i64 0, i64 0), i8* %0, i64 %13)
%15 = getelementptr inbounds [128 x i8], [128 x i8]* @irc_target_nick.buffer, i64 0, i64 %13
store i8 0, i8* %15
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @irc_target_nick.buffer, i64 0, i64 0)
}