#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 */
char *malloc(int);
int /*<<< orphan*/ *strchr(char *, char);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
char *strtok(char *, char *);
char *get_username(char *line) {
  char *username = malloc(512);
  char clone[512];
  strncpy(clone, line, strlen(line) + 1);
  if (strchr(clone, '!') != NULL) {
    char *splitted = strtok(clone, "!");
    if (splitted != NULL) {
      strncpy(username, splitted + 1, strlen(splitted) + 1);
    } else {
      username[0] = '\0';
    }
  } else {
    username[0] = '\0';
  }
  return username;
}


x86 assembly (clang, -O0):
<get_username>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x200,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    -0x210(%rbp),%rax
mov    %rax,-0x228(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x220(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x228(%rbp),%rdi
mov    -0x220(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <strncpy@plt>
lea    -0x210(%rbp),%rdi
mov    $0x21,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     1240 <get_username+0xf0>
lea    -0x210(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
je     1234 <get_username+0xe4>
mov    -0x10(%rbp),%rax
mov    %rax,-0x238(%rbp)
mov    -0x218(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x230(%rbp)
mov    -0x218(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x238(%rbp),%rdi
mov    -0x230(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <strncpy@plt>
jmp    123b <get_username+0xeb>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    1247 <get_username+0xf7>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_username>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%rbx
mov    $0x200,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    %r15,%rdi
mov    $0x21,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11cc <get_username+0x7c>
lea    0xe61(%rip),%rsi
mov    %rsp,%rdi
call   1070 <strtok@plt>
test   %rax,%rax
je     11cc <get_username+0x7c>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
jmp    11d0 <get_username+0x80>
movb   $0x0,(%r14)
mov    %r14,%rax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"!\00"
define i8* @get_username(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [512 x i8]
%5 = alloca i8*
store i8* %0, i8** %2
%6 = call i8* @malloc(i32 512)
store i8* %6, i8** %3
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%8 = load i8*, i8** %2
%9 = load i8*, i8** %2
%10 = call i64 @strlen(i8* %9)
%11 = add nsw i64 %10, 1
%12 = call i32 @strncpy(i8* %7, i8* %8, i64 %11)
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%14 = call i32* @strchr(i8* %13, i8 signext 33)
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %33
16: ; preds = %1
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%18 = call i8* @strtok(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %29
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8*, i8** %5
%26 = call i64 @strlen(i8* %25)
%27 = add nsw i64 %26, 1
%28 = call i32 @strncpy(i8* %22, i8* %24, i64 %27)
br label %32
29: ; preds = %16
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i64 0
store i8 0, i8* %31
br label %32
32: ; preds = %29, %21
br label %36
33: ; preds = %1
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i64 0
store i8 0, i8* %35
br label %36
36: ; preds = %33, %32
%37 = load i8*, i8** %3
ret i8* %37
}

LLVM IR (-O2):
@.str = [2 x i8] c"!\00"
define i8* @get_username(i8* %0) {
%2 = alloca [512 x i8]
%3 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = add nsw i64 %5, 1
%7 = call i32 @strncpy(i8* %4, i8* %0, i64 %6)
%8 = call i32* @strchr(i8* %4, i8 signext 33)
%9 = icmp eq i32* %8, null
br i1 %9, label %19, label %10
10: ; preds = %1
%11 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %18, label %13
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %11, i64 1
%15 = call i64 @strlen(i8* %11)
%16 = add nsw i64 %15, 1
%17 = call i32 @strncpy(i8* %3, i8* %14, i64 %16)
br label %20
18: ; preds = %10
store i8 0, i8* %3
br label %20
19: ; preds = %1
store i8 0, i8* %3
br label %20
20: ; preds = %13, %18, %19
ret i8* %3
}