const char *get_nick(const char *prefix) {
  static char nick[32];
  if (prefix) {
    char *e = strchr(prefix, '!');
    if (e)
      *e = 0;
    snprintf(nick, sizeof(nick), "%.*s", (int)(e - prefix), prefix);
  } else {
    *nick = 0;
  }
  return nick;
}


x86 assembly (clang, -O0):
<get_nick>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     118b <get_nick+0x6b>
mov    -0x8(%rbp),%rdi
mov    $0x21,%esi
call   1030 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     115b <get_nick+0x3b>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%ecx
mov    -0x8(%rbp),%r8
lea    0x2ecd(%rip),%rdi
mov    $0x20,%esi
lea    0xe81(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    1192 <get_nick+0x72>
movb   $0x0,0x2eae(%rip)
lea    0x2ea7(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_nick>:
push   %rbx
test   %rdi,%rdi
je     115e <get_nick+0x3e>
mov    %rdi,%rbx
mov    $0x21,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     113b <get_nick+0x1b>
movb   $0x0,(%rax)
sub    %ebx,%eax
lea    0x2efc(%rip),%rdi
lea    0xeb5(%rip),%rdx
mov    $0x20,%esi
mov    %eax,%ecx
mov    %rbx,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    1165 <get_nick+0x45>
movb   $0x0,0x2edb(%rip)
lea    0x2ed4(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
@get_nick.nick = internal global [32 x i8] zeroinitializer
@.str = [5 x i8] c"%.*s\00"
define i8* @get_nick(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %22
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = call i8* @strchr(i8* %7, i32 33)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = load i8*, i8** %3
store i8 0, i8* %12
br label %13
13: ; preds = %11, %6
%14 = load i8*, i8** %3
%15 = load i8*, i8** %2
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %15 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
%20 = load i8*, i8** %2
%21 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_nick.nick, i64 0, i64 0), i64 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %19, i8* %20)
br label %23
22: ; preds = %1
store i8 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_nick.nick, i64 0, i64 0)
br label %23
23: ; preds = %22, %13
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_nick.nick, i64 0, i64 0)
}

LLVM IR (-O2):
@get_nick.nick = internal global [32 x i8] zeroinitializer
@.str = [5 x i8] c"%.*s\00"
define i8* @get_nick(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %13, label %3
3: ; preds = %1
%4 = tail call i8* @strchr(i8* %0, i32 33)
%5 = icmp eq i8* %4, null
br i1 %5, label %7, label %6
6: ; preds = %3
store i8 0, i8* %4
br label %7
7: ; preds = %6, %3
%8 = ptrtoint i8* %4 to i64
%9 = ptrtoint i8* %0 to i64
%10 = sub i64 %8, %9
%11 = trunc i64 %10 to i32
%12 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @get_nick.nick, i64 0, i64 0), i64 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %11, i8* %0)
br label %14
13: ; preds = %1
store i8 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_nick.nick, i64 0, i64 0)
br label %14
14: ; preds = %13, %7
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_nick.nick, i64 0, i64 0)
}