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

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char const *, int);
char *strchr(char const *, char);
int strlen(char const *);
void BN_ExtractNick(const char *Prefix, char Nick[], int Length) {
  int p;
  char *buf;
  if (Prefix == NULL) {
    Nick[0] = 0;
    return;
  }
  buf = strchr(Prefix, '!');
  if (buf == NULL)
    p = strlen(Prefix);
  else
    p = buf - Prefix;
  if (p >= Length)
    p = Length - 1;
  memcpy(Nick, Prefix, p);
  Nick[p] = 0;
}


x86 assembly (clang, -O0):
<BN_ExtractNick>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    115a <BN_ExtractNick+0x2a>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    11c7 <BN_ExtractNick+0x97>
mov    -0x8(%rbp),%rdi
mov    $0x21,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1188 <BN_ExtractNick+0x58>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
jmp    1196 <BN_ExtractNick+0x66>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     11ab <BN_ExtractNick+0x7b>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BN_ExtractNick>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
test   %rdi,%rdi
je     117d <BN_ExtractNick+0x4d>
mov    %edx,%r15d
mov    %rdi,%rbx
mov    $0x21,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1158 <BN_ExtractNick+0x28>
sub    %ebx,%eax
jmp    1160 <BN_ExtractNick+0x30>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    -0x1(%r15),%ebp
cmp    %r15d,%eax
cmovl  %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
movslq %ebp,%rax
add    %rax,%r14
movb   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @BN_ExtractNick(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i64 0
store i8 0, i8* %13
br label %45
14: ; preds = %3
%15 = load i8*, i8** %4
%16 = call i8* @strchr(i8* %15, i8 signext 33)
store i8* %16, i8** %8
%17 = load i8*, i8** %8
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %7
br label %29
22: ; preds = %14
%23 = load i8*, i8** %8
%24 = load i8*, i8** %4
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = trunc i64 %27 to i32
store i32 %28, i32* %7
br label %29
29: ; preds = %22, %19
%30 = load i32, i32* %7
%31 = load i32, i32* %6
%32 = icmp sge i32 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32, i32* %6
%35 = sub nsw i32 %34, 1
store i32 %35, i32* %7
br label %36
36: ; preds = %33, %29
%37 = load i8*, i8** %5
%38 = load i8*, i8** %4
%39 = load i32, i32* %7
%40 = call i32 @memcpy(i8* %37, i8* %38, i32 %39)
%41 = load i8*, i8** %5
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 0, i8* %44
br label %45
45: ; preds = %36, %11
ret void
}

LLVM IR (-O2):
define void @BN_ExtractNick(i8* %0, i8* %1, i32 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %23, label %5
5: ; preds = %3
%6 = tail call i8* @strchr(i8* %0, i8 signext 33)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @strlen(i8* %0)
br label %15
10: ; preds = %5
%11 = ptrtoint i8* %6 to i64
%12 = ptrtoint i8* %0 to i64
%13 = sub i64 %11, %12
%14 = trunc i64 %13 to i32
br label %15
15: ; preds = %10, %8
%16 = phi i32 [ %9, %8 ], [ %14, %10 ]
%17 = icmp slt i32 %16, %2
%18 = add nsw i32 %2, -1
%19 = select i1 %17, i32 %16, i32 %18
%20 = tail call i32 @memcpy(i8* %1, i8* %0, i32 %19)
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8, i8* %1, i64 %21
br label %23
23: ; preds = %3, %15
%24 = phi i8* [ %22, %15 ], [ %1, %3 ]
store i8 0, i8* %24
ret void
}