#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*/ free(char **);
scalar_t__ realloc(char **, int);
int /*<<< orphan*/ strcmp(char *, char *);
unsigned int statetoint(char *name) {
  static char **states = NULL;
  static int nbstates = 0;
  static int nballoc = 0;
  unsigned int i;
  if (name == NULL) {
    if (states)
      free(states);
    i = nbstates;
    nbstates = 0;
    nballoc = 0;
    return i;
  }
  for (i = 0; i < nbstates; i++)
    if (!strcmp(states[i], name))
      return i + 1;
  if (nbstates + 1 >= nballoc)
    states =
        (char **)realloc(states, sizeof(char *) * (nballoc = 2 * nballoc + 1));
  states[nbstates++] = name;
  return nbstates;
}


x86 assembly (clang, -O0):
<statetoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1189 <statetoint+0x59>
cmpq   $0x0,0x2ef1(%rip)
je     1161 <statetoint+0x31>
mov    0x2ee4(%rip),%rdi
call   1030 <free@plt>
mov    0x2ee1(%rip),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,0x2ed4(%rip)
movl   $0x0,0x2ece(%rip)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    124e <statetoint+0x11e>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    0x2eaf(%rip),%eax
jae    11e0 <statetoint+0xb0>
mov    0x2e9a(%rip),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11cd <statetoint+0x9d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    124e <statetoint+0x11e>
jmp    11d2 <statetoint+0xa2>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1190 <statetoint+0x60>
mov    0x2e62(%rip),%eax
add    $0x1,%eax
cmp    0x2e5d(%rip),%eax
jl     1222 <statetoint+0xf2>
mov    0x2e44(%rip),%rdi
mov    0x2e4a(%rip),%eax
shl    $0x1,%eax
add    $0x1,%eax
mov    %eax,0x2e3e(%rip)
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,0x2e1e(%rip)
mov    -0x10(%rbp),%rdx
mov    0x2e13(%rip),%rax
mov    0x2e15(%rip),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,0x2e0a(%rip)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    0x2dfd(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<statetoint>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11d1 <statetoint+0xa1>
mov    %rdi,%r14
mov    0x2efd(%rip),%r15d
test   %r15,%r15
je     117d <statetoint+0x4d>
mov    0x2ee9(%rip),%r12
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r12,%rbx,8),%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11fe <statetoint+0xce>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <statetoint+0x30>
lea    0x1(%r15),%ebx
mov    0x2ec5(%rip),%ecx
mov    0x2eb2(%rip),%rax
cmp    %ecx,%ebx
jl     11c2 <statetoint+0x92>
mov    %ecx,%edx
add    %edx,%edx
add    %ecx,%ecx
add    $0x1,%ecx
mov    %ecx,0x2eab(%rip)
lea    0x8(,%rdx,8),%esi
mov    %rax,%rdi
call   1050 <realloc@plt>
mov    %rax,0x2e89(%rip)
mov    0x2e8a(%rip),%r15d
lea    0x1(%r15),%ebx
mov    %ebx,0x2e80(%rip)
movslq %r15d,%rcx
mov    %r14,(%rax,%rcx,8)
jmp    1201 <statetoint+0xd1>
mov    0x2e68(%rip),%rdi
test   %rdi,%rdi
je     11e2 <statetoint+0xb2>
call   1030 <free@plt>
mov    0x2e60(%rip),%ebx
movl   $0x0,0x2e56(%rip)
movl   $0x0,0x2e50(%rip)
jmp    1201 <statetoint+0xd1>
add    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@statetoint.states = internal global i8** null
@statetoint.nbstates = internal global i32 0
@statetoint.nballoc = internal global i32 0
define i32 @statetoint(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %16
7: ; preds = %1
%8 = load i8**, i8*** @statetoint.states
%9 = icmp ne i8** %8, null
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i8**, i8*** @statetoint.states
%12 = call i32 @free(i8** %11)
br label %13
13: ; preds = %10, %7
%14 = load i32, i32* @statetoint.nbstates
store i32 %14, i32* %4
store i32 0, i32* @statetoint.nbstates
store i32 0, i32* @statetoint.nballoc
%15 = load i32, i32* %4
store i32 %15, i32* %2
br label %60
16: ; preds = %1
store i32 0, i32* %4
br label %17
17: ; preds = %34, %16
%18 = load i32, i32* %4
%19 = load i32, i32* @statetoint.nbstates
%20 = icmp ult i32 %18, %19
br i1 %20, label %21, label %37
21: ; preds = %17
%22 = load i8**, i8*** @statetoint.states
%23 = load i32, i32* %4
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = load i8*, i8** %3
%28 = call i32 @strcmp(i8* %26, i8* %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %21
%31 = load i32, i32* %4
%32 = add i32 %31, 1
store i32 %32, i32* %2
br label %60
33: ; preds = %21
br label %34
34: ; preds = %33
%35 = load i32, i32* %4
%36 = add i32 %35, 1
store i32 %36, i32* %4
br label %17
37: ; preds = %17
%38 = load i32, i32* @statetoint.nbstates
%39 = add nsw i32 %38, 1
%40 = load i32, i32* @statetoint.nballoc
%41 = icmp sge i32 %39, %40
br i1 %41, label %42, label %52
42: ; preds = %37
%43 = load i8**, i8*** @statetoint.states
%44 = load i32, i32* @statetoint.nballoc
%45 = mul nsw i32 2, %44
%46 = add nsw i32 %45, 1
store i32 %46, i32* @statetoint.nballoc
%47 = sext i32 %46 to i64
%48 = mul i64 8, %47
%49 = trunc i64 %48 to i32
%50 = call i64 @realloc(i8** %43, i32 %49)
%51 = inttoptr i64 %50 to i8**
store i8** %51, i8*** @statetoint.states
br label %52
52: ; preds = %42, %37
%53 = load i8*, i8** %3
%54 = load i8**, i8*** @statetoint.states
%55 = load i32, i32* @statetoint.nbstates
%56 = add nsw i32 %55, 1
store i32 %56, i32* @statetoint.nbstates
%57 = sext i32 %55 to i64
%58 = getelementptr inbounds i8*, i8** %54, i64 %57
store i8* %53, i8** %58
%59 = load i32, i32* @statetoint.nbstates
store i32 %59, i32* %2
br label %60
60: ; preds = %52, %30, %13
%61 = load i32, i32* %2
ret i32 %61
}

LLVM IR (-O2):
@statetoint.states = internal unnamed_addr global i8** null
@statetoint.nbstates = internal unnamed_addr global i32 0
@statetoint.nballoc = internal unnamed_addr global i32 0
define i32 @statetoint(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %9, label %3
3: ; preds = %1
%4 = load i32, i32* @statetoint.nbstates
%5 = icmp eq i32 %4, 0
br i1 %5, label %28, label %6
6: ; preds = %3
%7 = load i8**, i8*** @statetoint.states
%8 = zext i32 %4 to i64
br label %16
9: ; preds = %1
%10 = load i8**, i8*** @statetoint.states
%11 = icmp eq i8** %10, null
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @free(i8** %10)
br label %14
14: ; preds = %12, %9
%15 = load i32, i32* @statetoint.nbstates
store i32 0, i32* @statetoint.nbstates
store i32 0, i32* @statetoint.nballoc
br label %47
16: ; preds = %6, %25
%17 = phi i64 [ 0, %6 ], [ %26, %25 ]
%18 = getelementptr inbounds i8*, i8** %7, i64 %17
%19 = load i8*, i8** %18
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %19, i8* %0)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = trunc i64 %17 to i32
%24 = add nuw i32 %23, 1
br label %47
25: ; preds = %16
%26 = add nuw nsw i64 %17, 1
%27 = icmp eq i64 %26, %8
br i1 %27, label %28, label %16
28: ; preds = %25, %3
%29 = add nsw i32 %4, 1
%30 = load i32, i32* @statetoint.nballoc
%31 = icmp slt i32 %29, %30
%32 = load i8**, i8*** @statetoint.states
br i1 %31, label %41, label %33
33: ; preds = %28
%34 = shl nsw i32 %30, 1
%35 = or i32 %34, 1
store i32 %35, i32* @statetoint.nballoc
%36 = shl i32 %35, 3
%37 = tail call i64 @realloc(i8** %32, i32 %36)
%38 = inttoptr i64 %37 to i8**
store i8** %38, i8*** @statetoint.states
%39 = load i32, i32* @statetoint.nbstates
%40 = add nsw i32 %39, 1
br label %41
41: ; preds = %28, %33
%42 = phi i32 [ %40, %33 ], [ %29, %28 ]
%43 = phi i32 [ %39, %33 ], [ %4, %28 ]
%44 = phi i8** [ %38, %33 ], [ %32, %28 ]
store i32 %42, i32* @statetoint.nbstates
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds i8*, i8** %44, i64 %45
store i8* %0, i8** %46
br label %47
47: ; preds = %41, %22, %14
%48 = phi i32 [ %15, %14 ], [ %24, %22 ], [ %42, %41 ]
ret i32 %48
}