#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 const *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
void resolve_request(const char *reqbuf, char *urlbuf, char *versionbuf) {
  char *pos, *pos2;
  pos = strchr(reqbuf, (int)' ');
  pos2 = strchr(pos + 1, (int)' ');
  strncpy(urlbuf, pos + 1, pos2 - pos - 1);
  urlbuf[pos2 - pos - 1] = '\0';
  pos = strchr(pos2 + 1, (int)'\r');
  strncpy(versionbuf, pos2 + 1, pos - pos2 - 1);
  versionbuf[pos - pos2 - 1] = '\0';
}


x86 assembly (clang, -O0):
<resolve_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rdx
sub    %rdx,%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
mov    $0xd,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%rdx
sub    %rdx,%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolve_request>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
lea    0x1(%rax),%r13
mov    %r13,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,%r12
not    %rbx
add    %rax,%rbx
mov    %r15,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%rbx,1)
lea    0x1(%r12),%rbx
mov    %rbx,%rdi
mov    $0xd,%esi
call   1040 <strchr@plt>
not    %r12
add    %rax,%r12
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r14,%r12,1)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @resolve_request(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %4
%10 = call i8* @strchr(i8* %9, i32 32)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = call i8* @strchr(i8* %12, i32 32)
store i8* %13, i8** %8
%14 = load i8*, i8** %5
%15 = load i8*, i8** %7
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8*, i8** %8
%18 = load i8*, i8** %7
%19 = ptrtoint i8* %17 to i64
%20 = ptrtoint i8* %18 to i64
%21 = sub i64 %19, %20
%22 = sub nsw i64 %21, 1
%23 = trunc i64 %22 to i32
%24 = call i32 @strncpy(i8* %14, i8* %16, i32 %23)
%25 = load i8*, i8** %5
%26 = load i8*, i8** %8
%27 = load i8*, i8** %7
%28 = ptrtoint i8* %26 to i64
%29 = ptrtoint i8* %27 to i64
%30 = sub i64 %28, %29
%31 = sub nsw i64 %30, 1
%32 = getelementptr inbounds i8, i8* %25, i64 %31
store i8 0, i8* %32
%33 = load i8*, i8** %8
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = call i8* @strchr(i8* %34, i32 13)
store i8* %35, i8** %7
%36 = load i8*, i8** %6
%37 = load i8*, i8** %8
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8*, i8** %7
%40 = load i8*, i8** %8
%41 = ptrtoint i8* %39 to i64
%42 = ptrtoint i8* %40 to i64
%43 = sub i64 %41, %42
%44 = sub nsw i64 %43, 1
%45 = trunc i64 %44 to i32
%46 = call i32 @strncpy(i8* %36, i8* %38, i32 %45)
%47 = load i8*, i8** %6
%48 = load i8*, i8** %7
%49 = load i8*, i8** %8
%50 = ptrtoint i8* %48 to i64
%51 = ptrtoint i8* %49 to i64
%52 = sub i64 %50, %51
%53 = sub nsw i64 %52, 1
%54 = getelementptr inbounds i8, i8* %47, i64 %53
store i8 0, i8* %54
ret void
}

LLVM IR (-O2):
define void @resolve_request(i8* %0, i8* %1, i8* %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 32)
%5 = getelementptr inbounds i8, i8* %4, i64 1
%6 = tail call i8* @strchr(i8* %5, i32 32)
%7 = ptrtoint i8* %6 to i64
%8 = ptrtoint i8* %4 to i64
%9 = xor i64 %8, -1
%10 = add i64 %7, %9
%11 = trunc i64 %10 to i32
%12 = tail call i32 @strncpy(i8* %1, i8* %5, i32 %11)
%13 = getelementptr inbounds i8, i8* %1, i64 %10
store i8 0, i8* %13
%14 = getelementptr inbounds i8, i8* %6, i64 1
%15 = tail call i8* @strchr(i8* %14, i32 13)
%16 = ptrtoint i8* %15 to i64
%17 = xor i64 %7, -1
%18 = add i64 %16, %17
%19 = trunc i64 %18 to i32
%20 = tail call i32 @strncpy(i8* %2, i8* %14, i32 %19)
%21 = getelementptr inbounds i8, i8* %2, i64 %18
store i8 0, i8* %21
ret void
}