#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*/ strcmp(char *, char *);
int strlen(char *);
int ParseCommaString(char *s) {
  int Len;
  Len = strlen(s);
  if (Len < 3)
    return (0);
  s += Len - 2;
  if (!strcmp(",1", s)) {
    *s = 0;
    return (1);
  }
  if (!strcmp(",2", s)) {
    *s = 0;
    return (2);
  }
  return (0);
}


x86 assembly (clang, -O0):
<ParseCommaString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    114e <ParseCommaString+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    11c1 <ParseCommaString+0xa1>
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe93(%rip),%rdi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    118e <ParseCommaString+0x6e>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11c1 <ParseCommaString+0xa1>
mov    -0x10(%rbp),%rsi
lea    0xe6a(%rip),%rdi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11ba <ParseCommaString+0x9a>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x2,-0x4(%rbp)
jmp    11c1 <ParseCommaString+0xa1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ParseCommaString>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
xor    %ebp,%ebp
cmp    $0x3,%eax
jl     116d <ParseCommaString+0x4d>
add    $0xfffffffe,%eax
add    %rax,%rbx
lea    0xec1(%rip),%rdi
mov    %rbx,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1165 <ParseCommaString+0x45>
lea    0xeb1(%rip),%rdi
mov    %rbx,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    116d <ParseCommaString+0x4d>
mov    $0x2,%ebp
jmp    116a <ParseCommaString+0x4a>
mov    $0x1,%ebp
movb   $0x0,(%rbx)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c",1\00"
@.str.1 = [3 x i8] c",2\00"
define i32 @ParseCommaString(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %28
10: ; preds = %1
%11 = load i32, i32* %4
%12 = sub nsw i32 %11, 2
%13 = load i8*, i8** %3
%14 = sext i32 %12 to i64
%15 = getelementptr inbounds i8, i8* %13, i64 %14
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = call i32 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %10
%20 = load i8*, i8** %3
store i8 0, i8* %20
store i32 1, i32* %2
br label %28
21: ; preds = %10
%22 = load i8*, i8** %3
%23 = call i32 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = load i8*, i8** %3
store i8 0, i8* %26
store i32 2, i32* %2
br label %28
27: ; preds = %21
store i32 0, i32* %2
br label %28
28: ; preds = %27, %25, %19, %9
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [3 x i8] c",1\00"
@.str.1 = [3 x i8] c",2\00"
define i32 @ParseCommaString(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp slt i32 %2, 3
br i1 %3, label %15, label %4
4: ; preds = %1
%5 = add nsw i32 %2, -2
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = tail call i32 @strcmp(i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* dereferenceable(1) %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %4
%11 = tail call i32 @strcmp(i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* dereferenceable(1) %7)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10, %4
%14 = phi i32 [ 1, %4 ], [ 2, %10 ]
store i8 0, i8* %7
br label %15
15: ; preds = %13, %10, %1
%16 = phi i32 [ 0, %1 ], [ 0, %10 ], [ %14, %13 ]
ret i32 %16
}