#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__ filter_type_url(char *, int);
int sscanf(char *, char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncasecmp(char *, char *, int);
void parse_page(char *mem, void *total, void (*cb_func)(char *url, void *)) {
  char *p, *fmt;
  int len, n;
  char buf[4096];
  p = mem;
  fmt = "%*[\" \t\r\n=']%4096[^ \t'\"<>)\r]";
  len = -1;
  for (; *p; p++) {
    if (!strncasecmp(p, "href", 4)) {
      len = 4;
    }
    if (len != -1) {
      p += len;
      len = -1;
      if (sscanf(p, fmt, buf) == 1) {
        n = strlen(buf);
        if (filter_type_url(buf, n) == 0) {
          filter_type_url(buf, n);
          cb_func(buf, total);
          p += n;
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<parse_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     125b <parse_page+0x11b>
mov    -0x20(%rbp),%rdi
lea    0xe93(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%eax
jne    11a3 <parse_page+0x63>
movl   $0x4,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
je     1245 <parse_page+0x105>
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x1030(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1240 <parse_page+0x100>
lea    -0x1030(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x30(%rbp)
lea    -0x1030(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1060 <filter_type_url@plt>
cmp    $0x0,%rax
jne    123b <parse_page+0xfb>
lea    -0x1030(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1060 <filter_type_url@plt>
mov    -0x18(%rbp),%rax
lea    -0x1030(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   *%rax
mov    -0x30(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    1240 <parse_page+0x100>
jmp    1245 <parse_page+0x105>
jmp    124a <parse_page+0x10a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1171 <parse_page+0x31>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_page>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rdx,0x8(%rsp)
cmpb   $0x0,(%rdi)
je     11ec <parse_page+0xac>
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xeb0(%rip),%r12
lea    0xe8d(%rip),%r13
lea    0x10(%rsp),%rbp
jmp    118a <parse_page+0x4a>
nopw   0x0(%rax,%rax,1)
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
je     11ec <parse_page+0xac>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1040 <strncasecmp@plt>
test   %eax,%eax
jne    1180 <parse_page+0x40>
add    $0x4,%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1180 <parse_page+0x40>
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
mov    %eax,%esi
call   1060 <filter_type_url@plt>
test   %rax,%rax
jne    1180 <parse_page+0x40>
mov    %rbp,%rdi
mov    %r14d,%esi
call   1060 <filter_type_url@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   *0x8(%rsp)
movslq %r14d,%rax
add    %rax,%rbx
jmp    1180 <parse_page+0x40>
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"%*[\22 \09\0D\0A=']%4096[^ \09'\22<>)\0D]\00"
@.str.1 = [5 x i8] c"href\00"
define void @parse_page(i8* %0, i8* %1, void (i8*, i8*)* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca void (i8*, i8*)*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca [4096 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store void (i8*, i8*)* %2, void (i8*, i8*)** %6
%12 = load i8*, i8** %4
store i8* %12, i8** %7
store i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8** %8
store i32 -1, i32* %9
br label %13
13: ; preds = %56, %3
%14 = load i8*, i8** %7
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %59
17: ; preds = %13
%18 = load i8*, i8** %7
%19 = call i32 @strncasecmp(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %17
store i32 4, i32* %9
br label %22
22: ; preds = %21, %17
%23 = load i32, i32* %9
%24 = icmp ne i32 %23, -1
br i1 %24, label %25, label %55
25: ; preds = %22
%26 = load i32, i32* %9
%27 = load i8*, i8** %7
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8* %29, i8** %7
store i32 -1, i32* %9
%30 = load i8*, i8** %7
%31 = load i8*, i8** %8
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%33 = call i32 @sscanf(i8* %30, i8* %31, i8* %32)
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %54
35: ; preds = %25
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%37 = call i32 @strlen(i8* %36)
store i32 %37, i32* %10
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%39 = load i32, i32* %10
%40 = call i64 @filter_type_url(i8* %38, i32 %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %53
42: ; preds = %35
%43 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%44 = load i32, i32* %10
%45 = call i64 @filter_type_url(i8* %43, i32 %44)
%46 = load void (i8*, i8*)*, void (i8*, i8*)** %6
%47 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%48 = load i8*, i8** %5
%49 = load i32, i32* %10
%50 = load i8*, i8** %7
%51 = sext i32 %49 to i64
%52 = getelementptr inbounds i8, i8* %50, i64 %51
store i8* %52, i8** %7
br label %53
53: ; preds = %42, %35
br label %54
54: ; preds = %53, %25
br label %55
55: ; preds = %54, %22
br label %56
56: ; preds = %55
%57 = load i8*, i8** %7
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %7
br label %13
59: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"%*[\22 \09\0D\0A=']%4096[^ \09'\22<>)\0D]\00"
@.str.1 = [5 x i8] c"href\00"
define void @parse_page(i8* nocapture %0, i8* %1, void (i8*, i8*)* nocapture %2) {
%4 = alloca [4096 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %29, label %8
8: ; preds = %3, %24
%9 = phi i8* [ %26, %24 ], [ %0, %3 ]
%10 = call i32 @strncasecmp(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %9, i64 4
%14 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %5)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = call i32 @strlen(i8* %5)
%18 = call i64 @filter_type_url(i8* %5, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = call i64 @filter_type_url(i8* %5, i32 %17)
%22 = sext i32 %17 to i64
%23 = getelementptr inbounds i8, i8* %13, i64 %22
br label %24
24: ; preds = %8, %16, %20, %12
%25 = phi i8* [ %23, %20 ], [ %13, %16 ], [ %13, %12 ], [ %9, %8 ]
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %8
29: ; preds = %24, %3
ret void
}