#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 *URL_encode(char *const);
int /*<<< orphan*/ free(char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
char *strstr(char *, char *);
bool dissect_address(char *const address, char *host,
                     const size_t max_host_length, char *resource,
                     const size_t max_resource_length) {
  char *encoded_addr = URL_encode(address);
  char *start_pos = strstr(encoded_addr, "://");
  start_pos = ((start_pos == NULL) ? (char *)encoded_addr : start_pos + 3);
  char *slash_pos = strchr(start_pos, '/');
  if (slash_pos == NULL || slash_pos[1] == '\0') {
    strcpy(host, start_pos);
    if (slash_pos != NULL)
      strchr(host, '/')[0] = '\0';
    strcpy(resource, "/");
    free(encoded_addr);
    return true;
  }
  char *addr_end = strchr(slash_pos, '\0');
  if (start_pos >= slash_pos - 1) {
    free(encoded_addr);
    return false;
  }
  if (slash_pos - start_pos > max_host_length) {
    free(encoded_addr);
    return false;
  }
  if (addr_end - slash_pos > max_resource_length) {
    free(encoded_addr);
    return false;
  }
  strcpy(host, start_pos);
  host[slash_pos - start_pos] = '\0';
  strcpy(resource, slash_pos);
  resource[addr_end - slash_pos] = '\0';
  free(encoded_addr);
  return true;
}


x86 assembly (clang, -O0):
<dissect_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <URL_encode@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11a5 <dissect_address+0x55>
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
jmp    11b1 <dissect_address+0x61>
mov    -0x40(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     11e7 <dissect_address+0x97>
mov    -0x48(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1235 <dissect_address+0xe5>
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1040 <strcpy@plt>
cmpq   $0x0,-0x48(%rbp)
je     1210 <dissect_address+0xc0>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
lea    0xde7(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    1312 <dissect_address+0x1c2>
mov    -0x48(%rbp),%rdi
xor    %esi,%esi
call   1060 <strchr@plt>
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x48(%rbp),%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jb     126e <dissect_address+0x11e>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1312 <dissect_address+0x1c2>
mov    -0x48(%rbp),%rax
mov    -0x40(%rbp),%rcx
sub    %rcx,%rax
cmp    -0x20(%rbp),%rax
jbe    1298 <dissect_address+0x148>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1312 <dissect_address+0x1c2>
mov    -0x50(%rbp),%rax
mov    -0x48(%rbp),%rcx
sub    %rcx,%rax
cmp    -0x30(%rbp),%rax
jbe    12c2 <dissect_address+0x172>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1312 <dissect_address+0x1c2>
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    -0x40(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dissect_address>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r14
mov    %rcx,%rbp
mov    %rdx,0x10(%rsp)
mov    %rsi,%r15
call   1050 <URL_encode@plt>
mov    %rax,%r13
lea    0xe75(%rip),%rsi
mov    %rax,%rdi
call   1080 <strstr@plt>
lea    0x3(%rax),%rbx
test   %rax,%rax
cmove  %r13,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     1214 <dissect_address+0xb4>
mov    %rax,%r12
cmpb   $0x0,0x1(%rax)
je     1221 <dissect_address+0xc1>
mov    %r14,0x8(%rsp)
mov    %r12,%rdi
call   1060 <strlen@plt>
lea    -0x1(%r12),%rcx
xor    %r14d,%r14d
cmp    %rcx,%rbx
jae    1251 <dissect_address+0xf1>
mov    %rbp,(%rsp)
mov    %r12,%rbp
sub    %rbx,%rbp
cmp    0x10(%rsp),%rbp
ja     1251 <dissect_address+0xf1>
cmp    0x8(%rsp),%rax
ja     1251 <dissect_address+0xf1>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rax,%r14
call   1040 <strcpy@plt>
movb   $0x0,(%r15,%rbp,1)
mov    (%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
movb   $0x0,(%rbx,%r14,1)
jmp    124b <dissect_address+0xeb>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
jmp    123c <dissect_address+0xdc>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
movb   $0x0,(%rax)
lea    0xdbf(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcpy@plt>
mov    $0x1,%r14d
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"://\00"
@.str.1 = [2 x i8] c"/\00"
define i32 @dissect_address(i8* %0, i8* %1, i64 %2, i8* %3, i64 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i8* %3, i8** %10
store i64 %4, i64* %11
%16 = load i8*, i8** %7
%17 = call i8* @URL_encode(i8* %16)
store i8* %17, i8** %12
%18 = load i8*, i8** %12
%19 = call i8* @strstr(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %19, i8** %13
%20 = load i8*, i8** %13
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %5
%23 = load i8*, i8** %12
br label %27
24: ; preds = %5
%25 = load i8*, i8** %13
%26 = getelementptr inbounds i8, i8* %25, i64 3
br label %27
27: ; preds = %24, %22
%28 = phi i8* [ %23, %22 ], [ %26, %24 ]
store i8* %28, i8** %13
%29 = load i8*, i8** %13
%30 = call i8* @strchr(i8* %29, i8 signext 47)
store i8* %30, i8** %14
%31 = load i8*, i8** %14
%32 = icmp eq i8* %31, null
br i1 %32, label %39, label %33
33: ; preds = %27
%34 = load i8*, i8** %14
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %54
39: ; preds = %33, %27
%40 = load i8*, i8** %8
%41 = load i8*, i8** %13
%42 = call i32 @strcpy(i8* %40, i8* %41)
%43 = load i8*, i8** %14
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %49
45: ; preds = %39
%46 = load i8*, i8** %8
%47 = call i8* @strchr(i8* %46, i8 signext 47)
%48 = getelementptr inbounds i8, i8* %47, i64 0
store i8 0, i8* %48
br label %49
49: ; preds = %45, %39
%50 = load i8*, i8** %10
%51 = call i32 @strcpy(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%52 = load i8*, i8** %12
%53 = call i32 @free(i8* %52)
store i32 1, i32* %6
br label %109
54: ; preds = %33
%55 = load i8*, i8** %14
%56 = call i8* @strchr(i8* %55, i8 signext 0)
store i8* %56, i8** %15
%57 = load i8*, i8** %13
%58 = load i8*, i8** %14
%59 = getelementptr inbounds i8, i8* %58, i64 -1
%60 = icmp uge i8* %57, %59
br i1 %60, label %61, label %64
61: ; preds = %54
%62 = load i8*, i8** %12
%63 = call i32 @free(i8* %62)
store i32 0, i32* %6
br label %109
64: ; preds = %54
%65 = load i8*, i8** %14
%66 = load i8*, i8** %13
%67 = ptrtoint i8* %65 to i64
%68 = ptrtoint i8* %66 to i64
%69 = sub i64 %67, %68
%70 = load i64, i64* %9
%71 = icmp ugt i64 %69, %70
br i1 %71, label %72, label %75
72: ; preds = %64
%73 = load i8*, i8** %12
%74 = call i32 @free(i8* %73)
store i32 0, i32* %6
br label %109
75: ; preds = %64
%76 = load i8*, i8** %15
%77 = load i8*, i8** %14
%78 = ptrtoint i8* %76 to i64
%79 = ptrtoint i8* %77 to i64
%80 = sub i64 %78, %79
%81 = load i64, i64* %11
%82 = icmp ugt i64 %80, %81
br i1 %82, label %83, label %86
83: ; preds = %75
%84 = load i8*, i8** %12
%85 = call i32 @free(i8* %84)
store i32 0, i32* %6
br label %109
86: ; preds = %75
%87 = load i8*, i8** %8
%88 = load i8*, i8** %13
%89 = call i32 @strcpy(i8* %87, i8* %88)
%90 = load i8*, i8** %8
%91 = load i8*, i8** %14
%92 = load i8*, i8** %13
%93 = ptrtoint i8* %91 to i64
%94 = ptrtoint i8* %92 to i64
%95 = sub i64 %93, %94
%96 = getelementptr inbounds i8, i8* %90, i64 %95
store i8 0, i8* %96
%97 = load i8*, i8** %10
%98 = load i8*, i8** %14
%99 = call i32 @strcpy(i8* %97, i8* %98)
%100 = load i8*, i8** %10
%101 = load i8*, i8** %15
%102 = load i8*, i8** %14
%103 = ptrtoint i8* %101 to i64
%104 = ptrtoint i8* %102 to i64
%105 = sub i64 %103, %104
%106 = getelementptr inbounds i8, i8* %100, i64 %105
store i8 0, i8* %106
%107 = load i8*, i8** %12
%108 = call i32 @free(i8* %107)
store i32 1, i32* %6
br label %109
109: ; preds = %86, %83, %72, %61, %49
%110 = load i32, i32* %6
ret i32 %110
}

LLVM IR (-O2):
@.str = [4 x i8] c"://\00"
@.str.1 = [2 x i8] c"/\00"
define i32 @dissect_address(i8* %0, i8* %1, i64 %2, i8* %3, i64 %4) {
%6 = tail call i8* @URL_encode(i8* %0)
%7 = tail call i8* @strstr(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
%9 = getelementptr inbounds i8, i8* %7, i64 3
%10 = select i1 %8, i8* %6, i8* %9
%11 = tail call i8* @strchr(i8* dereferenceable(1) %10, i8 signext 47)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %5
%14 = tail call i32 @strcpy(i8* %1, i8* %10)
br label %22
15: ; preds = %5
%16 = getelementptr inbounds i8, i8* %11, i64 1
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = tail call i32 @strcpy(i8* %1, i8* %10)
%21 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 47)
store i8 0, i8* %21
br label %22
22: ; preds = %13, %19
%23 = tail call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %40
24: ; preds = %15
%25 = tail call i64 @strlen(i8* %11)
%26 = getelementptr inbounds i8, i8* %11, i64 -1
%27 = icmp ult i8* %10, %26
br i1 %27, label %28, label %40
28: ; preds = %24
%29 = ptrtoint i8* %11 to i64
%30 = ptrtoint i8* %10 to i64
%31 = sub i64 %29, %30
%32 = icmp ugt i64 %31, %2
%33 = icmp ugt i64 %25, %4
%34 = select i1 %32, i1 true, i1 %33
br i1 %34, label %40, label %35
35: ; preds = %28
%36 = tail call i32 @strcpy(i8* %1, i8* %10)
%37 = getelementptr inbounds i8, i8* %1, i64 %31
store i8 0, i8* %37
%38 = tail call i32 @strcpy(i8* %3, i8* %11)
%39 = getelementptr inbounds i8, i8* %3, i64 %25
store i8 0, i8* %39
br label %40
40: ; preds = %28, %24, %35, %22
%41 = phi i32 [ 1, %22 ], [ 1, %35 ], [ 0, %24 ], [ 0, %28 ]
%42 = tail call i32 @free(i8* %6)
ret i32 %41
}