#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen_read(char *);
int nb_cols_geno(char *file) {
  FILE *fp = fopen_read(file);
  int cols = 0;
  int c;
  c = fgetc(fp);
  while ((c != EOF) && (c != 10)) {
    cols++;
    c = fgetc(fp);
  }
  fclose(fp);
  return cols;
}


x86 assembly (clang, -O0):
<nb_cols_geno>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fopen_read@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
xor    %eax,%eax
mov    0x2e80(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x19(%rbp)
je     117d <nb_cols_geno+0x4d>
cmpl   $0xa,-0x18(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    118d <nb_cols_geno+0x5d>
jmp    11a7 <nb_cols_geno+0x77>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x18(%rbp)
jmp    115c <nb_cols_geno+0x2c>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nb_cols_geno>:
push   %rbp
push   %r14
push   %rbx
call   1050 <fopen_read@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <fgetc@plt>
xor    %ebp,%ebp
cmp    $0xa,%eax
je     1175 <nb_cols_geno+0x45>
mov    0x2e96(%rip),%r14
cmp    (%r14),%eax
je     1175 <nb_cols_geno+0x45>
xor    %ebp,%ebp
nopl   0x0(%rax)
add    $0x1,%ebp
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    $0xa,%eax
je     1175 <nb_cols_geno+0x45>
cmp    (%r14),%eax
jne    1160 <nb_cols_geno+0x30>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
define i32 @nb_cols_geno(i8* %0) {
%2 = tail call i32* @fopen_read(i8* %0)
%3 = tail call i32 @fgetc(i32* %2)
%4 = load i32, i32* @EOF
%5 = icmp ne i32 %3, %4
%6 = icmp ne i32 %3, 10
%7 = and i1 %6, %5
br i1 %7, label %8, label %16
8: ; preds = %1, %8
%9 = phi i32 [ %10, %8 ], [ 0, %1 ]
%10 = add nuw nsw i32 %9, 1
%11 = tail call i32 @fgetc(i32* %2)
%12 = load i32, i32* @EOF
%13 = icmp ne i32 %11, %12
%14 = icmp ne i32 %11, 10
%15 = and i1 %14, %13
br i1 %15, label %8, label %16
16: ; preds = %8, %1
%17 = phi i32 [ 0, %1 ], [ %10, %8 ]
%18 = tail call i32 @fclose(i32* %2)
ret i32 %17
}