#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 *strchr(char *, char);
int is_config_header(char *buf) {
  char *brace_l;
  char *brace_r;
  char *sharp;
  brace_l = strchr(buf, '[');
  brace_r = strchr(buf, ']');
  sharp = strchr(buf, '#');
  if (brace_l && brace_r && brace_r > brace_l && (sharp > brace_r || !sharp)) {
    *brace_r = '\0';
    return (brace_l - buf + 1);
  }
  return (-1);
}


x86 assembly (clang, -O0):
<is_config_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x5b,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x5d,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x23,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ad <is_config_header+0x9d>
cmpq   $0x0,-0x20(%rbp)
je     11ad <is_config_header+0x9d>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    11ad <is_config_header+0x9d>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
ja     118f <is_config_header+0x7f>
cmpq   $0x0,-0x28(%rbp)
jne    11ad <is_config_header+0x9d>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,-0x4(%rbp)
jmp    11b4 <is_config_header+0xa4>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_config_header>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    $0x5b,%esi
call   1030 <strchr@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    $0x5d,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x23,%esi
call   1030 <strchr@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %r14,%r14
je     1170 <is_config_header+0x60>
test   %rbx,%rbx
je     1170 <is_config_header+0x60>
cmp    %r14,%rbx
jbe    1170 <is_config_header+0x60>
cmp    %rbx,%rcx
ja     1163 <is_config_header+0x53>
test   %rcx,%rcx
jne    1170 <is_config_header+0x60>
movb   $0x0,(%rbx)
sub    %r15d,%r14d
add    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @is_config_header(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @strchr(i8* %7, i8 signext 91)
store i8* %8, i8** %4
%9 = load i8*, i8** %3
%10 = call i8* @strchr(i8* %9, i8 signext 93)
store i8* %10, i8** %5
%11 = load i8*, i8** %3
%12 = call i8* @strchr(i8* %11, i8 signext 35)
store i8* %12, i8** %6
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %38
15: ; preds = %1
%16 = load i8*, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %38
18: ; preds = %15
%19 = load i8*, i8** %5
%20 = load i8*, i8** %4
%21 = icmp ugt i8* %19, %20
br i1 %21, label %22, label %38
22: ; preds = %18
%23 = load i8*, i8** %6
%24 = load i8*, i8** %5
%25 = icmp ugt i8* %23, %24
br i1 %25, label %29, label %26
26: ; preds = %22
%27 = load i8*, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %38, label %29
29: ; preds = %26, %22
%30 = load i8*, i8** %5
store i8 0, i8* %30
%31 = load i8*, i8** %4
%32 = load i8*, i8** %3
%33 = ptrtoint i8* %31 to i64
%34 = ptrtoint i8* %32 to i64
%35 = sub i64 %33, %34
%36 = add nsw i64 %35, 1
%37 = trunc i64 %36 to i32
store i32 %37, i32* %2
br label %39
38: ; preds = %26, %18, %15, %1
store i32 -1, i32* %2
br label %39
39: ; preds = %38, %29
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
define i32 @is_config_header(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 91)
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 93)
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 35)
%5 = icmp ne i8* %2, null
%6 = icmp ne i8* %3, null
%7 = select i1 %5, i1 %6, i1 false
%8 = icmp ugt i8* %3, %2
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %10, label %20
10: ; preds = %1
%11 = icmp ule i8* %4, %3
%12 = icmp ne i8* %4, null
%13 = and i1 %11, %12
br i1 %13, label %20, label %14
14: ; preds = %10
store i8 0, i8* %3
%15 = ptrtoint i8* %2 to i64
%16 = ptrtoint i8* %0 to i64
%17 = sub i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = add i32 %18, 1
br label %20
20: ; preds = %1, %10, %14
%21 = phi i32 [ %19, %14 ], [ -1, %10 ], [ -1, %1 ]
ret i32 %21
}