#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 /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char const *, char *);
void extract_server_path(const char *header, char *output) {
  char *p = strstr(header, "GET /");
  if (p) {
    char *p1 = strchr(p + 4, ' ');
    strncpy(output, p + 4, (int)(p1 - p - 4));
  }
}


x86 assembly (clang, -O0):
<extract_server_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1197 <extract_server_path+0x67>
mov    -0x18(%rbp),%rdi
add    $0x4,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x4,%rsi
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
sub    $0x4,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_server_path>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xec1(%rip),%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1176 <extract_server_path+0x46>
mov    %rax,%r15
mov    %rax,%rbx
add    $0x4,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
sub    %r15d,%eax
lea    -0x4(%rax),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strncpy@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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