#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(int);
char *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
char *get_fileName(char *buf) {
  char *p = (char *)malloc(256);
  p = strchr(buf, ' ');
  if (p != NULL) {
    *p++ = '\0';
    if (strcmp(buf, "GET") == 0) {
      char *q = strchr(p, ' ');
      if (q != NULL) {
        *q = '\0';
        return p;
      }
    }
    return NULL;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<get_fileName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x100,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d6 <get_fileName+0xa6>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11c9 <get_fileName+0x99>
mov    -0x18(%rbp),%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c4 <get_fileName+0x94>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11de <get_fileName+0xae>
jmp    11c9 <get_fileName+0x99>
movq   $0x0,-0x8(%rbp)
jmp    11de <get_fileName+0xae>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_fileName>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x100,%edi
call   1050 <malloc@plt>
mov    %r14,%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     116d <get_fileName+0x3d>
mov    %rax,%rbx
movb   $0x0,(%rax)
lea    0xea0(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     117a <get_fileName+0x4a>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     116d <get_fileName+0x3d>
movb   $0x0,(%rax)
jmp    116f <get_fileName+0x3f>

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

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