#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*/ fprintf(int /*<<< orphan*/, char *);
size_t parse_dimension(char *, char **);
int /*<<< orphan*/ stderr;
char *strchr(char const *, char);
int parse_array_decl(const char *decl, size_t *d1, size_t *d2) {
  char *end;
  char *s;
  s = strchr(decl, '[');
  if (s == NULL) {
    fprintf(stderr, "bin2c: failed to parse array declaration\n");
    return -1;
  }
  s++;
  *d1 = parse_dimension(s, &end);
  if (*end != ']') {
    return -1;
  }
  s = end + 1;
  if (*s == '[') {
    s++;
    *d2 = parse_dimension(s, &end);
    if (*end != ']') {
      return -1;
    }
  } else {
    *d2 = 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_array_decl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x5b,%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1182 <parse_array_decl+0x52>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1233 <parse_array_decl+0x103>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <parse_dimension@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5d,%eax
je     11c1 <parse_array_decl+0x91>
movl   $0xffffffff,-0x4(%rbp)
jmp    1233 <parse_array_decl+0x103>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
jne    1221 <parse_array_decl+0xf1>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <parse_dimension@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5d,%eax
je     121c <parse_array_decl+0xec>
movl   $0xffffffff,-0x4(%rbp)
jmp    1233 <parse_array_decl+0x103>
jmp    122c <parse_array_decl+0xfc>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_array_decl>:
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    $0x5b,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1189 <parse_array_decl+0x59>
add    $0x1,%rax
mov    %rsp,%rsi
mov    %rax,%rdi
call   1030 <parse_dimension@plt>
mov    %rax,0x0(%rbp)
mov    (%rsp),%rdi
mov    $0xffffffff,%ebp
cmpb   $0x5d,(%rdi)
jne    11ae <parse_array_decl+0x7e>
cmpb   $0x5b,0x1(%rdi)
jne    11a5 <parse_array_decl+0x75>
add    $0x2,%rdi
mov    %rsp,%rsi
call   1030 <parse_dimension@plt>
mov    %rax,(%rbx)
mov    (%rsp),%rax
cmpb   $0x5d,(%rax)
je     11ac <parse_array_decl+0x7c>
jmp    11ae <parse_array_decl+0x7e>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebp
jmp    11ae <parse_array_decl+0x7e>
movq   $0x0,(%rbx)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [42 x i8] c"bin2c: failed to parse array declaration\0A\00"
define i32 @parse_array_decl(i8* %0, i64* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i64* %1, i64** %6
store i64* %2, i64** %7
%10 = load i8*, i8** %5
%11 = call i8* @strchr(i8* %10, i8 signext 91)
store i8* %11, i8** %9
%12 = load i8*, i8** %9
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %50
17: ; preds = %3
%18 = load i8*, i8** %9
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %9
%20 = load i8*, i8** %9
%21 = call i64 @parse_dimension(i8* %20, i8** %8)
%22 = load i64*, i64** %6
store i64 %21, i64* %22
%23 = load i8*, i8** %8
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 93
br i1 %26, label %27, label %28
27: ; preds = %17
store i32 -1, i32* %4
br label %50
28: ; preds = %17
%29 = load i8*, i8** %8
%30 = getelementptr inbounds i8, i8* %29, i64 1
store i8* %30, i8** %9
%31 = load i8*, i8** %9
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 91
br i1 %34, label %35, label %47
35: ; preds = %28
%36 = load i8*, i8** %9
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %9
%38 = load i8*, i8** %9
%39 = call i64 @parse_dimension(i8* %38, i8** %8)
%40 = load i64*, i64** %7
store i64 %39, i64* %40
%41 = load i8*, i8** %8
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 93
br i1 %44, label %45, label %46
45: ; preds = %35
store i32 -1, i32* %4
br label %50
46: ; preds = %35
br label %49
47: ; preds = %28
%48 = load i64*, i64** %7
store i64 0, i64* %48
br label %49
49: ; preds = %47, %46
store i32 0, i32* %4
br label %50
50: ; preds = %49, %45, %27, %14
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [42 x i8] c"bin2c: failed to parse array declaration\0A\00"
define i32 @parse_array_decl(i8* %0, i64* nocapture writeonly %1, i64* nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 91)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %29
11: ; preds = %3
%12 = getelementptr inbounds i8, i8* %6, i64 1
%13 = call i64 @parse_dimension(i8* %12, i8** %4)
store i64 %13, i64* %1
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 93
br i1 %16, label %17, label %29
17: ; preds = %11
%18 = getelementptr inbounds i8, i8* %14, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 91
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = getelementptr inbounds i8, i8* %14, i64 2
%23 = call i64 @parse_dimension(i8* %22, i8** %4)
store i64 %23, i64* %2
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 93
br i1 %26, label %28, label %29
27: ; preds = %17
store i64 0, i64* %2
br label %28
28: ; preds = %21, %27
br label %29
29: ; preds = %21, %11, %28, %8
%30 = phi i32 [ -1, %8 ], [ 0, %28 ], [ -1, %11 ], [ -1, %21 ]
ret i32 %30
}