#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 strlen(char *);
int parse_mmstr(char *mmstr) {
  int mm = 0, i;
  if (strlen(mmstr) > 0)
    mm++;
  for (i = 0; i <= strlen(mmstr); i++) {
    if (mmstr[i] == ',')
      mm++;
  }
  return (mm);
}


x86 assembly (clang, -O0):
<parse_mmstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jle    113e <parse_mmstr+0x2e>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jg     1192 <parse_mmstr+0x82>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
jne    117f <parse_mmstr+0x6f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1184 <parse_mmstr+0x74>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1145 <parse_mmstr+0x35>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_mmstr>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
xor    %ebp,%ebp
test   %eax,%eax
setg   %bpl
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
js     1160 <parse_mmstr+0x50>
mov    $0xffffffffffffffff,%rbx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
cmpb   $0x2c,0x1(%r14,%rbx,1)
sete   %al
add    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
add    $0x1,%rbx
cmp    %rax,%rbx
jl     1140 <parse_mmstr+0x30>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @parse_mmstr(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* %3
%10 = add nsw i32 %9, 1
store i32 %10, i32* %3
br label %11
11: ; preds = %8, %1
store i32 0, i32* %4
br label %12
12: ; preds = %29, %11
%13 = load i32, i32* %4
%14 = load i8*, i8** %2
%15 = call i32 @strlen(i8* %14)
%16 = icmp sle i32 %13, %15
br i1 %16, label %17, label %32
17: ; preds = %12
%18 = load i8*, i8** %2
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 44
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %28
28: ; preds = %25, %17
br label %29
29: ; preds = %28
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %12
32: ; preds = %12
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
define i32 @parse_mmstr(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %19, label %7
7: ; preds = %1, %7
%8 = phi i64 [ %15, %7 ], [ 0, %1 ]
%9 = phi i32 [ %14, %7 ], [ %4, %1 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %8
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 44
%13 = zext i1 %12 to i32
%14 = add nuw nsw i32 %9, %13
%15 = add nuw nsw i64 %8, 1
%16 = tail call i32 @strlen(i8* %0)
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %8, %17
br i1 %18, label %7, label %19
19: ; preds = %7, %1
%20 = phi i32 [ %4, %1 ], [ %14, %7 ]
ret i32 %20
}