#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int nColumns() {
  char c;
  int colNum = 0;
  FILE *f;
  f = fopen("car.txt", "r");
  c = fgetc(f);
  while (!feof(f)) {
    if (c == ',' || c == '\n') {
      ++colNum;
      c = fgetc(f);
    } else {
      c = fgetc(f);
      if (feof(f)) {
        ++colNum;
      }
    }
  }
  fclose(f);
  return colNum;
}


x86 assembly (clang, -O0):
<nColumns>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x1(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1191 <nColumns+0x51>
jmp    11f7 <nColumns+0xb7>
movsbl -0x1(%rbp),%eax
cmp    $0x2c,%eax
je     11ab <nColumns+0x6b>
movsbl -0x1(%rbp),%eax
cmp    $0xa,%eax
jne    11c5 <nColumns+0x85>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x1(%rbp)
jmp    11f2 <nColumns+0xb2>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x1(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     11ed <nColumns+0xad>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11f2 <nColumns+0xb2>
jmp    1172 <nColumns+0x32>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nColumns>:
push   %rbp
push   %r14
push   %rbx
lea    0xeb5(%rip),%rdi
lea    0xeb6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1050 <feof@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     1184 <nColumns+0x44>
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %r14d,%r14d
jmp    11ab <nColumns+0x6b>
nopl   0x0(%rax)
add    $0x1,%r14d
mov    %rbp,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1050 <feof@plt>
test   %rax,%rax
jne    1174 <nColumns+0x34>
cmp    $0x2c,%bl
je     1190 <nColumns+0x50>
cmp    $0xa,%bl
je     1190 <nColumns+0x50>
mov    %rbp,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1050 <feof@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%r14d
jmp    119e <nColumns+0x5e>

LLVM IR (-O0):
@.str = [8 x i8] c"car.txt\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @nColumns() {
%1 = alloca i8
%2 = alloca i32
%3 = alloca i32*
store i32 0, i32* %2
%4 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
%5 = load i32*, i32** %3
%6 = call signext i8 @fgetc(i32* %5)
store i8 %6, i8* %1
br label %7
7: ; preds = %35, %0
%8 = load i32*, i32** %3
%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* %1
%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* %1
%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* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
%23 = load i32*, i32** %3
%24 = call signext i8 @fgetc(i32* %23)
store i8 %24, i8* %1
br label %35
25: ; preds = %16
%26 = load i32*, i32** %3
%27 = call signext i8 @fgetc(i32* %26)
store i8 %27, i8* %1
%28 = load i32*, i32** %3
%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* %2
%33 = add nsw i32 %32, 1
store i32 %33, i32* %2
br label %34
34: ; preds = %31, %25
br label %35
35: ; preds = %34, %20
br label %7
36: ; preds = %7
%37 = load i32*, i32** %3
%38 = call i32 @fclose(i32* %37)
%39 = load i32, i32* %2
ret i32 %39
}

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