#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 isValidDNACharacter(char);
int strlen(char *);
int getStates(char *word, char *states, int start, int *end) {
  int len = strlen(word);
  int i, j = start, sep = 1;
  for (i = 0; i < len; ++i) {
    if (word[i] == ',') {
      sep = 1;
      ++j;
    } else if (sep == 1 && isValidDNACharacter(word[i]) == 1) {
      sep = 0;
      states[j] = word[i];
    } else
      return 0;
  }
  *end = j + 1;
  return 1;
}


x86 assembly (clang, -O0):
<getStates>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
movl   $0x1,-0x38(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    11f7 <getStates+0xd7>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
jne    118d <getStates+0x6d>
movl   $0x1,-0x38(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11e4 <getStates+0xc4>
cmpl   $0x1,-0x38(%rbp)
jne    11d3 <getStates+0xb3>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isValidDNACharacter@plt>
cmp    $0x1,%eax
jne    11d3 <getStates+0xb3>
movl   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11df <getStates+0xbf>
movl   $0x0,-0x4(%rbp)
jmp    120a <getStates+0xea>
jmp    11e4 <getStates+0xc4>
jmp    11e9 <getStates+0xc9>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1157 <getStates+0x37>
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getStates>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbp
mov    %edx,%r12d
mov    %rsi,%r15
mov    %rdi,%rbx
call   1040 <strlen@plt>
test   %eax,%eax
mov    %rbp,(%rsp)
jle    119e <getStates+0x7e>
mov    %eax,%r13d
mov    $0x1,%eax
xor    %r14d,%r14d
xor    %ebp,%ebp
jmp    1172 <getStates+0x52>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r12d
mov    $0x1,%eax
add    $0x1,%r14
cmp    %r14,%r13
je     119e <getStates+0x7e>
movzbl (%rbx,%r14,1),%ecx
cmp    $0x2c,%cl
je     1160 <getStates+0x40>
cmp    $0x1,%eax
jne    11ae <getStates+0x8e>
movsbl %cl,%edi
call   1030 <isValidDNACharacter@plt>
cmp    $0x1,%eax
jne    11ae <getStates+0x8e>
movzbl (%rbx,%r14,1),%eax
movslq %r12d,%rcx
mov    %al,(%r15,%rcx,1)
xor    %eax,%eax
jmp    1169 <getStates+0x49>
add    $0x1,%r12d
mov    (%rsp),%rax
mov    %r12d,(%rax)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @getStates(i8* %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%14 = load i8*, i8** %6
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %10
%16 = load i32, i32* %8
store i32 %16, i32* %12
store i32 1, i32* %13
store i32 0, i32* %11
br label %17
17: ; preds = %56, %4
%18 = load i32, i32* %11
%19 = load i32, i32* %10
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %59
21: ; preds = %17
%22 = load i8*, i8** %6
%23 = load i32, i32* %11
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 44
br i1 %28, label %29, label %32
29: ; preds = %21
store i32 1, i32* %13
%30 = load i32, i32* %12
%31 = add nsw i32 %30, 1
store i32 %31, i32* %12
br label %55
32: ; preds = %21
%33 = load i32, i32* %13
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %53
35: ; preds = %32
%36 = load i8*, i8** %6
%37 = load i32, i32* %11
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = call i32 @isValidDNACharacter(i8 signext %40)
%42 = icmp eq i32 %41, 1
br i1 %42, label %43, label %53
43: ; preds = %35
store i32 0, i32* %13
%44 = load i8*, i8** %6
%45 = load i32, i32* %11
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = load i8*, i8** %7
%50 = load i32, i32* %12
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 %48, i8* %52
br label %54
53: ; preds = %35, %32
store i32 0, i32* %5
br label %63
54: ; preds = %43
br label %55
55: ; preds = %54, %29
br label %56
56: ; preds = %55
%57 = load i32, i32* %11
%58 = add nsw i32 %57, 1
store i32 %58, i32* %11
br label %17
59: ; preds = %17
%60 = load i32, i32* %12
%61 = add nsw i32 %60, 1
%62 = load i32*, i32** %9
store i32 %61, i32* %62
store i32 1, i32* %5
br label %63
63: ; preds = %59, %53
%64 = load i32, i32* %5
ret i32 %64
}

LLVM IR (-O2):
define i32 @getStates(i8* %0, i8* nocapture writeonly %1, i32 %2, i32* nocapture writeonly %3) {
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %32
7: ; preds = %4
%8 = zext i32 %5 to i64
br label %9
9: ; preds = %7, %27
%10 = phi i64 [ 0, %7 ], [ %30, %27 ]
%11 = phi i32 [ 1, %7 ], [ %29, %27 ]
%12 = phi i32 [ %2, %7 ], [ %28, %27 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %10
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 44
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = add nsw i32 %12, 1
br label %27
18: ; preds = %9
%19 = icmp eq i32 %11, 1
br i1 %19, label %20, label %35
20: ; preds = %18
%21 = tail call i32 @isValidDNACharacter(i8 signext %14)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %35
23: ; preds = %20
%24 = load i8, i8* %13
%25 = sext i32 %12 to i64
%26 = getelementptr inbounds i8, i8* %1, i64 %25
store i8 %24, i8* %26
br label %27
27: ; preds = %16, %23
%28 = phi i32 [ %17, %16 ], [ %12, %23 ]
%29 = phi i32 [ 1, %16 ], [ 0, %23 ]
%30 = add nuw nsw i64 %10, 1
%31 = icmp eq i64 %30, %8
br i1 %31, label %32, label %9
32: ; preds = %27, %4
%33 = phi i32 [ %2, %4 ], [ %28, %27 ]
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
br label %35
35: ; preds = %18, %20, %32
%36 = phi i32 [ 1, %32 ], [ 0, %20 ], [ 0, %18 ]
ret i32 %36
}