#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int strlen(char *);
char *strtok(char *, char *);
void read_file(FILE *fp, int *rowMaxIndex, int *columnMaxIndex) {
  char part[1024];
  char *token;
  int idx;
  *rowMaxIndex = 0;
  *columnMaxIndex = 0;
  while (fgets(part, 1024, fp) != NULL) {
    token = NULL;
    while ((token = strtok((token == NULL) ? part : NULL, ",")) != NULL) {
      if (*rowMaxIndex == 0) {
        *columnMaxIndex = *columnMaxIndex + 1;
      }
      for (idx = 0; idx < strlen(token); idx++) {
        if (token[idx] == '\n') {
          *rowMaxIndex = *rowMaxIndex + 1;
          break;
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1278 <read_file+0x148>
movq   $0x0,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    11a6 <read_file+0x76>
lea    -0x420(%rbp),%rax
mov    %rax,-0x438(%rbp)
jmp    11b4 <read_file+0x84>
xor    %eax,%eax
mov    %rax,-0x438(%rbp)
jmp    11b4 <read_file+0x84>
mov    -0x438(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
je     1273 <read_file+0x143>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11f4 <read_file+0xc4>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x42c(%rbp)
mov    -0x42c(%rbp),%eax
mov    %eax,-0x43c(%rbp)
mov    -0x428(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x43c(%rbp),%eax
cmp    %ecx,%eax
jge    126e <read_file+0x13e>
mov    -0x428(%rbp),%rax
movslq -0x42c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1255 <read_file+0x125>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    126e <read_file+0x13e>
jmp    125a <read_file+0x12a>
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
jmp    11fe <read_file+0xce>
jmp    1185 <read_file+0x55>
jmp    115b <read_file+0x2b>
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rdx
movl   $0x0,(%rsi)
movl   $0x0,(%r14)
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %rdx,0x8(%rsp)
call   1040 <fgets@plt>
test   %rax,%rax
je     120d <read_file+0xdd>
lea    0xe85(%rip),%r12
lea    0x10(%rsp),%r13
jmp    11a7 <read_file+0x77>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    $0x400,%esi
mov    0x8(%rsp),%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     120d <read_file+0xdd>
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
je     1190 <read_file+0x60>
mov    %rax,%rbp
jmp    11d5 <read_file+0xa5>
nopl   0x0(%rax)
addl   $0x1,(%rbx)
xor    %edi,%edi
mov    %r12,%rsi
call   1050 <strtok@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1190 <read_file+0x60>
cmpl   $0x0,(%rbx)
jne    11de <read_file+0xae>
addl   $0x1,(%r14)
mov    %rbp,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11c3 <read_file+0x93>
xor    %r15d,%r15d
nopl   (%rax)
cmpb   $0xa,0x0(%rbp,%r15,1)
je     11c0 <read_file+0x90>
add    $0x1,%r15
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%r15
jl     11f0 <read_file+0xc0>
jmp    11c3 <read_file+0x93>
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
define void @read_file(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca i8*
%9 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%10 = load i32*, i32** %5
store i32 0, i32* %10
%11 = load i32*, i32** %6
store i32 0, i32* %11
br label %12
12: ; preds = %61, %3
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%14 = load i32*, i32** %4
%15 = call i32* @fgets(i8* %13, i32 1024, i32* %14)
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %62
17: ; preds = %12
store i8* null, i8** %8
br label %18
18: ; preds = %60, %17
%19 = load i8*, i8** %8
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
br label %24
23: ; preds = %18
br label %24
24: ; preds = %23, %21
%25 = phi i8* [ %22, %21 ], [ null, %23 ]
%26 = call i8* @strtok(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %26, i8** %8
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %61
28: ; preds = %24
%29 = load i32*, i32** %5
%30 = load i32, i32* %29
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load i32*, i32** %6
%34 = load i32, i32* %33
%35 = add nsw i32 %34, 1
%36 = load i32*, i32** %6
store i32 %35, i32* %36
br label %37
37: ; preds = %32, %28
store i32 0, i32* %9
br label %38
38: ; preds = %57, %37
%39 = load i32, i32* %9
%40 = load i8*, i8** %8
%41 = call i32 @strlen(i8* %40)
%42 = icmp slt i32 %39, %41
br i1 %42, label %43, label %60
43: ; preds = %38
%44 = load i8*, i8** %8
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 10
br i1 %50, label %51, label %56
51: ; preds = %43
%52 = load i32*, i32** %5
%53 = load i32, i32* %52
%54 = add nsw i32 %53, 1
%55 = load i32*, i32** %5
store i32 %54, i32* %55
br label %60
56: ; preds = %43
br label %57
57: ; preds = %56
%58 = load i32, i32* %9
%59 = add nsw i32 %58, 1
store i32 %59, i32* %9
br label %38
60: ; preds = %51, %38
br label %18
61: ; preds = %24
br label %12
62: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
define void @read_file(i32* nocapture %0, i32* nocapture %1, i32* nocapture %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
store i32 0, i32* %1
store i32 0, i32* %2
%6 = call i32* @fgets(i8* %5, i32 1024, i32* %0)
%7 = icmp eq i32* %6, null
br i1 %7, label %40, label %11
8: ; preds = %37, %11
%9 = call i32* @fgets(i8* %5, i32 1024, i32* %0)
%10 = icmp eq i32* %9, null
br i1 %10, label %40, label %11
11: ; preds = %3, %8
%12 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %8, label %14
14: ; preds = %11, %37
%15 = phi i8* [ %38, %37 ], [ %12, %11 ]
%16 = load i32, i32* %1
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %21
21: ; preds = %18, %14
%22 = call i32 @strlen(i8* %15)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %28, label %37
24: ; preds = %28
%25 = call i32 @strlen(i8* %15)
%26 = sext i32 %25 to i64
%27 = icmp slt i64 %33, %26
br i1 %27, label %28, label %37
28: ; preds = %21, %24
%29 = phi i64 [ %33, %24 ], [ 0, %21 ]
%30 = getelementptr inbounds i8, i8* %15, i64 %29
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 10
%33 = add nuw nsw i64 %29, 1
br i1 %32, label %34, label %24
34: ; preds = %28
%35 = load i32, i32* %1
%36 = add nsw i32 %35, 1
store i32 %36, i32* %1
br label %37
37: ; preds = %24, %21, %34
%38 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%39 = icmp eq i8* %38, null
br i1 %39, label %8, label %14
40: ; preds = %8, %3
ret void
}