#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 *malloc(int);
char **parse_string(char *);
char *strchr(char *, char);
scalar_t__ strncasecmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
char *http_parse(char *buf, char ***args) {
  char *url, *ep;
  int len;
  if (strncasecmp(buf, "GET ", 4))
    return (NULL);
  ep = strstr(buf, " HTTP/");
  if (!ep)
    ep = strstr(buf, " http/");
  if (!ep)
    return (NULL);
  len = ep - buf - 4;
  url = malloc(len + 1);
  if (!url)
    return (NULL);
  strncpy(url, buf + 4, len);
  url[len] = '\0';
  if (args) {
    char *p;
    if ((p = strchr(url, '?')) != NULL) {
      *args = parse_string(p + 1);
    }
  }
  return (url);
}


x86 assembly (clang, -O0):
<http_parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
mov    $0x4,%edx
call   1070 <strncasecmp@plt>
cmp    $0x0,%rax
je     119c <http_parse+0x3c>
movq   $0x0,-0x8(%rbp)
jmp    128b <http_parse+0x12b>
mov    -0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11cf <http_parse+0x6f>
mov    -0x10(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e7 <http_parse+0x87>
movq   $0x0,-0x8(%rbp)
jmp    128b <http_parse+0x12b>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
sub    $0x4,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1220 <http_parse+0xc0>
movq   $0x0,-0x8(%rbp)
jmp    128b <http_parse+0x12b>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x4,%rsi
mov    -0x2c(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpq   $0x0,-0x18(%rbp)
je     1283 <http_parse+0x123>
mov    -0x20(%rbp),%rdi
mov    $0x3f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     127e <http_parse+0x11e>
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
call   1030 <parse_string@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    1283 <http_parse+0x123>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_parse>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xe8b(%rip),%rsi
mov    $0x4,%edx
call   1070 <strncasecmp@plt>
test   %rax,%rax
je     1196 <http_parse+0x36>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe68(%rip),%rsi
mov    %r12,%rdi
call   1080 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c4 <http_parse+0x64>
lea    0xe58(%rip),%rsi
mov    %r12,%rdi
call   1080 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1184 <http_parse+0x24>
sub    %r12d,%ebx
lea    -0x3(%rbx),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1184 <http_parse+0x24>
mov    %rax,%r15
add    $0xfffffffc,%ebx
add    $0x4,%r12
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1040 <strncpy@plt>
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
test   %r14,%r14
je     1187 <http_parse+0x27>
mov    %r15,%rdi
mov    $0x3f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1187 <http_parse+0x27>
add    $0x1,%rax
mov    %rax,%rdi
call   1030 <parse_string@plt>
mov    %rax,(%r14)
jmp    1187 <http_parse+0x27>

LLVM IR (-O0):
@.str = [5 x i8] c"GET \00"
@.str.1 = [7 x i8] c" HTTP/\00"
@.str.2 = [7 x i8] c" http/\00"
define i8* @http_parse(i8* %0, i8*** %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8***
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store i8*** %1, i8**** %5
%10 = load i8*, i8** %4
%11 = call i64 @strncasecmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i8* null, i8** %3
br label %64
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i8* @strstr(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = icmp ne i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = call i8* @strstr(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i8* %21, i8** %7
br label %22
22: ; preds = %19, %14
%23 = load i8*, i8** %7
%24 = icmp ne i8* %23, null
br i1 %24, label %26, label %25
25: ; preds = %22
store i8* null, i8** %3
br label %64
26: ; preds = %22
%27 = load i8*, i8** %7
%28 = load i8*, i8** %4
%29 = ptrtoint i8* %27 to i64
%30 = ptrtoint i8* %28 to i64
%31 = sub i64 %29, %30
%32 = sub nsw i64 %31, 4
%33 = trunc i64 %32 to i32
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
%36 = call i8* @malloc(i32 %35)
store i8* %36, i8** %6
%37 = load i8*, i8** %6
%38 = icmp ne i8* %37, null
br i1 %38, label %40, label %39
39: ; preds = %26
store i8* null, i8** %3
br label %64
40: ; preds = %26
%41 = load i8*, i8** %6
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i64 4
%44 = load i32, i32* %8
%45 = call i32 @strncpy(i8* %41, i8* %43, i32 %44)
%46 = load i8*, i8** %6
%47 = load i32, i32* %8
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 0, i8* %49
%50 = load i8***, i8**** %5
%51 = icmp ne i8*** %50, null
br i1 %51, label %52, label %62
52: ; preds = %40
%53 = load i8*, i8** %6
%54 = call i8* @strchr(i8* %53, i8 signext 63)
store i8* %54, i8** %9
%55 = icmp ne i8* %54, null
br i1 %55, label %56, label %61
56: ; preds = %52
%57 = load i8*, i8** %9
%58 = getelementptr inbounds i8, i8* %57, i64 1
%59 = call i8** @parse_string(i8* %58)
%60 = load i8***, i8**** %5
store i8** %59, i8*** %60
br label %61
61: ; preds = %56, %52
br label %62
62: ; preds = %61, %40
%63 = load i8*, i8** %6
store i8* %63, i8** %3
br label %64
64: ; preds = %62, %39, %25, %13
%65 = load i8*, i8** %3
ret i8* %65
}

LLVM IR (-O2):
@.str = [5 x i8] c"GET \00"
@.str.1 = [7 x i8] c" HTTP/\00"
@.str.2 = [7 x i8] c" http/\00"
define i8* @http_parse(i8* %0, i8*** writeonly %1) {
%3 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %33
5: ; preds = %2
%6 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %33, label %11
11: ; preds = %5, %8
%12 = phi i8* [ %9, %8 ], [ %6, %5 ]
%13 = ptrtoint i8* %12 to i64
%14 = ptrtoint i8* %0 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
%17 = add i32 %16, -4
%18 = add i32 %16, -3
%19 = tail call i8* @malloc(i32 %18)
%20 = icmp eq i8* %19, null
br i1 %20, label %33, label %21
21: ; preds = %11
%22 = getelementptr inbounds i8, i8* %0, i64 4
%23 = tail call i32 @strncpy(i8* %19, i8* %22, i32 %17)
%24 = sext i32 %17 to i64
%25 = getelementptr inbounds i8, i8* %19, i64 %24
store i8 0, i8* %25
%26 = icmp eq i8*** %1, null
br i1 %26, label %33, label %27
27: ; preds = %21
%28 = tail call i8* @strchr(i8* %19, i8 signext 63)
%29 = icmp eq i8* %28, null
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = getelementptr inbounds i8, i8* %28, i64 1
%32 = tail call i8** @parse_string(i8* %31)
store i8** %32, i8*** %1
br label %33
33: ; preds = %21, %30, %27, %11, %8, %2
%34 = phi i8* [ null, %2 ], [ null, %8 ], [ null, %11 ], [ %19, %27 ], [ %19, %30 ], [ %19, %21 ]
ret i8* %34
}