#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*/ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int matrix_getColCount(FILE *file) {
  int count = 0;
  int c;
  do {
    c = fgetc(file);
    if (c == ' ')
      count++;
  } while (c != '\n' && !feof(file));
  rewind(file);
  return count + 1;
}


x86 assembly (clang, -O0):
<matrix_getColCount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x20,-0x10(%rbp)
jne    1162 <matrix_getColCount+0x32>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1167 <matrix_getColCount+0x37>
xor    %eax,%eax
cmpl   $0xa,-0x10(%rbp)
mov    %al,-0x11(%rbp)
je     118a <matrix_getColCount+0x5a>
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1143 <matrix_getColCount+0x13>
mov    -0x8(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix_getColCount>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %ebp,%ebx
mov    %r14,%rdi
call   1040 <fgetc@plt>
xor    %ebp,%ebp
cmp    $0x20,%eax
sete   %bpl
add    %ebx,%ebp
cmp    $0xa,%eax
je     1166 <matrix_getColCount+0x36>
mov    %r14,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     1140 <matrix_getColCount+0x10>
mov    %r14,%rdi
call   1030 <rewind@plt>
add    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @matrix_getColCount(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %3
br label %5
5: ; preds = %22, %1
%6 = load i32*, i32** %2
%7 = call i32 @fgetc(i32* %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 32
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i32, i32* %3
%12 = add nsw i32 %11, 1
store i32 %12, i32* %3
br label %13
13: ; preds = %10, %5
br label %14
14: ; preds = %13
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 10
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i32*, i32** %2
%19 = call i32 @feof(i32* %18)
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
br label %22
22: ; preds = %17, %14
%23 = phi i1 [ false, %14 ], [ %21, %17 ]
br i1 %23, label %5, label %24
24: ; preds = %22
%25 = load i32*, i32** %2
%26 = call i32 @rewind(i32* %25)
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
ret i32 %28
}

LLVM IR (-O2):
define i32 @matrix_getColCount(i32* nocapture %0) {
br label %2
2: ; preds = %9, %1
%3 = phi i32 [ 0, %1 ], [ %7, %9 ]
%4 = tail call i32 @fgetc(i32* %0)
%5 = icmp eq i32 %4, 32
%6 = zext i1 %5 to i32
%7 = add nuw nsw i32 %3, %6
%8 = icmp eq i32 %4, 10
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = tail call i32 @feof(i32* %0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %2, label %12
12: ; preds = %2, %9
%13 = tail call i32 @rewind(i32* %0)
%14 = add nuw nsw i32 %7, 1
ret i32 %14
}