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


x86 assembly (clang, -O0):
<luaL_item_end>:
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,-0x1c(%rbp)
test   %eax,%eax
je     1180 <luaL_item_end+0x50>
jmp    115e <luaL_item_end+0x2e>
mov    -0x1c(%rbp),%eax
sub    $0x25,%eax
je     1191 <luaL_item_end+0x61>
jmp    116f <luaL_item_end+0x3f>
mov    -0x1c(%rbp),%eax
sub    $0x5b,%eax
je     11c3 <luaL_item_end+0x93>
jmp    11f8 <luaL_item_end+0xc8>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    1200 <luaL_item_end+0xd0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11b2 <luaL_item_end+0x82>
lea    0xe58(%rip),%rdi
mov    $0x25,%esi
call   1040 <luaL_verror@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1200 <luaL_item_end+0xd0>
mov    -0x10(%rbp),%rdi
call   1030 <bracket_end@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e7 <luaL_item_end+0xb7>
lea    0xe41(%rip),%rdi
call   1050 <lua_error@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1200 <luaL_item_end+0xd0>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<luaL_item_end>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movsbl (%rdi),%eax
test   %eax,%eax
je     1167 <luaL_item_end+0x37>
lea    0x1(%rbx),%r14
cmp    $0x5b,%eax
je     116c <luaL_item_end+0x3c>
cmp    $0x25,%eax
jne    118c <luaL_item_end+0x5c>
cmpb   $0x0,(%r14)
jne    1163 <luaL_item_end+0x33>
lea    0xea7(%rip),%rdi
mov    $0x25,%esi
call   1040 <luaL_verror@plt>
add    $0x2,%rbx
mov    %rbx,%r14
jmp    118c <luaL_item_end+0x5c>
mov    %r14,%rdi
call   1030 <bracket_end@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1188 <luaL_item_end+0x58>
lea    0xea0(%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* @luaL_item_end(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = getelementptr inbounds i8, i8* %5, i32 1
store i8* %6, i8** %3
%7 = load i8, i8* %5
%8 = sext i8 %7 to i32
switch i32 %8, label %32 [
i32 0, label %9
i32 37, label %12
i32 91, label %22
]
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 -1
store i8* %11, i8** %2
br label %34
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @luaL_verror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8 signext 37)
br label %19
19: ; preds = %17, %12
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 1
store i8* %21, i8** %2
br label %34
22: ; preds = %1
%23 = load i8*, i8** %3
%24 = call i8* @bracket_end(i8* %23)
store i8* %24, i8** %4
%25 = load i8*, i8** %4
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 @lua_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %22
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 1
store i8* %31, i8** %2
br label %34
32: ; preds = %1
%33 = load i8*, i8** %3
store i8* %33, i8** %2
br label %34
34: ; preds = %32, %29, %19, %9
%35 = load i8*, i8** %2
ret i8* %35
}

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* @luaL_item_end(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 %19 [
i32 0, label %20
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 %20
12: ; preds = %1
%13 = tail call i8* @bracket_end(i8* %2)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @lua_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = getelementptr inbounds i8, i8* %13, i64 1
br label %20
19: ; preds = %1
br label %20
20: ; preds = %1, %19, %17, %10
%21 = phi i8* [ %2, %19 ], [ %18, %17 ], [ %11, %10 ], [ %0, %1 ]
ret i8* %21
}