#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*/ atoi(char *);
char *strchr(char const *, char);
size_t HTS_get_state_num(const char *string) {
  char *left, *right;
  left = strchr(string, '[');
  if (left == NULL)
    return 0;
  left++;
  right = strchr(left, ']');
  if (right == NULL)
    return 0;
  return (size_t)atoi(left);
}


x86 assembly (clang, -O0):
<HTS_get_state_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x5b,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1156 <HTS_get_state_num+0x36>
movq   $0x0,-0x8(%rbp)
jmp    119b <HTS_get_state_num+0x7b>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x5d,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118c <HTS_get_state_num+0x6c>
movq   $0x0,-0x8(%rbp)
jmp    119b <HTS_get_state_num+0x7b>
mov    -0x18(%rbp),%rdi
call   1040 <atoi@plt>
cltq
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HTS_get_state_num>:
push   %rbx
mov    $0x5b,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1155 <HTS_get_state_num+0x35>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x5d,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1155 <HTS_get_state_num+0x35>
mov    %rbx,%rdi
call   1040 <atoi@plt>
cltq
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i64 @HTS_get_state_num(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 91)
%3 = icmp eq i8* %2, null
br i1 %3, label %11, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %2, i64 1
%6 = tail call i8* @strchr(i8* %5, i8 signext 93)
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = tail call i32 @atoi(i8* %5)
%10 = sext i32 %9 to i64
br label %11
11: ; preds = %4, %1, %8
%12 = phi i64 [ %10, %8 ], [ 0, %1 ], [ 0, %4 ]
ret i64 %12
}