#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);
long strtol(char *, char **, int /*<<< orphan*/);
size_t parse_dimension(char *dim, char **endptr) {
  long result;
  if (*dim == ']') {
    *endptr = dim;
    return 0;
  }
  result = strtol(dim, endptr, 0);
  if (**endptr == ']') {
    return (size_t)result;
  }
  *endptr = strchr(dim, ']');
  return 0;
}


x86 assembly (clang, -O0):
<parse_dimension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5d,%eax
jne    1158 <parse_dimension+0x38>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11ab <parse_dimension+0x8b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x5d,%eax
jne    118b <parse_dimension+0x6b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ab <parse_dimension+0x8b>
mov    -0x10(%rbp),%rdi
mov    $0x5d,%esi
call   1030 <strchr@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_dimension>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
cmpb   $0x5d,(%rdi)
je     1154 <parse_dimension+0x34>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    (%r14),%rcx
cmpb   $0x5d,(%rcx)
je     1159 <parse_dimension+0x39>
mov    %rbx,%rdi
mov    $0x5d,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
mov    %rbx,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @parse_dimension(i8* %0, i8** %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i64
store i8* %0, i8** %4
store i8** %1, i8*** %5
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 93
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i8**, i8*** %5
store i8* %12, i8** %13
store i64 0, i64* %3
br label %29
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = load i8**, i8*** %5
%17 = call i64 @strtol(i8* %15, i8** %16, i32 0)
store i64 %17, i64* %6
%18 = load i8**, i8*** %5
%19 = load i8*, i8** %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 93
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = load i64, i64* %6
store i64 %24, i64* %3
br label %29
25: ; preds = %14
%26 = load i8*, i8** %4
%27 = call i8* @strchr(i8* %26, i8 signext 93)
%28 = load i8**, i8*** %5
store i8* %27, i8** %28
store i64 0, i64* %3
br label %29
29: ; preds = %25, %23, %11
%30 = load i64, i64* %3
ret i64 %30
}

LLVM IR (-O2):
define i64 @parse_dimension(i8* %0, i8** nocapture %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 93
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = tail call i64 @strtol(i8* %0, i8** %1, i32 0)
%7 = load i8*, i8** %1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 93
br i1 %9, label %14, label %10
10: ; preds = %5
%11 = tail call i8* @strchr(i8* %0, i8 signext 93)
br label %12
12: ; preds = %2, %10
%13 = phi i8* [ %11, %10 ], [ %0, %2 ]
store i8* %13, i8** %1
br label %14
14: ; preds = %12, %5
%15 = phi i64 [ %6, %5 ], [ 0, %12 ]
ret i64 %15
}