#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 mutilsHowmanyCommas(char *buf) {
  int n = 0, length;
  if (*buf == '\0')
    return (0);
  length = strlen(buf);
  if ((length % 3) == 0)
    n = (length / 3) - 1;
  else
    n = length / 3;
  if (n < 0)
    n = 0;
  return (n);
}


x86 assembly (clang, -O0):
<mutilsHowmanyCommas>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    113f <mutilsHowmanyCommas+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    119a <mutilsHowmanyCommas+0x8a>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1175 <mutilsHowmanyCommas+0x65>
mov    -0x18(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1183 <mutilsHowmanyCommas+0x73>
mov    -0x18(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1194 <mutilsHowmanyCommas+0x84>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mutilsHowmanyCommas>:
push   %rax
cmpb   $0x0,(%rdi)
je     1146 <mutilsHowmanyCommas+0x36>
call   1030 <strlen@plt>
movslq %eax,%rcx
imul   $0x55555556,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rax
add    %edx,%eax
lea    (%rax,%rax,2),%edx
xor    %esi,%esi
cmp    %edx,%ecx
sete   %sil
xor    %ecx,%ecx
sub    %esi,%eax
cmovs  %ecx,%eax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
define i32 @mutilsHowmanyCommas(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = srem i32 %5, 3
%7 = icmp eq i32 %6, 0
%8 = sdiv i32 %5, 3
%9 = sext i1 %7 to i32
%10 = add nsw i32 %8, %9
%11 = icmp sgt i32 %10, 0
%12 = select i1 %11, i32 %10, i32 0
br label %13
13: ; preds = %1, %4
%14 = phi i32 [ %12, %4 ], [ 0, %1 ]
ret i32 %14
}