#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 *getenv(char *);
char *malloc(int);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ url_decode(char *);
char *query_string_path() {
  char *path;
  char *query_string;
  int length;
  query_string = getenv("QUERY_STRING");
  if (NULL != query_string && 0 == strncmp("path=", query_string, 5)) {
    length = strlen(query_string);
    path = malloc(length);
    strncpy(path, query_string + 5, length - 5);
  }
  url_decode(path);
  return path;
}


x86 assembly (clang, -O0):
<query_string_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     11d6 <query_string_path+0x76>
mov    -0x10(%rbp),%rsi
lea    0xe7e(%rip),%rdi
mov    $0x5,%edx
call   1050 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11d6 <query_string_path+0x76>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x5,%rsi
mov    -0x14(%rbp),%edx
sub    $0x5,%edx
call   1040 <strncpy@plt>
mov    -0x8(%rbp),%rdi
call   1070 <url_decode@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<query_string_path>:
push   %rbp
push   %r14
push   %rbx
lea    0xe95(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11bb <query_string_path+0x5b>
mov    %rax,%rbx
lea    0xe8e(%rip),%rdi
mov    %rax,%rsi
mov    $0x5,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
jne    11bb <query_string_path+0x5b>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
add    $0x5,%rbx
add    $0xfffffffb,%ebp
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <strncpy@plt>
jmp    11bb <query_string_path+0x5b>
mov    %r14,%rdi
call   1070 <url_decode@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"QUERY_STRING\00"
@.str.1 = [6 x i8] c"path=\00"
define i8* @query_string_path() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32
%4 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* null, %5
br i1 %6, label %7, label %22
7: ; preds = %0
%8 = load i8*, i8** %2
%9 = call i64 @strncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %8, i32 5)
%10 = icmp eq i64 0, %9
br i1 %10, label %11, label %22
11: ; preds = %7
%12 = load i8*, i8** %2
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = call i8* @malloc(i32 %14)
store i8* %15, i8** %1
%16 = load i8*, i8** %1
%17 = load i8*, i8** %2
%18 = getelementptr inbounds i8, i8* %17, i64 5
%19 = load i32, i32* %3
%20 = sub nsw i32 %19, 5
%21 = call i32 @strncpy(i8* %16, i8* %18, i32 %20)
br label %22
22: ; preds = %11, %7, %0
%23 = load i8*, i8** %1
%24 = call i32 @url_decode(i8* %23)
%25 = load i8*, i8** %1
ret i8* %25
}

LLVM IR (-O2):
@.str = [13 x i8] c"QUERY_STRING\00"
@.str.1 = [6 x i8] c"path=\00"
define i8* @query_string_path() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %12, label %3
3: ; preds = %0
%4 = tail call i64 @strncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 5)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %1)
%8 = tail call i8* @malloc(i32 %7)
%9 = getelementptr inbounds i8, i8* %1, i64 5
%10 = add nsw i32 %7, -5
%11 = tail call i32 @strncpy(i8* %8, i8* %9, i32 %10)
br label %12
12: ; preds = %6, %3, %0
%13 = phi i8* [ %8, %6 ], [ undef, %3 ], [ undef, %0 ]
%14 = tail call i32 @url_decode(i8* %13)
ret i8* %13
}