#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 *ag_malloc(int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
char *get_path(char *raw) {
  char *start_path;
  char *end_path;
  char *rval;
  int plength;
  start_path = strstr(raw, " ");
  ;
  if (!start_path)
    return NULL;
  start_path++;
  end_path = strstr(start_path, " ");
  if (!end_path)
    return NULL;
  end_path--;
  plength = end_path - start_path + 1;
  rval = ag_malloc(plength + 1);
  strncpy(rval, start_path, plength);
  return rval;
}


x86 assembly (clang, -O0):
<get_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1168 <get_path+0x38>
movq   $0x0,-0x8(%rbp)
jmp    11e5 <get_path+0xb5>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a0 <get_path+0x70>
movq   $0x0,-0x8(%rbp)
jmp    11e5 <get_path+0xb5>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
call   1040 <ag_malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_path>:
push   %rbp
push   %r14
push   %rbx
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1181 <get_path+0x51>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1181 <get_path+0x51>
mov    %eax,%ebp
sub    %ebx,%ebp
mov    %ebx,%ecx
not    %ecx
lea    (%rcx,%rax,1),%edi
add    $0x2,%edi
call   1050 <ag_malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
jmp    1184 <get_path+0x54>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i8* @get_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i8* @strstr(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %1
store i8* null, i8** %2
br label %39
13: ; preds = %1
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = call i8* @strstr(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = icmp ne i8* %18, null
br i1 %19, label %21, label %20
20: ; preds = %13
store i8* null, i8** %2
br label %39
21: ; preds = %13
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i32 -1
store i8* %23, i8** %5
%24 = load i8*, i8** %5
%25 = load i8*, i8** %4
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = add nsw i64 %28, 1
%30 = trunc i64 %29 to i32
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
%33 = call i8* @ag_malloc(i32 %32)
store i8* %33, i8** %6
%34 = load i8*, i8** %6
%35 = load i8*, i8** %4
%36 = load i32, i32* %7
%37 = call i32 @strncpy(i8* %34, i8* %35, i32 %36)
%38 = load i8*, i8** %6
store i8* %38, i8** %2
br label %39
39: ; preds = %21, %20, %12
%40 = load i8*, i8** %2
ret i8* %40
}

LLVM IR (-O2):
define i8* @get_path(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 32)
%3 = icmp eq i8* %2, null
br i1 %3, label %18, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %2, i64 1
%6 = tail call i8* @strchr(i8* %5, i32 32)
%7 = icmp eq i8* %6, null
br i1 %7, label %18, label %8
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %6, i64 -1
%10 = ptrtoint i8* %9 to i64
%11 = ptrtoint i8* %5 to i64
%12 = sub i64 %10, %11
%13 = trunc i64 %12 to i32
%14 = add i32 %13, 1
%15 = add i32 %13, 2
%16 = tail call i8* @ag_malloc(i32 %15)
%17 = tail call i32 @strncpy(i8* %16, i8* %5, i32 %14)
br label %18
18: ; preds = %4, %1, %8
%19 = phi i8* [ %16, %8 ], [ null, %1 ], [ null, %4 ]
ret i8* %19
}