#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 *, int);
char *strchr(char const *, char);
void BN_ExtractExactUserName(const char *Prefix, char UserName[], int Length) {
  int p;
  char *buf, *buf2;
  if (Prefix == NULL) {
    UserName[0] = 0;
    return;
  }
  buf = strchr(Prefix, '!');
  buf2 = strchr(Prefix, '@');
  if ((buf == NULL) || (buf2 == NULL)) {
    UserName[0] = 0;
    return;
  }
  p = buf2 - buf - 1;
  if (p >= Length)
    p = Length - 1;
  memcpy(UserName, buf + 1, p);
  UserName[p] = 0;
}


x86 assembly (clang, -O0):
<BN_ExtractExactUserName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    114a <BN_ExtractExactUserName+0x2a>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    11d7 <BN_ExtractExactUserName+0xb7>
mov    -0x8(%rbp),%rdi
mov    $0x21,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x40,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1184 <BN_ExtractExactUserName+0x64>
cmpq   $0x0,-0x28(%rbp)
jne    1190 <BN_ExtractExactUserName+0x70>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    11d7 <BN_ExtractExactUserName+0xb7>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     11b7 <BN_ExtractExactUserName+0x97>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    -0x18(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BN_ExtractExactUserName>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
test   %rdi,%rdi
je     1182 <BN_ExtractExactUserName+0x62>
mov    %edx,%r14d
mov    %rdi,%rbx
mov    $0x21,%esi
call   1030 <strchr@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    $0x40,%esi
call   1030 <strchr@plt>
test   %r12,%r12
je     1182 <BN_ExtractExactUserName+0x62>
test   %rax,%rax
je     1182 <BN_ExtractExactUserName+0x62>
mov    %r12d,%ecx
not    %ecx
add    %ecx,%eax
lea    -0x1(%r14),%ebx
cmp    %r14d,%eax
cmovl  %eax,%ebx
add    $0x1,%r12
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
movslq %ebx,%rax
add    %rax,%r15
movb   $0x0,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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