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


x86 assembly (clang, -O0):
<get_prefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x200,%edi
call   1050 <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>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1225 <get_prefix+0xe5>
lea    -0x210(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
je     1219 <get_prefix+0xd9>
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    1220 <get_prefix+0xe0>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    122c <get_prefix+0xec>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_prefix>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%rbx
mov    $0x200,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
cmpb   $0x3a,(%rbx)
jne    11aa <get_prefix+0x6a>
lea    0xe83(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     11aa <get_prefix+0x6a>
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    11ae <get_prefix+0x6e>
movb   $0x0,(%r14)
mov    %r14,%rax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i8* @get_prefix(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 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 58
br i1 %17, label %18, label %35
18: ; preds = %1
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%20 = call i8* @strtok(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %20, i8** %5
%21 = load i8*, i8** %5
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %31
23: ; preds = %18
%24 = load i8*, i8** %3
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8*, i8** %5
%28 = call i64 @strlen(i8* %27)
%29 = add nsw i64 %28, 1
%30 = call i32 @strncpy(i8* %24, i8* %26, i64 %29)
br label %34
31: ; preds = %18
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i64 0
store i8 0, i8* %33
br label %34
34: ; preds = %31, %23
br label %38
35: ; preds = %1
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i64 0
store i8 0, i8* %37
br label %38
38: ; preds = %35, %34
%39 = load i8*, i8** %3
ret i8* %39
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i8* @get_prefix(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 = load i8, i8* %0
%9 = icmp eq i8 %8, 58
br i1 %9, label %10, label %19
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
}