#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 */
int /*<<< orphan*/ sprintf(char *, char *, char const *);
scalar_t__ strlen(char *);
char *strstrn(char const *, char *, int);
int XMLParserStrict_getNumTagsOccurances(const char *pBuff, const int iBuffLen,
                                         const char *tagName) {
  const char *curLoc, *XMLend;
  char curTagEnd[(128)], curTagBegin[(128)];
  const char *curTagOpenLoc, *curTagCloseLoc;
  int i;
  if ((iBuffLen <= 0) || (tagName == NULL))
    return -1;
  curLoc = pBuff;
  XMLend = pBuff + iBuffLen;
  sprintf(curTagBegin, "<%s>", tagName);
  sprintf(curTagEnd, "</%s>", tagName);
  ;
  for (i = 0; (*curLoc); i++) {
    curTagOpenLoc = strstrn(curLoc, curTagBegin, (int)(XMLend - curLoc));
    curTagCloseLoc = strstrn(curLoc, curTagEnd, (int)(XMLend - curLoc));
    if ((curTagOpenLoc == NULL) || (curTagCloseLoc == NULL) ||
        (curTagCloseLoc < curTagOpenLoc) ||
        (curTagCloseLoc > (pBuff + iBuffLen)))
      return i;
    curLoc = curTagCloseLoc + (int)strlen(curTagEnd);
  }
  return i;
}


x86 assembly (clang, -O0):
<XMLParserStrict_getNumTagsOccurances>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    115b <XMLParserStrict_getNumTagsOccurances+0x2b>
cmpq   $0x0,-0x20(%rbp)
jne    1167 <XMLParserStrict_getNumTagsOccurances+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    12af <XMLParserStrict_getNumTagsOccurances+0x17f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe70(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe5e(%rip),%rsi
call   1050 <sprintf@plt>
movl   $0x0,-0x144(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     12a6 <XMLParserStrict_getNumTagsOccurances+0x176>
mov    -0x28(%rbp),%rdi
lea    -0x130(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <strstrn@plt>
mov    %rax,-0x138(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <strstrn@plt>
mov    %rax,-0x140(%rbp)
cmpq   $0x0,-0x138(%rbp)
je     1256 <XMLParserStrict_getNumTagsOccurances+0x126>
cmpq   $0x0,-0x140(%rbp)
je     1256 <XMLParserStrict_getNumTagsOccurances+0x126>
mov    -0x140(%rbp),%rax
cmp    -0x138(%rbp),%rax
jb     1256 <XMLParserStrict_getNumTagsOccurances+0x126>
mov    -0x140(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jbe    1264 <XMLParserStrict_getNumTagsOccurances+0x134>
mov    -0x144(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12af <XMLParserStrict_getNumTagsOccurances+0x17f>
mov    -0x140(%rbp),%rax
mov    %rax,-0x150(%rbp)
lea    -0xb0(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x150(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x144(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x144(%rbp)
jmp    11b6 <XMLParserStrict_getNumTagsOccurances+0x86>
mov    -0x144(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<XMLParserStrict_getNumTagsOccurances>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    $0xffffffff,%r12d
test   %esi,%esi
jle    1208 <XMLParserStrict_getNumTagsOccurances+0xd8>
mov    %rdx,%r15
test   %rdx,%rdx
je     1208 <XMLParserStrict_getNumTagsOccurances+0xd8>
mov    %esi,%r14d
mov    %rdi,%rbp
lea    0xe98(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
call   1050 <sprintf@plt>
lea    0xe8b(%rip),%rsi
lea    0x80(%rsp),%rdi
mov    %r15,%rdx
call   1050 <sprintf@plt>
cmpb   $0x0,0x0(%rbp)
je     1205 <XMLParserStrict_getNumTagsOccurances+0xd5>
mov    %r14d,%r14d
add    %rbp,%r14
xor    %r12d,%r12d
lea    0x80(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14d,%ebx
sub    %ebp,%ebx
mov    %rbp,%rdi
mov    %rsp,%rsi
mov    %ebx,%edx
call   1040 <strstrn@plt>
mov    %rax,%r13
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <strstrn@plt>
test   %r13,%r13
je     1208 <XMLParserStrict_getNumTagsOccurances+0xd8>
mov    %rax,%rbx
test   %rax,%rax
je     1208 <XMLParserStrict_getNumTagsOccurances+0xd8>
cmp    %r13,%rbx
jb     1208 <XMLParserStrict_getNumTagsOccurances+0xd8>
cmp    %r14,%rbx
ja     1208 <XMLParserStrict_getNumTagsOccurances+0xd8>
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
mov    %rbx,%rbp
add    %rax,%rbp
add    $0x1,%r12d
cmpb   $0x0,(%rbx,%rax,1)
jne    11b0 <XMLParserStrict_getNumTagsOccurances+0x80>
jmp    1208 <XMLParserStrict_getNumTagsOccurances+0xd8>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"<%s>\00"
@.str.1 = [6 x i8] c"</%s>\00"
define i32 @XMLParserStrict_getNumTagsOccurances(i8* %0, i32 %1, i8* %2) {
%4 = alloca [128 x i8]
%5 = alloca [128 x i8]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%8 = icmp slt i32 %1, 1
%9 = icmp eq i8* %2, null
%10 = or i1 %8, %9
br i1 %10, label %43, label %11
11: ; preds = %3
%12 = zext i32 %1 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %2)
%15 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%16 = load i8, i8* %0
%17 = icmp eq i8 %16, 0
br i1 %17, label %43, label %18
18: ; preds = %11
%19 = ptrtoint i8* %13 to i64
br label %20
20: ; preds = %18, %35
%21 = phi i32 [ 0, %18 ], [ %40, %35 ]
%22 = phi i8* [ %0, %18 ], [ %39, %35 ]
%23 = ptrtoint i8* %22 to i64
%24 = sub i64 %19, %23
%25 = trunc i64 %24 to i32
%26 = call i8* @strstrn(i8* %22, i8* %7, i32 %25)
%27 = call i8* @strstrn(i8* %22, i8* %6, i32 %25)
%28 = icmp eq i8* %26, null
%29 = icmp eq i8* %27, null
%30 = select i1 %28, i1 true, i1 %29
%31 = icmp ult i8* %27, %26
%32 = select i1 %30, i1 true, i1 %31
%33 = icmp ugt i8* %27, %13
%34 = select i1 %32, i1 true, i1 %33
br i1 %34, label %43, label %35
35: ; preds = %20
%36 = call i64 @strlen(i8* %6)
%37 = shl i64 %36, 32
%38 = ashr exact i64 %37, 32
%39 = getelementptr inbounds i8, i8* %27, i64 %38
%40 = add nuw nsw i32 %21, 1
%41 = load i8, i8* %39
%42 = icmp eq i8 %41, 0
br i1 %42, label %43, label %20
43: ; preds = %20, %35, %11, %3
%44 = phi i32 [ -1, %3 ], [ 0, %11 ], [ %21, %20 ], [ %40, %35 ]
ret i32 %44
}