#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*/ abort();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
char *get_nick(char *msg) {
  unsigned i = 0;
  char *nick = malloc(sizeof(char) * strlen(msg));
  if (nick == NULL) {
    perror("malloc");
    abort();
  }
  while (*++msg != '!') {
    if (*msg == '\0') {
      fputs("Incoming message invalid. Exiting.\n", stderr);
      abort();
    }
    *(nick + i) = *msg;
    i++;
  }
  *(nick + i) = '\0';
  fprintf(stderr, "\tFrom nick: '%s'\n", nick);
  return nick;
}


x86 assembly (clang, -O0):
<get_nick>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ab <get_nick+0x4b>
lea    0xe61(%rip),%rdi
call   1080 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    11b0 <get_nick+0x50>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl 0x1(%rax),%eax
cmp    $0x21,%eax
je     1216 <get_nick+0xb6>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11f8 <get_nick+0x98>
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
lea    0xe1b(%rip),%rdi
call   1050 <fputs@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%dl
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b0 <get_nick+0x50>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdf6(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_nick>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11e0 <get_nick+0x80>
mov    %rax,%r14
xor    %eax,%eax
nopl   (%rax)
movzbl 0x1(%rbx,%rax,1),%ecx
cmp    $0x21,%cl
je     119a <get_nick+0x3a>
test   %cl,%cl
je     11c4 <get_nick+0x64>
mov    %eax,%edx
mov    %cl,(%r14,%rdx,1)
add    $0x1,%rax
jmp    1180 <get_nick+0x20>
mov    %eax,%eax
movb   $0x0,(%r14,%rax,1)
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
lea    0xe33(%rip),%rdi
call   1050 <fputs@plt>
xor    %eax,%eax
call   1030 <abort@plt>
lea    0xe19(%rip),%rdi
call   1080 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"malloc\00"
@.str.1 = [36 x i8] c"Incoming message invalid. Exiting.\0A\00"
@stderr = global i32 0
@.str.2 = [18 x i8] c"\09From nick: '%s'\0A\00"
define i8* @get_nick(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = sext i32 %6 to i64
%8 = mul i64 1, %7
%9 = trunc i64 %8 to i32
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = call i32 (...) @abort()
unreachable
16: ; preds = %1
br label %17
17: ; preds = %32, %16
%18 = load i8*, i8** %2
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %2
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 33
br i1 %22, label %23, label %41
23: ; preds = %17
%24 = load i8*, i8** %2
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = call i32 @fputs(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = call i32 (...) @abort()
unreachable
32: ; preds = %23
%33 = load i8*, i8** %2
%34 = load i8, i8* %33
%35 = load i8*, i8** %4
%36 = load i32, i32* %3
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 %34, i8* %38
%39 = load i32, i32* %3
%40 = add i32 %39, 1
store i32 %40, i32* %3
br label %17
41: ; preds = %17
%42 = load i8*, i8** %4
%43 = load i32, i32* %3
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 0, i8* %45
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %4
%48 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = load i8*, i8** %4
ret i8* %49
}

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
@.str.1 = [36 x i8] c"Incoming message invalid. Exiting.\0A\00"
@stderr = global i32 0
@.str.2 = [18 x i8] c"\09From nick: '%s'\0A\00"
define i8* @get_nick(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i8* @malloc(i32 %2)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 (...) @abort()
unreachable
8: ; preds = %1, %17
%9 = phi i32 [ %20, %17 ], [ 0, %1 ]
%10 = phi i8* [ %11, %17 ], [ %0, %1 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %11
switch i8 %12, label %17 [
i8 33, label %21
i8 0, label %13
]
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = tail call i32 @fputs(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = tail call i32 (...) @abort()
unreachable
17: ; preds = %8
%18 = zext i32 %9 to i64
%19 = getelementptr inbounds i8, i8* %3, i64 %18
store i8 %12, i8* %19
%20 = add i32 %9, 1
br label %8
21: ; preds = %8
%22 = zext i32 %9 to i64
%23 = getelementptr inbounds i8, i8* %3, i64 %22
store i8 0, i8* %23
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %3)
ret i8* %3
}