#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int strlen(char *);
char *strtok_r(char *, char *, char **);
void parse_cmd_line(char *process) {
  char *cmd, *save, *tmp;
  int i;
  int first_run = 1;
  char *t = malloc(strlen(process) + 1);
  memcpy(t, process, strlen(process) + 1);
  while ((tmp = strtok_r((first_run == 1 ? t : NULL), "/", &save)) != NULL) {
    cmd = tmp;
    if (first_run == 1) {
      first_run = 0;
    }
  }
  if (cmd != NULL) {
    for (i = 0; i < strlen(cmd); i++) {
      if (cmd[i] == ' ' || cmd[i] == ':') {
        cmd[i] = '_';
      }
    }
    memcpy(process, cmd, strlen(cmd) + 1);
  }
  free(t);
  return;
}


x86 assembly (clang, -O0):
<parse_cmd_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1060 <memcpy@plt>
cmpl   $0x1,-0x28(%rbp)
jne    11bc <parse_cmd_line+0x6c>
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    11c7 <parse_cmd_line+0x77>
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
jmp    11c7 <parse_cmd_line+0x77>
mov    -0x48(%rbp),%rdi
lea    0xe2e(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1207 <parse_cmd_line+0xb7>
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x1,-0x28(%rbp)
jne    1202 <parse_cmd_line+0xb2>
movl   $0x0,-0x28(%rbp)
jmp    11a5 <parse_cmd_line+0x55>
cmpq   $0x0,-0x10(%rbp)
je     12a9 <parse_cmd_line+0x159>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
cmp    %ecx,%eax
jge    127e <parse_cmd_line+0x12e>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     125f <parse_cmd_line+0x10f>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    126b <parse_cmd_line+0x11b>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x5f,(%rax,%rcx,1)
jmp    1270 <parse_cmd_line+0x120>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1219 <parse_cmd_line+0xc9>
mov    -0x8(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1060 <memcpy@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_cmd_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <memcpy@plt>
lea    0xe72(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rbp,%r14
mov    %rbp,%rdi
call   1050 <strtok_r@plt>
test   %rax,%rax
je     124d <parse_cmd_line+0xfd>
mov    %rbx,0x8(%rsp)
mov    $0x1,%ebp
mov    $0x1,%r15b
lea    0xe45(%rip),%r12
lea    0x10(%rsp),%r13
jmp    11e0 <parse_cmd_line+0x90>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rsi
mov    %r13,%rdx
call   1050 <strtok_r@plt>
test   %rax,%rax
je     11ff <parse_cmd_line+0xaf>
mov    %rax,%rbx
test   $0x1,%r15b
mov    $0x0,%eax
cmovne %eax,%ebp
mov    %r14,%rdi
cmp    $0x1,%ebp
sete   %r15b
je     11d0 <parse_cmd_line+0x80>
xor    %edi,%edi
jmp    11d0 <parse_cmd_line+0x80>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1235 <parse_cmd_line+0xe5>
xor    %ebp,%ebp
jmp    1227 <parse_cmd_line+0xd7>
nop
movb   $0x5f,(%rbx,%rbp,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbp
jge    1235 <parse_cmd_line+0xe5>
movzbl (%rbx,%rbp,1),%eax
cmp    $0x3a,%al
je     1210 <parse_cmd_line+0xc0>
cmp    $0x20,%al
je     1210 <parse_cmd_line+0xc0>
jmp    1214 <parse_cmd_line+0xc4>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1060 <memcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define void @parse_cmd_line(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %2
store i32 1, i32* %7
%9 = load i8*, i8** %2
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %10, 1
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = load i8*, i8** %2
%15 = load i8*, i8** %2
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %16, 1
%18 = call i32 @memcpy(i8* %13, i8* %14, i32 %17)
br label %19
19: ; preds = %34, %1
%20 = load i32, i32* %7
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = load i8*, i8** %8
br label %25
24: ; preds = %19
br label %25
25: ; preds = %24, %22
%26 = phi i8* [ %23, %22 ], [ null, %24 ]
%27 = call i8* @strtok_r(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %4)
store i8* %27, i8** %5
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %35
29: ; preds = %25
%30 = load i8*, i8** %5
store i8* %30, i8** %3
%31 = load i32, i32* %7
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 0, i32* %7
br label %34
34: ; preds = %33, %29
br label %19
35: ; preds = %25
%36 = load i8*, i8** %3
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %76
38: ; preds = %35
store i32 0, i32* %6
br label %39
39: ; preds = %66, %38
%40 = load i32, i32* %6
%41 = load i8*, i8** %3
%42 = call i32 @strlen(i8* %41)
%43 = icmp slt i32 %40, %42
br i1 %43, label %44, label %69
44: ; preds = %39
%45 = load i8*, i8** %3
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 32
br i1 %51, label %60, label %52
52: ; preds = %44
%53 = load i8*, i8** %3
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 58
br i1 %59, label %60, label %65
60: ; preds = %52, %44
%61 = load i8*, i8** %3
%62 = load i32, i32* %6
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
store i8 95, i8* %64
br label %65
65: ; preds = %60, %52
br label %66
66: ; preds = %65
%67 = load i32, i32* %6
%68 = add nsw i32 %67, 1
store i32 %68, i32* %6
br label %39
69: ; preds = %39
%70 = load i8*, i8** %2
%71 = load i8*, i8** %3
%72 = load i8*, i8** %3
%73 = call i32 @strlen(i8* %72)
%74 = add nsw i32 %73, 1
%75 = call i32 @memcpy(i8* %70, i8* %71, i32 %74)
br label %76
76: ; preds = %69, %35
%77 = load i8*, i8** %8
%78 = call i32 @free(i8* %77)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define void @parse_cmd_line(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, 1
%6 = tail call i8* @malloc(i32 %5)
%7 = tail call i32 @strlen(i8* %0)
%8 = add nsw i32 %7, 1
%9 = tail call i32 @memcpy(i8* %6, i8* %0, i32 %8)
%10 = call i8* @strtok_r(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2)
%11 = icmp eq i8* %10, null
br i1 %11, label %38, label %12
12: ; preds = %1, %12
%13 = phi i8* [ %19, %12 ], [ %10, %1 ]
%14 = phi i1 [ %17, %12 ], [ true, %1 ]
%15 = phi i32 [ %16, %12 ], [ 1, %1 ]
%16 = select i1 %14, i32 0, i32 %15
%17 = icmp eq i32 %16, 1
%18 = select i1 %17, i8* %6, i8* null
%19 = call i8* @strtok_r(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %12
21: ; preds = %12
%22 = call i32 @strlen(i8* %13)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %34
24: ; preds = %21, %29
%25 = phi i64 [ %30, %29 ], [ 0, %21 ]
%26 = getelementptr inbounds i8, i8* %13, i64 %25
%27 = load i8, i8* %26
switch i8 %27, label %29 [
i8 32, label %28
i8 58, label %28
]
28: ; preds = %24, %24
store i8 95, i8* %26
br label %29
29: ; preds = %24, %28
%30 = add nuw nsw i64 %25, 1
%31 = call i32 @strlen(i8* %13)
%32 = sext i32 %31 to i64
%33 = icmp slt i64 %30, %32
br i1 %33, label %24, label %34
34: ; preds = %29, %21
%35 = call i32 @strlen(i8* %13)
%36 = add nsw i32 %35, 1
%37 = call i32 @memcpy(i8* %0, i8* %13, i32 %36)
br label %38
38: ; preds = %1, %34
%39 = call i32 @free(i8* %6)
ret void
}