#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__ EOF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int cols_count(char file[400], int rows) {
  FILE *fp;
  int c = 0;
  char junk[40];
  if ((fp = fopen(file, "r")) == NULL) {
    printf("Cannot open file %s \n", file);
    exit(0);
  }
  while (fscanf(fp, "%s", junk) != EOF)
    c++;
  fclose(fp);
  return (c / rows);
}


x86 assembly (clang, -O0):
<cols_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    119b <cols_count+0x4b>
mov    -0x8(%rbp),%rsi
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
jmp    11a0 <cols_count+0x50>
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe69(%rip),%rsi
call   1050 <fscanf@plt>
mov    0x2e2d(%rip),%rcx
cmp    (%rcx),%rax
je     11d2 <cols_count+0x82>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a0 <cols_count+0x50>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
cltd
idivl  -0xc(%rbp)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cols_count>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%r14d
mov    %rdi,%rbp
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c4 <cols_count+0x74>
mov    %rax,%rbx
mov    $0xffffffff,%ebp
lea    0xe94(%rip),%r15
mov    %rsp,%r12
mov    0x2e5a(%rip),%r13
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <fscanf@plt>
add    $0x1,%ebp
cmp    0x0(%r13),%rax
jne    1190 <cols_count+0x40>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
cltd
idiv   %r14d
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe37(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"Cannot open file %s \0A\00"
@.str.2 = [3 x i8] c"%s\00"
@EOF = global i64 0
define i32 @cols_count(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [40 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %6
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %2
br label %16
16: ; preds = %22, %15
%17 = load i32*, i32** %5
%18 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%19 = call i64 @fscanf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = load i64, i64* @EOF
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %16
25: ; preds = %16
%26 = load i32*, i32** %5
%27 = call i32 @fclose(i32* %26)
%28 = load i32, i32* %6
%29 = load i32, i32* %4
%30 = sdiv i32 %28, %29
ret i32 %30
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"Cannot open file %s \0A\00"
@.str.2 = [3 x i8] c"%s\00"
@EOF = global i64 0
define i32 @cols_count(i8* %0, i32 %1) {
%3 = alloca [40 x i8]
%4 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %2, %10
%11 = phi i32 [ %15, %10 ], [ 0, %2 ]
%12 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%13 = load i64, i64* @EOF
%14 = icmp eq i64 %12, %13
%15 = add nuw nsw i32 %11, 1
br i1 %14, label %16, label %10
16: ; preds = %10
%17 = call i32 @fclose(i32* %5)
%18 = sdiv i32 %11, %1
ret i32 %18
}