#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 findNextChar(char const *, int, char);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *);
int /*<<< orphan*/ stderr;
int strlen(char const *);
scalar_t__ strncmp(char const *, char const *, int);
int checkToken(const char *data, int len, const char *cmpStr) {
  int cmpLen = strlen(cmpStr);
  int next;
  if (*data != '*') {
    fprintf(stderr, "ERROR: not at start of %s (found '%.10s')\n", cmpStr,
            data);
    return -1;
  }
  next = findNextChar(data, len, '\n');
  if (next < cmpLen + 1)
    return -1;
  if (strncmp(data + 1, cmpStr, cmpLen) != 0) {
    fprintf(stderr, "ERROR: '%s' not found (got '%.7s')\n", cmpStr, data + 1);
    return -1;
  }
  return next + 1;
}


x86 assembly (clang, -O0):
<checkToken>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2a,%eax
je     1198 <checkToken+0x58>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe79(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121d <checkToken+0xdd>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0xa,%edx
call   1040 <findNextChar@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11c9 <checkToken+0x89>
movl   $0xffffffff,-0x4(%rbp)
jmp    121d <checkToken+0xdd>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1214 <checkToken+0xd4>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
add    $0x1,%rcx
lea    0xe28(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121d <checkToken+0xdd>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkToken>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rdx,%rdi
call   1050 <strlen@plt>
cmpb   $0x2a,(%rbx)
jne    11b4 <checkToken+0x74>
mov    %eax,%r13d
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0xa,%edx
call   1040 <findNextChar@plt>
mov    $0xffffffff,%r15d
cmp    %r13d,%eax
jle    11d5 <checkToken+0x95>
mov    %eax,%r12d
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r13d,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11e7 <checkToken+0xa7>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1060 <fprintf@plt>
jmp    11d5 <checkToken+0x95>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1060 <fprintf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x1,%r12d
mov    %r12d,%r15d
jmp    11d5 <checkToken+0x95>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"ERROR: not at start of %s (found '%.10s')\0A\00"
@.str.1 = [36 x i8] c"ERROR: '%s' not found (got '%.7s')\0A\00"
define i32 @checkToken(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%10 = load i8*, i8** %7
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %8
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 42
br i1 %15, label %16, label %21
16: ; preds = %3
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %7
%19 = load i8*, i8** %5
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %19)
store i32 -1, i32* %4
br label %46
21: ; preds = %3
%22 = load i8*, i8** %5
%23 = load i32, i32* %6
%24 = call i32 @findNextChar(i8* %22, i32 %23, i8 signext 10)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
%28 = icmp slt i32 %25, %27
br i1 %28, label %29, label %30
29: ; preds = %21
store i32 -1, i32* %4
br label %46
30: ; preds = %21
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8*, i8** %7
%34 = load i32, i32* %8
%35 = call i64 @strncmp(i8* %32, i8* %33, i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %30
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %7
%40 = load i8*, i8** %5
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %39, i8* %41)
store i32 -1, i32* %4
br label %46
43: ; preds = %30
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %4
br label %46
46: ; preds = %43, %37, %29, %16
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"ERROR: not at start of %s (found '%.10s')\0A\00"
@.str.1 = [36 x i8] c"ERROR: '%s' not found (got '%.7s')\0A\00"
define i32 @checkToken(i8* %0, i32 %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 42
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %0)
br label %22
10: ; preds = %3
%11 = tail call i32 @findNextChar(i8* %0, i32 %1, i8 signext 10)
%12 = icmp sgt i32 %11, %4
br i1 %12, label %13, label %22
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %0, i64 1
%15 = tail call i64 @strncmp(i8* %14, i8* %2, i32 %4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %14)
br label %22
20: ; preds = %13
%21 = add nsw i32 %11, 1
br label %22
22: ; preds = %10, %20, %17, %7
%23 = phi i32 [ -1, %7 ], [ -1, %17 ], [ %21, %20 ], [ -1, %10 ]
ret i32 %23
}