#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 count_fields(char *line) {
  int count = 0;
  int done = 0;
  char *c;
  for (c = line; !done; ++c) {
    done = (*c == '\0');
    if (*c == ',' || done)
      ++count;
  }
  return count;
}


x86 assembly (clang, -O0):
<count_fields>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x10(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1134 <count_fields+0x34>
jmp    1182 <count_fields+0x82>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
je     1163 <count_fields+0x63>
cmpl   $0x0,-0x10(%rbp)
je     116c <count_fields+0x6c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1171 <count_fields+0x71>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    111e <count_fields+0x1e>
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_fields>:
xor    %eax,%eax
jmp    111b <count_fields+0x1b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%eax
add    $0x1,%rdi
test   %cl,%cl
je     1129 <count_fields+0x29>
movzbl (%rdi),%ecx
cmp    $0x2c,%cl
je     1110 <count_fields+0x10>
test   %cl,%cl
je     1110 <count_fields+0x10>
jmp    1113 <count_fields+0x13>
ret

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

LLVM IR (-O2):
define i32 @count_fields(i8* nocapture %0) {
br label %2
2: ; preds = %1, %9
%3 = phi i8* [ %0, %1 ], [ %11, %9 ]
%4 = phi i32 [ 0, %1 ], [ %10, %9 ]
%5 = load i8, i8* %3
%6 = icmp eq i8 %5, 0
switch i8 %5, label %9 [
i8 44, label %7
i8 0, label %7
]
7: ; preds = %2, %2
%8 = add nsw i32 %4, 1
br label %9
9: ; preds = %2, %7
%10 = phi i32 [ %8, %7 ], [ %4, %2 ]
%11 = getelementptr inbounds i8, i8* %3, i64 1
br i1 %6, label %12, label %2
12: ; preds = %9
ret i32 %10
}