#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 */
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
char *getCommandExecutableName(char *commandline) {
  char *nameStart;
  char *nameEnd;
  char *name;
  int length;
  nameStart = commandline;
  nameEnd = commandline;
  for (;;) {
    if (nameEnd[0] <= 32) {
      nameEnd--;
      break;
    }
    if (nameEnd[0] == '/') {
      nameEnd = nameEnd + 1;
      nameStart = nameEnd;
      continue;
    }
    nameEnd = nameEnd + 1;
  }
  length = (nameEnd - nameStart) + 1;
  name = (char *)malloc((size_t)(length + 1));
  memcpy(name, nameStart, (size_t)length);
  name[length] = '\0';
  return name;
}


x86 assembly (clang, -O0):
<getCommandExecutableName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jg     115d <getCommandExecutableName+0x3d>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1197 <getCommandExecutableName+0x77>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1186 <getCommandExecutableName+0x66>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    113c <getCommandExecutableName+0x1c>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113c <getCommandExecutableName+0x1c>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x24(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCommandExecutableName>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%cl
cmp    $0x21,%cl
jge    1190 <getCommandExecutableName+0x70>
mov    %r14,%rax
mov    %r14d,%ebx
not    %ebx
add    %eax,%ebx
shl    $0x20,%rbx
movabs $0x200000000,%rdi
add    %rbx,%rdi
sar    $0x20,%rdi
call   1040 <malloc@plt>
mov    %rax,%r15
movabs $0x100000000,%r12
add    %rbx,%r12
sar    $0x20,%r12
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1030 <memcpy@plt>
movb   $0x0,(%r15,%r12,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
nopl   0x0(%rax)
lea    0x1(%r14),%rdx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rdx,%rax
cmp    $0x2f,%cl
movzbl (%rdx),%ecx
je     11c0 <getCommandExecutableName+0xa0>
lea    0x1(%rax),%rdx
cmp    $0x21,%cl
jge    11a0 <getCommandExecutableName+0x80>
jmp    1135 <getCommandExecutableName+0x15>
nopl   0x0(%rax)
mov    %rax,%r14
cmp    $0x21,%cl
jge    1190 <getCommandExecutableName+0x70>
jmp    1135 <getCommandExecutableName+0x15>

LLVM IR (-O0):
define i8* @getCommandExecutableName(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
store i8* %7, i8** %3
%8 = load i8*, i8** %2
store i8* %8, i8** %4
br label %9
9: ; preds = %28, %24, %1
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp sle i32 %13, 32
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i32 -1
store i8* %17, i8** %4
br label %31
18: ; preds = %9
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 47
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 1
store i8* %26, i8** %4
%27 = load i8*, i8** %4
store i8* %27, i8** %3
br label %9
28: ; preds = %18
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i64 1
store i8* %30, i8** %4
br label %9
31: ; preds = %15
%32 = load i8*, i8** %4
%33 = load i8*, i8** %3
%34 = ptrtoint i8* %32 to i64
%35 = ptrtoint i8* %33 to i64
%36 = sub i64 %34, %35
%37 = add nsw i64 %36, 1
%38 = trunc i64 %37 to i32
store i32 %38, i32* %6
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = call i64 @malloc(i64 %41)
%43 = inttoptr i64 %42 to i8*
store i8* %43, i8** %5
%44 = load i8*, i8** %5
%45 = load i8*, i8** %3
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = call i32 @memcpy(i8* %44, i8* %45, i64 %47)
%49 = load i8*, i8** %5
%50 = load i32, i32* %6
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 0, i8* %52
%53 = load i8*, i8** %5
ret i8* %53
}

LLVM IR (-O2):
define i8* @getCommandExecutableName(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp slt i8 %2, 33
br i1 %3, label %7, label %4
4: ; preds = %1, %30
%5 = phi i8 [ %28, %30 ], [ %2, %1 ]
%6 = phi i8* [ %27, %30 ], [ %0, %1 ]
br label %23
7: ; preds = %30, %31, %1
%8 = phi i8* [ %0, %1 ], [ %6, %31 ], [ %27, %30 ]
%9 = phi i8* [ %0, %1 ], [ %27, %31 ], [ %27, %30 ]
%10 = getelementptr inbounds i8, i8* %9, i64 -1
%11 = ptrtoint i8* %10 to i64
%12 = ptrtoint i8* %8 to i64
%13 = sub i64 %11, %12
%14 = shl i64 %13, 32
%15 = add i64 %14, 8589934592
%16 = ashr exact i64 %15, 32
%17 = tail call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
%19 = add i64 %14, 4294967296
%20 = ashr exact i64 %19, 32
%21 = tail call i32 @memcpy(i8* %18, i8* %8, i64 %20)
%22 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 0, i8* %22
ret i8* %18
23: ; preds = %4, %31
%24 = phi i8 [ %5, %4 ], [ %28, %31 ]
%25 = phi i8* [ %6, %4 ], [ %27, %31 ]
%26 = icmp eq i8 %24, 47
%27 = getelementptr inbounds i8, i8* %25, i64 1
%28 = load i8, i8* %27
%29 = icmp slt i8 %28, 33
br i1 %26, label %30, label %31
30: ; preds = %23
br i1 %29, label %7, label %4
31: ; preds = %23
br i1 %29, label %7, label %23
}