#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 */
scalar_t__ compare_tag(unsigned char const *, unsigned char const *, int);
int /*<<< orphan*/ custom_strncasecmp(unsigned char const *, char *, int);
int return_chars_until_chr(unsigned char const *, char);
int return_javascript_body_len(unsigned char const *);
int return_junky_chunk_len(const unsigned char *src,
                           const unsigned char *closing_tag,
                           int closing_tag_len) {
  const unsigned char *rpos = src;
  int junklen = 0;
  int otagsize;
  int bodysize;
  int ctagsize;
  if (!custom_strncasecmp(closing_tag, "SCRIPT", 6)) {
    otagsize = return_chars_until_chr(rpos, '>');
    rpos += otagsize;
    bodysize = return_javascript_body_len(rpos);
    rpos += bodysize;
    ctagsize = return_chars_until_chr(rpos, '>');
    junklen += (otagsize + bodysize + ctagsize);
  } else {
    while (*rpos != '\0') {
      if (*rpos == '<') {
        if (*(rpos + 1) == '/') {
          if (compare_tag(rpos + 2, closing_tag, closing_tag_len) == 0) {
            return (junklen + 2 + return_chars_until_chr(rpos + 2, '>'));
          }
        }
      }
      junklen++;
      rpos++;
    }
  }
  return (junklen);
}


