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


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)
cmp    $0x0,%rax
je     1174 <HTS_get_state_num+0x44>
mov    -0x10(%rbp),%rdi
mov    $0x5d,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1180 <HTS_get_state_num+0x50>
movl   $0x0,-0x4(%rbp)
jmp    119f <HTS_get_state_num+0x6f>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HTS_get_state_num>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x5b,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1171 <HTS_get_state_num+0x41>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x5d,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1171 <HTS_get_state_num+0x41>
movb   $0x0,(%rax)
add    $0x1,%rbx
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <atoi@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @HTS_get_state_num(i8* %0) {
%2 = alloca i32
%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 = icmp eq i8* %7, null
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i8* @strrchr(i8* %10, i8 signext 93)
store i8* %11, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %9, %1
store i32 0, i32* %2
br label %20
14: ; preds = %9
%15 = load i8*, i8** %5
store i8 0, i8* %15
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %2
br label %20
20: ; preds = %14, %13
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
define i32 @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 %10, label %4
4: ; preds = %1
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 93)
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %4
store i8 0, i8* %5
%8 = getelementptr inbounds i8, i8* %2, i64 1
%9 = tail call i32 @atoi(i8* %8)
br label %10
10: ; preds = %1, %4, %7
%11 = phi i32 [ %9, %7 ], [ 0, %4 ], [ 0, %1 ]
ret i32 %11
}