#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 *strchr(char *, char);
int strlen(char *);
char *strstr(char const *, char *);
char *get_filename(const char *str) {
  char *str_start = strstr(str, "GET /");
  if (str_start != NULL) {
    char *filename = str_start + strlen("GET /");
    char *str_end = strchr(filename, ' ');
    if (str_end != NULL)
      *str_end = '\0';
    return filename;
  } else {
    return NULL;
  }
}


x86 assembly (clang, -O0):
<get_filename>:
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)
je     11b0 <get_filename+0x80>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe96(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11a3 <get_filename+0x73>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b8 <get_filename+0x88>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_filename>:
push   %rbx
lea    0xec8(%rip),%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     116d <get_filename+0x3d>
mov    %rax,%rbx
lea    0xeb4(%rip),%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     116f <get_filename+0x3f>
movb   $0x0,(%rax)
jmp    116f <get_filename+0x3f>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"GET /\00"
define i8* @get_filename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @strstr(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %24
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = call i8* @strchr(i8* %16, i8 signext 32)
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = load i8*, i8** %6
store i8 0, i8* %21
br label %22
22: ; preds = %20, %11
%23 = load i8*, i8** %5
store i8* %23, i8** %2
br label %25
24: ; preds = %1
store i8* null, i8** %2
br label %25
25: ; preds = %24, %22
%26 = load i8*, i8** %2
ret i8* %26
}

LLVM IR (-O2):
@.str = [6 x i8] c"GET /\00"
define i8* @get_filename(i8* %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %11, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %2, i64 %6
%8 = tail call i8* @strchr(i8* %7, i8 signext 32)
%9 = icmp eq i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %4
store i8 0, i8* %8
br label %11
11: ; preds = %1, %4, %10
%12 = phi i8* [ %7, %10 ], [ %7, %4 ], [ null, %1 ]
ret i8* %12
}