#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*/ isspace(char);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int strlen(char *);
char *getFileNameFromCommand(char *command) {
  int i = strlen(command);
  while (!isspace(command[i]) || i == 0) {
    i--;
  }
  char *nomeFile = malloc(i + 1);
  memcpy(nomeFile, command, i);
  nomeFile[i] = '\0';
  return nomeFile;
}


x86 assembly (clang, -O0):
<getFileNameFromCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isspace@plt>
mov    %eax,%ecx
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     1183 <getFileNameFromCommand+0x43>
cmpl   $0x0,-0xc(%rbp)
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1193 <getFileNameFromCommand+0x53>
jmp    11a1 <getFileNameFromCommand+0x61>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1158 <getFileNameFromCommand+0x18>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFileNameFromCommand>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <strlen@plt>
movslq %eax,%r13
lea    (%r15,%r13,1),%r14
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r13,%rbx
add    %rbp,%rbx
movsbl (%r14,%rbp,1),%edi
call   1040 <isspace@plt>
add    $0xffffffffffffffff,%rbp
test   %eax,%eax
je     1160 <getFileNameFromCommand+0x20>
test   %rbx,%rbx
je     1160 <getFileNameFromCommand+0x20>
lea    0x1(%r13,%rbp,1),%r14d
lea    0x2(%r13,%rbp,1),%edi
call   1060 <malloc@plt>
mov    %rax,%r12
add    %rax,%r13
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1050 <memcpy@plt>
movb   $0x0,0x1(%rbp,%r13,1)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @getFileNameFromCommand(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %3
br label %7
7: ; preds = %20, %1
%8 = load i8*, i8** %2
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = load i8, i8* %11
%13 = call i32 @isspace(i8 signext %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %7
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 0
br label %18
18: ; preds = %15, %7
%19 = phi i1 [ true, %7 ], [ %17, %15 ]
br i1 %19, label %20, label %23
20: ; preds = %18
%21 = load i32, i32* %3
%22 = add nsw i32 %21, -1
store i32 %22, i32* %3
br label %7
23: ; preds = %18
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
%26 = call i8* @malloc(i32 %25)
store i8* %26, i8** %4
%27 = load i8*, i8** %4
%28 = load i8*, i8** %2
%29 = load i32, i32* %3
%30 = call i32 @memcpy(i8* %27, i8* %28, i32 %29)
%31 = load i8*, i8** %4
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 0, i8* %34
%35 = load i8*, i8** %4
ret i8* %35
}

LLVM IR (-O2):
define i8* @getFileNameFromCommand(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
br label %4
4: ; preds = %4, %1
%5 = phi i64 [ %12, %4 ], [ %3, %1 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = tail call i32 @isspace(i8 signext %7)
%9 = icmp eq i32 %8, 0
%10 = icmp eq i64 %5, 0
%11 = select i1 %9, i1 true, i1 %10
%12 = add i64 %5, -1
br i1 %11, label %4, label %13
13: ; preds = %4
%14 = trunc i64 %5 to i32
%15 = add nsw i32 %14, 1
%16 = tail call i8* @malloc(i32 %15)
%17 = tail call i32 @memcpy(i8* %16, i8* %0, i32 %14)
%18 = getelementptr inbounds i8, i8* %16, i64 %5
store i8 0, i8* %18
ret i8* %16
}