#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 *concat(char *, char *);
char **continuous_substring(char *, char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fill_up_queue(char **);
int /*<<< orphan*/ free(char *);
char *get_kissmanga_page(char *);
char *get_series_path();
char *get_substring(char *, char *, char *, int);
int /*<<< orphan*/ parse_and_set_kissmanga_series_folder(char *);
char *strstr(char *, char *);
void download_kissmanga_series(char *randomChapterLink) {
  char *seriesPath = concat(get_series_path(), "/");
  char *concatedRandomLink = concat(seriesPath, randomChapterLink);
  free(seriesPath);
  char *initialPage = get_kissmanga_page(concatedRandomLink);
  free(concatedRandomLink);
  if (initialPage == NULL) {
    exit(26);
  }
  parse_and_set_kissmanga_series_folder(initialPage);
  char *skipFirst = strstr(initialPage, "</select>");
  if (skipFirst == NULL) {
    free(initialPage);
    exit(26);
  }
  skipFirst = skipFirst + 9;
  char *chaptersSection =
      get_substring(skipFirst, "</select>", "</select>", 26);
  free(initialPage);
  char **chaptersUnparsed =
      continuous_substring(chaptersSection, "<option value=", "</option>");
  free(chaptersSection);
  fill_up_queue(chaptersUnparsed);
}


x86 assembly (clang, -O0):
<download_kissmanga_series>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <get_series_path@plt>
mov    %rax,%rdi
lea    0xe43(%rip),%rsi
call   1060 <concat@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <concat@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1050 <get_kissmanga_page@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
jne    120b <download_kissmanga_series+0x6b>
mov    $0x1a,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <parse_and_set_kissmanga_series_folder@plt>
mov    -0x20(%rbp),%rdi
lea    0xde3(%rip),%rsi
call   10b0 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1246 <download_kissmanga_series+0xa6>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1a,%edi
call   1090 <exit@plt>
mov    -0x28(%rbp),%rax
add    $0x9,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xda5(%rip),%rdx
mov    $0x1a,%ecx
mov    %rdx,%rsi
call   10c0 <get_substring@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
lea    0xd8a(%rip),%rsi
lea    0xd92(%rip),%rdx
call   1070 <continuous_substring@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1080 <fill_up_queue@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<download_kissmanga_series>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <get_series_path@plt>
lea    0xe4b(%rip),%rsi
mov    %rax,%rdi
call   1060 <concat@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <concat@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1050 <get_kissmanga_page@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
test   %rbx,%rbx
je     1260 <download_kissmanga_series+0xc0>
mov    %rbx,%rdi
call   10a0 <parse_and_set_kissmanga_series_folder@plt>
lea    0xe05(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strstr@plt>
test   %rax,%rax
je     126a <download_kissmanga_series+0xca>
add    $0x9,%rax
lea    0xded(%rip),%rdx
mov    %rax,%rdi
mov    %rdx,%rsi
mov    $0x1a,%ecx
call   10c0 <get_substring@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xdd5(%rip),%rsi
lea    0xddd(%rip),%rdx
mov    %r14,%rdi
call   1070 <continuous_substring@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <fill_up_queue@plt>
mov    $0x1a,%edi
call   1090 <exit@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1a,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [10 x i8] c"</select>\00"
@.str.2 = [15 x i8] c"<option value=\00"
@.str.3 = [10 x i8] c"</option>\00"
define void @download_kissmanga_series(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8**
store i8* %0, i8** %2
%9 = call i8* (...) @get_series_path()
%10 = call i8* @concat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = load i8*, i8** %2
%13 = call i8* @concat(i8* %11, i8* %12)
store i8* %13, i8** %4
%14 = load i8*, i8** %3
%15 = call i32 @free(i8* %14)
%16 = load i8*, i8** %4
%17 = call i8* @get_kissmanga_page(i8* %16)
store i8* %17, i8** %5
%18 = load i8*, i8** %4
%19 = call i32 @free(i8* %18)
%20 = load i8*, i8** %5
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %1
%23 = call i32 @exit(i32 26)
unreachable
24: ; preds = %1
%25 = load i8*, i8** %5
%26 = call i32 @parse_and_set_kissmanga_series_folder(i8* %25)
%27 = load i8*, i8** %5
%28 = call i8* @strstr(i8* %27, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i8* %28, i8** %6
%29 = load i8*, i8** %6
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %35
31: ; preds = %24
%32 = load i8*, i8** %5
%33 = call i32 @free(i8* %32)
%34 = call i32 @exit(i32 26)
unreachable
35: ; preds = %24
%36 = load i8*, i8** %6
%37 = getelementptr inbounds i8, i8* %36, i64 9
store i8* %37, i8** %6
%38 = load i8*, i8** %6
%39 = call i8* @get_substring(i8* %38, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 26)
store i8* %39, i8** %7
%40 = load i8*, i8** %5
%41 = call i32 @free(i8* %40)
%42 = load i8*, i8** %7
%43 = call i8** @continuous_substring(i8* %42, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
store i8** %43, i8*** %8
%44 = load i8*, i8** %7
%45 = call i32 @free(i8* %44)
%46 = load i8**, i8*** %8
%47 = call i32 @fill_up_queue(i8** %46)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [10 x i8] c"</select>\00"
@.str.2 = [15 x i8] c"<option value=\00"
@.str.3 = [10 x i8] c"</option>\00"
define void @download_kissmanga_series(i8* %0) {
%2 = tail call i8* (...) @get_series_path()
%3 = tail call i8* @concat(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @concat(i8* %3, i8* %0)
%5 = tail call i32 @free(i8* %3)
%6 = tail call i8* @get_kissmanga_page(i8* %4)
%7 = tail call i32 @free(i8* %4)
%8 = icmp eq i8* %6, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = tail call i32 @exit(i32 26)
unreachable
11: ; preds = %1
%12 = tail call i32 @parse_and_set_kissmanga_series_folder(i8* %6)
%13 = tail call i8* @strstr(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = tail call i32 @free(i8* %6)
%17 = tail call i32 @exit(i32 26)
unreachable
18: ; preds = %11
%19 = getelementptr inbounds i8, i8* %13, i64 9
%20 = tail call i8* @get_substring(i8* %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 26)
%21 = tail call i32 @free(i8* %6)
%22 = tail call i8** @continuous_substring(i8* %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%23 = tail call i32 @free(i8* %20)
%24 = tail call i32 @fill_up_queue(i8** %22)
ret void
}