#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 *calloc(int, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
void extract_http_path(char *fullPath, char **destPtr) {
  int n = 0;
  int end = 0;
  while ((fullPath[n] != '\0') && (!end)) {
    switch (fullPath[n]) {
    case '?':
      end = 1;
      break;
    case '#':
      end = 1;
      break;
    default:
      n++;
      break;
    }
  }
  *destPtr = calloc(1, n + 1);
  memcpy(*destPtr, fullPath, n);
}


x86 assembly (clang, -O0):
<extract_http_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     1164 <extract_http_path+0x44>
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1174 <extract_http_path+0x54>
jmp    11c8 <extract_http_path+0xa8>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x20(%rbp)
sub    $0x23,%eax
je     11ae <extract_http_path+0x8e>
jmp    1191 <extract_http_path+0x71>
mov    -0x20(%rbp),%eax
sub    $0x3f,%eax
jne    11ba <extract_http_path+0x9a>
jmp    11a2 <extract_http_path+0x82>
movl   $0x1,-0x18(%rbp)
jmp    11c3 <extract_http_path+0xa3>
movl   $0x1,-0x18(%rbp)
jmp    11c3 <extract_http_path+0xa3>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <extract_http_path+0x1e>
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    $0x1,%edi
call   1030 <calloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_http_path>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%al
xor    %ebx,%ebx
test   %al,%al
je     115b <extract_http_path+0x3b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%eax
cmp    $0x23,%eax
je     115b <extract_http_path+0x3b>
cmp    $0x3f,%eax
je     115b <extract_http_path+0x3b>
movzbl 0x1(%r15,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    1140 <extract_http_path+0x20>
lea    0x1(%rbx),%esi
mov    $0x1,%edi
call   1030 <calloc@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <memcpy@plt>

LLVM IR (-O0):
define void @extract_http_path(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %33, %2
%8 = load i8*, i8** %3
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %7
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
br label %19
19: ; preds = %15, %7
%20 = phi i1 [ false, %7 ], [ %18, %15 ]
br i1 %20, label %21, label %34
21: ; preds = %19
%22 = load i8*, i8** %3
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
switch i32 %27, label %30 [
i32 63, label %28
i32 35, label %29
]
28: ; preds = %21
store i32 1, i32* %6
br label %33
29: ; preds = %21
store i32 1, i32* %6
br label %33
30: ; preds = %21
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %33
33: ; preds = %30, %29, %28
br label %7
34: ; preds = %19
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
%37 = call i8* @calloc(i32 1, i32 %36)
%38 = load i8**, i8*** %4
store i8* %37, i8** %38
%39 = load i8**, i8*** %4
%40 = load i8*, i8** %39
%41 = load i8*, i8** %3
%42 = load i32, i32* %5
%43 = call i32 @memcpy(i8* %40, i8* %41, i32 %42)
ret void
}

LLVM IR (-O2):
define void @extract_http_path(i8* %0, i8** nocapture writeonly %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %2, %9
%6 = phi i8 [ %13, %9 ], [ %3, %2 ]
%7 = phi i32 [ %10, %9 ], [ 0, %2 ]
%8 = sext i8 %6 to i32
switch i32 %8, label %9 [
i32 63, label %15
i32 35, label %15
]
9: ; preds = %5
%10 = add nuw nsw i32 %7, 1
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %5
15: ; preds = %5, %5, %9, %2
%16 = phi i32 [ 0, %2 ], [ %7, %5 ], [ %7, %5 ], [ %10, %9 ]
%17 = add nsw i32 %16, 1
%18 = tail call i8* @calloc(i32 1, i32 %17)
store i8* %18, i8** %1
%19 = tail call i32 @memcpy(i8* %18, i8* %0, i32 %16)
ret void
}