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


x86 assembly (clang, -O0):
<get_command>:
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>
lea    -0x210(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
je     1249 <get_command+0x109>
mov    -0x218(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    11eb <get_command+0xab>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe21(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
je     123d <get_command+0xfd>
mov    -0x10(%rbp),%rax
mov    %rax,-0x238(%rbp)
mov    -0x218(%rbp),%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    1244 <get_command+0x104>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    1250 <get_command+0x110>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_command>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%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,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
lea    0xe83(%rip),%rsi
mov    %r15,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     11c1 <get_command+0x81>
mov    %rax,%rbx
cmpb   $0x3a,(%rax)
jne    11a8 <get_command+0x68>
lea    0xe67(%rip),%rsi
xor    %edi,%edi
call   1060 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11c1 <get_command+0x81>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
jmp    11c5 <get_command+0x85>
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_command(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 i8* @strtok(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %39
17: ; preds = %1
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 58
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %24, i8** %5
br label %25
25: ; preds = %23, %17
%26 = load i8*, i8** %5
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = load i8*, i8** %3
%30 = load i8*, i8** %5
%31 = load i8*, i8** %5
%32 = call i64 @strlen(i8* %31)
%33 = add nsw i64 %32, 1
%34 = call i32 @strncpy(i8* %29, i8* %30, i64 %33)
br label %38
35: ; preds = %25
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i64 0
store i8 0, i8* %37
br label %38
38: ; preds = %35, %28
br label %42
39: ; preds = %1
%40 = load i8*, i8** %3
%41 = getelementptr inbounds i8, i8* %40, i64 0
store i8 0, i8* %41
br label %42
42: ; preds = %39, %38
%43 = load i8*, i8** %3
ret i8* %43
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i8* @get_command(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 i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %22, label %10
10: ; preds = %1
%11 = load i8, i8* %8
%12 = icmp eq i8 %11, 58
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %21, label %16
16: ; preds = %10, %13
%17 = phi i8* [ %14, %13 ], [ %8, %10 ]
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %18, 1
%20 = call i32 @strncpy(i8* %3, i8* %17, i64 %19)
br label %23
21: ; preds = %13
store i8 0, i8* %3
br label %23
22: ; preds = %1
store i8 0, i8* %3
br label %23
23: ; preds = %16, %21, %22
ret i8* %3
}