#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int nColumns(FILE *f) {
  char c;
  int colNum = 0;
  c = fgetc(f);
  while (!feof(f)) {
    if (c == ',' || c == '\n') {
      ++colNum;
      c = fgetc(f);
    } else {
      c = fgetc(f);
      if (feof(f)) {
        ++colNum;
      }
    }
  }
  return colNum;
}


x86 assembly (clang, -O0):
<nColumns>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    115e <nColumns+0x3e>
jmp    11c4 <nColumns+0xa4>
movsbl -0x9(%rbp),%eax
cmp    $0x2c,%eax
je     1178 <nColumns+0x58>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
jne    1192 <nColumns+0x72>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x9(%rbp)
jmp    11bf <nColumns+0x9f>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
je     11ba <nColumns+0x9a>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11bf <nColumns+0x9f>
jmp    113f <nColumns+0x1f>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nColumns>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
call   1030 <fgetc@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <feof@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     1146 <nColumns+0x26>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %r14d,%r14d
jmp    116b <nColumns+0x4b>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14d
mov    %rbp,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <feof@plt>
test   %rax,%rax
jne    113e <nColumns+0x1e>
cmp    $0x2c,%bl
je     1150 <nColumns+0x30>
cmp    $0xa,%bl
je     1150 <nColumns+0x30>
mov    %rbp,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <feof@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%r14d
jmp    115e <nColumns+0x3e>

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

LLVM IR (-O2):
define i32 @nColumns(i32* nocapture %0) {
%2 = tail call signext i8 @fgetc(i32* %0)
%3 = tail call i64 @feof(i32* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %22
5: ; preds = %1, %17
%6 = phi i32 [ %19, %17 ], [ 0, %1 ]
%7 = phi i8 [ %18, %17 ], [ %2, %1 ]
switch i8 %7, label %11 [
i8 44, label %8
i8 10, label %8
]
8: ; preds = %5, %5
%9 = add nsw i32 %6, 1
%10 = tail call signext i8 @fgetc(i32* %0)
br label %17
11: ; preds = %5
%12 = tail call signext i8 @fgetc(i32* %0)
%13 = tail call i64 @feof(i32* %0)
%14 = icmp ne i64 %13, 0
%15 = zext i1 %14 to i32
%16 = add nsw i32 %6, %15
br label %17
17: ; preds = %11, %8
%18 = phi i8 [ %10, %8 ], [ %12, %11 ]
%19 = phi i32 [ %9, %8 ], [ %16, %11 ]
%20 = tail call i64 @feof(i32* %0)
%21 = icmp eq i64 %20, 0
br i1 %21, label %5, label %22
22: ; preds = %17, %1
%23 = phi i32 [ 0, %1 ], [ %19, %17 ]
ret i32 %23
}