x86 assembly (clang, -O0):
<return_junky_chunk_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe93(%rip),%rsi
mov    $0x6,%edx
call   1060 <custom_strncasecmp@plt>
cmp    $0x0,%eax
jne    11e4 <return_junky_chunk_len+0xa4>
mov    -0x28(%rbp),%rdi
mov    $0x3e,%esi
call   1040 <return_chars_until_chr@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <return_javascript_body_len@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x3e,%esi
call   1040 <return_chars_until_chr@plt>
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%eax
add    -0x34(%rbp),%eax
add    -0x38(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    128b <return_junky_chunk_len+0x14b>
jmp    11e9 <return_junky_chunk_len+0xa9>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
je     1286 <return_junky_chunk_len+0x146>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x3c,%eax
jne    126c <return_junky_chunk_len+0x12c>
mov    -0x28(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x2f,%eax
jne    1267 <return_junky_chunk_len+0x127>
mov    -0x28(%rbp),%rdi
add    $0x2,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <compare_tag@plt>
cmp    $0x0,%rax
jne    1262 <return_junky_chunk_len+0x122>
mov    -0x2c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x2,%rdi
mov    $0x3e,%esi
call   1040 <return_chars_until_chr@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1291 <return_junky_chunk_len+0x151>
jmp    1267 <return_junky_chunk_len+0x127>
jmp    126c <return_junky_chunk_len+0x12c>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11e9 <return_junky_chunk_len+0xa9>
jmp    128b <return_junky_chunk_len+0x14b>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<return_junky_chunk_len>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0xea9(%rip),%rsi
mov    %rbp,%rdi
mov    $0x6,%edx
call   1060 <custom_strncasecmp@plt>
test   %eax,%eax
je     11c3 <return_junky_chunk_len+0x83>
add    $0x2,%rbx
xor    %r14d,%r14d
jmp    118c <return_junky_chunk_len+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   %al,%al
je     11f7 <return_junky_chunk_len+0xb7>
add    $0x1,%r14d
add    $0x1,%rbx
movzbl -0x2(%rbx),%eax
cmp    $0x3c,%al
jne    1180 <return_junky_chunk_len+0x40>
cmpb   $0x2f,-0x1(%rbx)
jne    1184 <return_junky_chunk_len+0x44>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
call   1050 <compare_tag@plt>
test   %rax,%rax
jne    1184 <return_junky_chunk_len+0x44>
mov    %rbx,%rdi
mov    $0x3e,%esi
call   1040 <return_chars_until_chr@plt>
add    %eax,%r14d
add    $0x2,%r14d
jmp    11f7 <return_junky_chunk_len+0xb7>
mov    %rbx,%rdi
mov    $0x3e,%esi
call   1040 <return_chars_until_chr@plt>
movslq %eax,%rbp
add    %rbp,%rbx
mov    %rbx,%rdi
call   1030 <return_javascript_body_len@plt>
movslq %eax,%r14
add    %r14,%rbx
mov    %rbx,%rdi
mov    $0x3e,%esi
call   1040 <return_chars_until_chr@plt>
add    %ebp,%r14d
add    %eax,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"SCRIPT\00"
define i32 @return_junky_chunk_len(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%13 = load i8*, i8** %5
store i8* %13, i8** %8
store i32 0, i32* %9
%14 = load i8*, i8** %6
%15 = call i32 @custom_strncasecmp(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%16 = icmp ne i32 %15, 0
br i1 %16, label %39, label %17
17: ; preds = %3
%18 = load i8*, i8** %8
%19 = call i32 @return_chars_until_chr(i8* %18, i8 signext 62)
store i32 %19, i32* %10
%20 = load i32, i32* %10
%21 = load i8*, i8** %8
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds i8, i8* %21, i64 %22
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = call i32 @return_javascript_body_len(i8* %24)
store i32 %25, i32* %11
%26 = load i32, i32* %11
%27 = load i8*, i8** %8
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8* %29, i8** %8
%30 = load i8*, i8** %8
%31 = call i32 @return_chars_until_chr(i8* %30, i8 signext 62)
store i32 %31, i32* %12
%32 = load i32, i32* %10
%33 = load i32, i32* %11
%34 = add nsw i32 %32, %33
%35 = load i32, i32* %12
%36 = add nsw i32 %34, %35
%37 = load i32, i32* %9
%38 = add nsw i32 %37, %36
store i32 %38, i32* %9
br label %78
39: ; preds = %3
br label %40
40: ; preds = %72, %39
%41 = load i8*, i8** %8
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %77
45: ; preds = %40
%46 = load i8*, i8** %8
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = icmp eq i32 %48, 60
br i1 %49, label %50, label %72
50: ; preds = %45
%51 = load i8*, i8** %8
%52 = getelementptr inbounds i8, i8* %51, i64 1
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = icmp eq i32 %54, 47
br i1 %55, label %56, label %71
56: ; preds = %50
%57 = load i8*, i8** %8
%58 = getelementptr inbounds i8, i8* %57, i64 2
%59 = load i8*, i8** %6
%60 = load i32, i32* %7
%61 = call i64 @compare_tag(i8* %58, i8* %59, i32 %60)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %70
63: ; preds = %56
%64 = load i32, i32* %9
%65 = add nsw i32 %64, 2
%66 = load i8*, i8** %8
%67 = getelementptr inbounds i8, i8* %66, i64 2
%68 = call i32 @return_chars_until_chr(i8* %67, i8 signext 62)
%69 = add nsw i32 %65, %68
store i32 %69, i32* %4
br label %80
70: ; preds = %56
br label %71
71: ; preds = %70, %50
br label %72
72: ; preds = %71, %45
%73 = load i32, i32* %9
%74 = add nsw i32 %73, 1
store i32 %74, i32* %9
%75 = load i8*, i8** %8
%76 = getelementptr inbounds i8, i8* %75, i32 1
store i8* %76, i8** %8
br label %40
77: ; preds = %40
br label %78
78: ; preds = %77, %17
%79 = load i32, i32* %9
store i32 %79, i32* %4
br label %80
80: ; preds = %78, %63
%81 = load i32, i32* %4
ret i32 %81
}

LLVM IR (-O2):
@.str = [7 x i8] c"SCRIPT\00"
define i32 @return_junky_chunk_len(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @custom_strncasecmp(i8* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %16
6: ; preds = %3
%7 = tail call i32 @return_chars_until_chr(i8* %0, i8 signext 62)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = tail call i32 @return_javascript_body_len(i8* %9)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = tail call i32 @return_chars_until_chr(i8* %12, i8 signext 62)
%14 = add nsw i32 %10, %7
%15 = add nsw i32 %14, %13
br label %35
16: ; preds = %3, %32
%17 = phi i32 [ %33, %32 ], [ 0, %3 ]
%18 = phi i8* [ %34, %32 ], [ %0, %3 ]
%19 = load i8, i8* %18
switch i8 %19, label %32 [
i8 0, label %35
i8 60, label %20
]
20: ; preds = %16
%21 = getelementptr inbounds i8, i8* %18, i64 1
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 47
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = getelementptr inbounds i8, i8* %18, i64 2
%26 = tail call i64 @compare_tag(i8* %25, i8* %1, i32 %2)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = add nuw nsw i32 %17, 2
%30 = tail call i32 @return_chars_until_chr(i8* %25, i8 signext 62)
%31 = add nsw i32 %29, %30
br label %35
32: ; preds = %16, %20, %24
%33 = add nuw nsw i32 %17, 1
%34 = getelementptr inbounds i8, i8* %18, i64 1
br label %16
35: ; preds = %16, %6, %28
%36 = phi i32 [ %31, %28 ], [ %15, %6 ], [ %17, %16 ]
ret i32 %36
}