#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 */
unsigned int atoi(char *);
scalar_t__ isdigit(char const);
const char *parse_index(unsigned *index, const char *s) {
  char s_index[15];
  int s_index_i;
  *index = 0;
  if (*s != '[')
    return NULL;
  s++;
  s_index_i = 0;
  while (isdigit(*s) && s_index_i < 15) {
    s_index[s_index_i++] = *s++;
  }
  s_index[s_index_i] = 0;
  if (*s == ']') {
    *index = atoi(s_index);
    return s + 1;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<parse_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
je     1157 <parse_index+0x37>
movq   $0x0,-0x8(%rbp)
jmp    120c <parse_index+0xec>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x2d(%rbp)
je     1192 <parse_index+0x72>
cmpl   $0xf,-0x2c(%rbp)
setl   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    11a2 <parse_index+0x82>
jmp    11c9 <parse_index+0xa9>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%cl
mov    -0x2c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
cltq
mov    %cl,-0x27(%rbp,%rax,1)
jmp    116a <parse_index+0x4a>
movslq -0x2c(%rbp),%rax
movb   $0x0,-0x27(%rbp,%rax,1)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5d,%eax
jne    1204 <parse_index+0xe4>
lea    -0x27(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    120c <parse_index+0xec>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_index>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x0,(%rdi)
cmpb   $0x5b,(%rsi)
jne    11a9 <parse_index+0x89>
mov    %rsi,%r15
mov    %rdi,%r14
movsbl 0x1(%rsi),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1184 <parse_index+0x64>
xor    %ebx,%ebx
nopl   0x0(%rax)
movzbl 0x1(%r15,%rbx,1),%eax
lea    0x1(%rbx),%r12
mov    %al,0x9(%rsp,%rbx,1)
movsbl 0x2(%r15,%rbx,1),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1177 <parse_index+0x57>
cmp    $0xe,%rbx
mov    %r12,%rbx
jb     1150 <parse_index+0x30>
lea    (%r15,%r12,1),%rax
add    $0x1,%rax
add    %r12,%r15
jmp    118b <parse_index+0x6b>
lea    0x1(%r15),%rax
xor    %r12d,%r12d
movb   $0x0,0x9(%rsp,%r12,1)
cmpb   $0x5d,(%rax)
jne    11a9 <parse_index+0x89>
lea    0x9(%rsp),%rdi
call   1040 <atoi@plt>
mov    %eax,(%r14)
add    $0x2,%r15
jmp    11ac <parse_index+0x8c>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @parse_index(i32* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca [15 x i8]
%7 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
%8 = load i32*, i32** %4
store i32 0, i32* %8
%9 = load i8*, i8** %5
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 91
br i1 %12, label %13, label %14
13: ; preds = %2
store i8* null, i8** %3
br label %50
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %5
store i32 0, i32* %7
br label %17
17: ; preds = %27, %14
%18 = load i8*, i8** %5
%19 = load i8, i8* %18
%20 = call i64 @isdigit(i8 signext %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 15
br label %25
25: ; preds = %22, %17
%26 = phi i1 [ false, %17 ], [ %24, %22 ]
br i1 %26, label %27, label %35
27: ; preds = %25
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %5
%30 = load i8, i8* %28
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 %33
store i8 %30, i8* %34
br label %17
35: ; preds = %25
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 %37
store i8 0, i8* %38
%39 = load i8*, i8** %5
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 93
br i1 %42, label %43, label %49
43: ; preds = %35
%44 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%45 = call i32 @atoi(i8* %44)
%46 = load i32*, i32** %4
store i32 %45, i32* %46
%47 = load i8*, i8** %5
%48 = getelementptr inbounds i8, i8* %47, i64 1
store i8* %48, i8** %3
br label %50
49: ; preds = %35
store i8* null, i8** %3
br label %50
50: ; preds = %49, %43, %13
%51 = load i8*, i8** %3
ret i8* %51
}

LLVM IR (-O2):
define i8* @parse_index(i32* nocapture writeonly %0, i8* %1) {
%3 = alloca [15 x i8]
%4 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
store i32 0, i32* %0
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, 91
br i1 %6, label %7, label %34
7: ; preds = %2
%8 = getelementptr inbounds i8, i8* %1, i64 1
%9 = load i8, i8* %8
%10 = tail call i64 @isdigit(i8 signext %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %24, label %12
12: ; preds = %7, %12
%13 = phi i64 [ %16, %12 ], [ 0, %7 ]
%14 = phi i8* [ %18, %12 ], [ %8, %7 ]
%15 = load i8, i8* %14
%16 = add nuw nsw i64 %13, 1
%17 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 %13
store i8 %15, i8* %17
%18 = getelementptr inbounds i8, i8* %14, i64 1
%19 = load i8, i8* %18
%20 = tail call i64 @isdigit(i8 signext %19)
%21 = icmp ne i64 %20, 0
%22 = icmp ult i64 %13, 14
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %12, label %24
24: ; preds = %12, %7
%25 = phi i8* [ %1, %7 ], [ %14, %12 ]
%26 = phi i64 [ 0, %7 ], [ %16, %12 ]
%27 = phi i8* [ %8, %7 ], [ %18, %12 ]
%28 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 %26
store i8 0, i8* %28
%29 = load i8, i8* %27
%30 = icmp eq i8 %29, 93
br i1 %30, label %31, label %34
31: ; preds = %24
%32 = call i32 @atoi(i8* %4)
store i32 %32, i32* %0
%33 = getelementptr inbounds i8, i8* %25, i64 2
br label %34
34: ; preds = %24, %2, %31
%35 = phi i8* [ %33, %31 ], [ null, %2 ], [ null, %24 ]
ret i8* %35
}