#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*/ luaL_verror(char *, char);
int /*<<< orphan*/ lua_error(char *);
char *strchr(char *, char);
char *luaI_classend(char *p) {
  switch (*p++) {
  case '%':
    if (*p == '\0')
      luaL_verror("incorrect pattern (ends with `%c')", '%');
    return p + 1;
  case '[':
    if (*p == '^')
      p++;
    if (*p == ']')
      p++;
    p = strchr(p, ']');
    if (!p)
      lua_error("incorrect pattern (missing `]')");
    return p + 1;
  default:
    return p;
  }
}


x86 assembly (clang, -O0):
<luaI_classend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
sub    $0x25,%eax
je     1170 <luaI_classend+0x40>
jmp    115f <luaI_classend+0x2f>
mov    -0x14(%rbp),%eax
sub    $0x5b,%eax
je     11a2 <luaI_classend+0x72>
jmp    1214 <luaI_classend+0xe4>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1191 <luaI_classend+0x61>
lea    0xe79(%rip),%rdi
mov    $0x25,%esi
call   1040 <luaL_verror@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    121c <luaI_classend+0xec>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5e,%eax
jne    11be <luaI_classend+0x8e>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5d,%eax
jne    11da <luaI_classend+0xaa>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x5d,%esi
call   1030 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1203 <luaI_classend+0xd3>
lea    0xe25(%rip),%rdi
call   1050 <lua_error@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    121c <luaI_classend+0xec>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<luaI_classend>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x1(%rdi),%r14
movsbl (%rdi),%eax
cmp    $0x5b,%eax
je     1168 <luaI_classend+0x38>
cmp    $0x25,%eax
jne    11a9 <luaI_classend+0x79>
cmpb   $0x0,(%r14)
jne    115f <luaI_classend+0x2f>
lea    0xeab(%rip),%rdi
mov    $0x25,%esi
call   1040 <luaL_verror@plt>
add    $0x2,%rbx
mov    %rbx,%r14
jmp    11a9 <luaI_classend+0x79>
lea    0x2(%rbx),%rax
xor    %ecx,%ecx
cmpb   $0x5e,0x1(%rbx)
sete   %cl
cmove  %rax,%r14
xor    %edi,%edi
cmpb   $0x5d,0x1(%rcx,%rbx,1)
sete   %dil
add    %r14,%rdi
mov    $0x5d,%esi
call   1030 <strchr@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11a5 <luaI_classend+0x75>
lea    0xe83(%rip),%rdi
call   1050 <lua_error@plt>
add    $0x1,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [35 x i8] c"incorrect pattern (ends with `%c')\00"
@.str.1 = [32 x i8] c"incorrect pattern (missing `]')\00"
define i8* @luaI_classend(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = getelementptr inbounds i8, i8* %4, i32 1
store i8* %5, i8** %3
%6 = load i8, i8* %4
%7 = sext i8 %6 to i32
switch i32 %7, label %44 [
i32 37, label %8
i32 91, label %18
]
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 @luaL_verror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8 signext 37)
br label %15
15: ; preds = %13, %8
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8* %17, i8** %2
br label %46
18: ; preds = %1
%19 = load i8*, i8** %3
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 94
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %3
br label %26
26: ; preds = %23, %18
%27 = load i8*, i8** %3
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 93
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %3
br label %34
34: ; preds = %31, %26
%35 = load i8*, i8** %3
%36 = call i8* @strchr(i8* %35, i8 signext 93)
store i8* %36, i8** %3
%37 = load i8*, i8** %3
%38 = icmp ne i8* %37, null
br i1 %38, label %41, label %39
39: ; preds = %34
%40 = call i32 @lua_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %41
41: ; preds = %39, %34
%42 = load i8*, i8** %3
%43 = getelementptr inbounds i8, i8* %42, i64 1
store i8* %43, i8** %2
br label %46
44: ; preds = %1
%45 = load i8*, i8** %3
store i8* %45, i8** %2
br label %46
46: ; preds = %44, %41, %15
%47 = load i8*, i8** %2
ret i8* %47
}

LLVM IR (-O2):
@.str = [35 x i8] c"incorrect pattern (ends with `%c')\00"
@.str.1 = [32 x i8] c"incorrect pattern (missing `]')\00"
define i8* @luaI_classend(i8* %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = load i8, i8* %0
%4 = sext i8 %3 to i32
switch i32 %4, label %27 [
i32 37, label %5
i32 91, label %12
]
5: ; preds = %1
%6 = load i8, i8* %2
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @luaL_verror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8 signext 37)
br label %10
10: ; preds = %8, %5
%11 = getelementptr inbounds i8, i8* %0, i64 2
br label %27
12: ; preds = %1
%13 = load i8, i8* %2
%14 = icmp eq i8 %13, 94
%15 = getelementptr inbounds i8, i8* %0, i64 2
%16 = select i1 %14, i8* %15, i8* %2
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 93
%19 = zext i1 %18 to i64
%20 = getelementptr i8, i8* %16, i64 %19
%21 = tail call i8* @strchr(i8* %20, i8 signext 93)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %25
23: ; preds = %12
%24 = tail call i32 @lua_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %12
%26 = getelementptr inbounds i8, i8* %21, i64 1
br label %27
27: ; preds = %1, %25, %10
%28 = phi i8* [ %26, %25 ], [ %11, %10 ], [ %2, %1 ]
ret i8* %28
}