#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 */
scalar_t__ is_identifier(char *);
int /*<<< orphan*/ sprintf(char *, char *);
int validate_marker(char **str, char *marker, char *error_msg) {
  int has_lbrack = 0;
  char *s = marker;
  *s = '\0';
  if (**str == '[') {
    has_lbrack = 1;
    (*str)++;
  }
  while (is_identifier(*str)) {
    *s = **str;
    s++;
    (*str)++;
  }
  if (has_lbrack && **str != ']') {
    sprintf(error_msg, "No matching ']' found");
    return 0;
  } else if (s == marker) {
    sprintf(error_msg, "No marker specified");
    return 0;
  }
  if (has_lbrack && **str == ']')
    (*str)++;
  *s = '\0';
  return 1;
}


x86 assembly (clang, -O0):
<validate_marker>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
jne    1172 <validate_marker+0x52>
movl   $0x1,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1177 <validate_marker+0x57>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <is_identifier@plt>
cmp    $0x0,%rax
je     11bb <validate_marker+0x9b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1177 <validate_marker+0x57>
cmpl   $0x0,-0x24(%rbp)
je     11f4 <validate_marker+0xd4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x5d,%eax
je     11f4 <validate_marker+0xd4>
mov    -0x20(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1040 <sprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    125c <validate_marker+0x13c>
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    121e <validate_marker+0xfe>
mov    -0x20(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   1040 <sprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    125c <validate_marker+0x13c>
jmp    1223 <validate_marker+0x103>
cmpl   $0x0,-0x24(%rbp)
je     124e <validate_marker+0x12e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x5d,%eax
jne    124e <validate_marker+0x12e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_marker>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
movb   $0x0,(%rsi)
mov    (%rdi),%rdi
mov    (%rdi),%bpl
cmp    $0x5b,%bpl
jne    1138 <validate_marker+0x28>
add    $0x1,%rdi
mov    %rdi,(%r12)
call   1030 <is_identifier@plt>
mov    %r15,%rbx
test   %rax,%rax
je     1173 <validate_marker+0x63>
mov    %r15,%rbx
nopl   0x0(%rax,%rax,1)
mov    (%r12),%rax
movzbl (%rax),%eax
mov    %al,(%rbx)
add    $0x1,%rbx
mov    (%r12),%rdi
add    $0x1,%rdi
mov    %rdi,(%r12)
call   1030 <is_identifier@plt>
test   %rax,%rax
jne    1150 <validate_marker+0x40>
cmp    $0x5b,%bpl
jne    1191 <validate_marker+0x81>
mov    (%r12),%rax
cmpb   $0x5d,(%rax)
jne    11b5 <validate_marker+0xa5>
cmp    %r15,%rbx
je     11a0 <validate_marker+0x90>
add    $0x1,%rax
mov    %rax,(%r12)
jmp    1196 <validate_marker+0x86>
cmp    %r15,%rbx
je     11a0 <validate_marker+0x90>
movb   $0x0,(%rbx)
mov    $0x1,%eax
jmp    11d0 <validate_marker+0xc0>
movups 0xe6f(%rip),%xmm0
movups %xmm0,(%r14)
movl   $0x646569,0x10(%r14)
jmp    11ce <validate_marker+0xbe>
movups 0xe44(%rip),%xmm0
movups %xmm0,(%r14)
movabs $0x646e756f662027,%rax
mov    %rax,0xe(%r14)
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"No matching ']' found\00"
@.str.1 = [20 x i8] c"No marker specified\00"
define i32 @validate_marker(i8** %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 0, i32* %8
%10 = load i8*, i8** %6
store i8* %10, i8** %9
%11 = load i8*, i8** %9
store i8 0, i8* %11
%12 = load i8**, i8*** %5
%13 = load i8*, i8** %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 91
br i1 %16, label %17, label %21
17: ; preds = %3
store i32 1, i32* %8
%18 = load i8**, i8*** %5
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %18
br label %21
21: ; preds = %17, %3
br label %22
22: ; preds = %27, %21
%23 = load i8**, i8*** %5
%24 = load i8*, i8** %23
%25 = call i64 @is_identifier(i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %37
27: ; preds = %22
%28 = load i8**, i8*** %5
%29 = load i8*, i8** %28
%30 = load i8, i8* %29
%31 = load i8*, i8** %9
store i8 %30, i8* %31
%32 = load i8*, i8** %9
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %9
%34 = load i8**, i8*** %5
%35 = load i8*, i8** %34
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %34
br label %22
37: ; preds = %22
%38 = load i32, i32* %8
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %49
40: ; preds = %37
%41 = load i8**, i8*** %5
%42 = load i8*, i8** %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 93
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = load i8*, i8** %7
%48 = call i32 @sprintf(i8* %47, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %72
49: ; preds = %40, %37
%50 = load i8*, i8** %9
%51 = load i8*, i8** %6
%52 = icmp eq i8* %50, %51
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i8*, i8** %7
%55 = call i32 @sprintf(i8* %54, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %72
56: ; preds = %49
br label %57
57: ; preds = %56
%58 = load i32, i32* %8
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %70
60: ; preds = %57
%61 = load i8**, i8*** %5
%62 = load i8*, i8** %61
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, 93
br i1 %65, label %66, label %70
66: ; preds = %60
%67 = load i8**, i8*** %5
%68 = load i8*, i8** %67
%69 = getelementptr inbounds i8, i8* %68, i32 1
store i8* %69, i8** %67
br label %70
70: ; preds = %66, %60, %57
%71 = load i8*, i8** %9
store i8 0, i8* %71
store i32 1, i32* %4
br label %72
72: ; preds = %70, %53, %46
%73 = load i32, i32* %4
ret i32 %73
}

LLVM IR (-O2):
@.str = [22 x i8] c"No matching ']' found\00"
@.str.1 = [20 x i8] c"No marker specified\00"
define i32 @validate_marker(i8** nocapture %0, i8* writeonly %1, i8* nocapture writeonly %2) {
store i8 0, i8* %1
%4 = load i8*, i8** %0
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 91
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = getelementptr inbounds i8, i8* %4, i64 1
store i8* %8, i8** %0
br label %9
9: ; preds = %7, %3
%10 = phi i8* [ %8, %7 ], [ %4, %3 ]
%11 = tail call i64 @is_identifier(i8* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %9, %13
%14 = phi i8* [ %17, %13 ], [ %1, %9 ]
%15 = load i8*, i8** %0
%16 = load i8, i8* %15
store i8 %16, i8* %14
%17 = getelementptr inbounds i8, i8* %14, i64 1
%18 = load i8*, i8** %0
%19 = getelementptr inbounds i8, i8* %18, i64 1
store i8* %19, i8** %0
%20 = tail call i64 @is_identifier(i8* %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %13
22: ; preds = %13, %9
%23 = phi i8* [ %1, %9 ], [ %17, %13 ]
br i1 %6, label %24, label %31
24: ; preds = %22
%25 = load i8*, i8** %0
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 93
br i1 %27, label %29, label %28
28: ; preds = %24
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(22) %2, i8* align 1 dereferenceable(22) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 22, i1 false)
br label %37
29: ; preds = %24
%30 = icmp eq i8* %23, %1
br i1 %30, label %33, label %34
31: ; preds = %22
%32 = icmp eq i8* %23, %1
br i1 %32, label %33, label %36
33: ; preds = %31, %29
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(20) %2, i8* align 1 dereferenceable(20) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i64 20, i1 false)
br label %37
34: ; preds = %29
%35 = getelementptr inbounds i8, i8* %25, i64 1
store i8* %35, i8** %0
br label %36
36: ; preds = %31, %34
store i8 0, i8* %23
br label %37
37: ; preds = %36, %33, %28
%38 = phi i32 [ 0, %28 ], [ 0, %33 ], [ 1, %36 ]
ret i32 %38
}