#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 atoi(char *);
char *strchr(char *, char);
int strlen(char *);
scalar_t__ strn_casecmp(char *, char *, int);
int has_trackID(char *inp, int *trackID) {
  int l;
  char *p;
  l = strlen(inp);
  if (l < 18)
    return 0;
  if (strn_casecmp(inp + l - 8, "RTSP/1.0", 8) != 0)
    return 0;
  p = inp;
  while (p) {
    p = strchr(p, '=');
    if (p - 7 < inp) {
      p++;
      continue;
    }
    if (strn_casecmp(p - 7, "trackid=", 8) != 0) {
      p++;
      continue;
    }
    *trackID = atoi(p + 1);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<has_trackID>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x12,-0x1c(%rbp)
jge    1172 <has_trackID+0x32>
movl   $0x0,-0x4(%rbp)
jmp    124c <has_trackID+0x10c>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffff8,%rdi
lea    0xe78(%rip),%rsi
mov    $0x8,%edx
call   1030 <strn_casecmp@plt>
cmp    $0x0,%rax
je     11a8 <has_trackID+0x68>
movl   $0x0,-0x4(%rbp)
jmp    124c <has_trackID+0x10c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1245 <has_trackID+0x105>
mov    -0x28(%rbp),%rdi
mov    $0x3d,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0xfffffffffffffff9,%rax
cmp    -0x10(%rbp),%rax
jae    11f0 <has_trackID+0xb0>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11b0 <has_trackID+0x70>
mov    -0x28(%rbp),%rdi
add    $0xfffffffffffffff9,%rdi
lea    0xe0a(%rip),%rsi
mov    $0x8,%edx
call   1030 <strn_casecmp@plt>
cmp    $0x0,%rax
je     1224 <has_trackID+0xe4>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11b0 <has_trackID+0x70>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    124c <has_trackID+0x10c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<has_trackID>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbp
call   1040 <strlen@plt>
xor    %ebx,%ebx
cmp    $0x12,%eax
jl     11d3 <has_trackID+0x93>
mov    %eax,%eax
lea    (%rax,%rbp,1),%rdi
add    $0xfffffffffffffff8,%rdi
lea    0xe96(%rip),%rsi
mov    $0x8,%edx
call   1030 <strn_casecmp@plt>
test   %rax,%rax
jne    11d3 <has_trackID+0x93>
test   %rbp,%rbp
je     11d3 <has_trackID+0x93>
lea    0xe84(%rip),%r15
mov    %rbp,%rbx
jmp    1194 <has_trackID+0x54>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x3d,%esi
call   1050 <strchr@plt>
mov    %rax,%rbx
lea    -0x7(%rax),%rdi
cmp    %rbp,%rdi
jb     1190 <has_trackID+0x50>
mov    %r15,%rsi
mov    $0x8,%edx
call   1030 <strn_casecmp@plt>
test   %rax,%rax
jne    1190 <has_trackID+0x50>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1060 <atoi@plt>
mov    %eax,(%r14)
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"RTSP/1.0\00"
@.str.1 = [9 x i8] c"trackid=\00"
define i32 @has_trackID(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 18
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %51
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = getelementptr inbounds i8, i8* %17, i64 -8
%19 = call i64 @strn_casecmp(i8* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %13
store i32 0, i32* %3
br label %51
22: ; preds = %13
%23 = load i8*, i8** %4
store i8* %23, i8** %7
br label %24
24: ; preds = %42, %34, %22
%25 = load i8*, i8** %7
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %50
27: ; preds = %24
%28 = load i8*, i8** %7
%29 = call i8* @strchr(i8* %28, i8 signext 61)
store i8* %29, i8** %7
%30 = load i8*, i8** %7
%31 = getelementptr inbounds i8, i8* %30, i64 -7
%32 = load i8*, i8** %4
%33 = icmp ult i8* %31, %32
br i1 %33, label %34, label %37
34: ; preds = %27
%35 = load i8*, i8** %7
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %7
br label %24
37: ; preds = %27
%38 = load i8*, i8** %7
%39 = getelementptr inbounds i8, i8* %38, i64 -7
%40 = call i64 @strn_casecmp(i8* %39, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = load i8*, i8** %7
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %7
br label %24
45: ; preds = %37
%46 = load i8*, i8** %7
%47 = getelementptr inbounds i8, i8* %46, i64 1
%48 = call i32 @atoi(i8* %47)
%49 = load i32*, i32** %5
store i32 %48, i32* %49
store i32 1, i32* %3
br label %51
50: ; preds = %24
store i32 0, i32* %3
br label %51
51: ; preds = %50, %45, %21, %12
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [9 x i8] c"RTSP/1.0\00"
@.str.1 = [9 x i8] c"trackid=\00"
define i32 @has_trackID(i8* %0, i32* nocapture writeonly %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp slt i32 %3, 18
br i1 %4, label %26, label %5
5: ; preds = %2
%6 = zext i32 %3 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = getelementptr inbounds i8, i8* %7, i64 -8
%9 = tail call i64 @strn_casecmp(i8* %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%10 = icmp ne i64 %9, 0
%11 = icmp eq i8* %0, null
%12 = or i1 %10, %11
br i1 %12, label %26, label %13
13: ; preds = %5, %18
%14 = phi i8* [ %19, %18 ], [ %0, %5 ]
%15 = tail call i8* @strchr(i8* %14, i8 signext 61)
%16 = getelementptr inbounds i8, i8* %15, i64 -7
%17 = icmp ult i8* %16, %0
br i1 %17, label %18, label %20
18: ; preds = %20, %13
%19 = getelementptr inbounds i8, i8* %15, i64 1
br label %13
20: ; preds = %13
%21 = tail call i64 @strn_casecmp(i8* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %18
23: ; preds = %20
%24 = getelementptr inbounds i8, i8* %15, i64 1
%25 = tail call i32 @atoi(i8* %24)
store i32 %25, i32* %1
br label %26
26: ; preds = %5, %2, %23
%27 = phi i32 [ 1, %23 ], [ 0, %2 ], [ 0, %5 ]
ret i32 %27
}