#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*/ dataInfo;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int atof(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *malloc(int);
int /*<<< orphan*/ strtok(char *, char *);
char *readData(char *file, int *lines, int *cols) {
  char dataInfo[10];
  FILE *f = fopen(file, "r");
  fgets(dataInfo, sizeof(dataInfo), f);
  *lines = atof(strtok(dataInfo, " "));
  *cols = atof(strtok(NULL, " \r\n"));
  int bufsize = (*lines) * (*cols);
  char *buffer = malloc(bufsize);
  char *buf_ptr = buffer;
  while (fgets(buf_ptr, bufsize, f) != NULL) {
    buf_ptr += (*cols);
  }
  fclose(f);
  return buffer;
}


x86 assembly (clang, -O0):
<readData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
lea    -0x22(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0xa,%esi
call   1050 <fgets@plt>
lea    -0x22(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1080 <strtok@plt>
mov    %eax,%edi
call   1030 <atof@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe40(%rip),%rsi
call   1080 <strtok@plt>
mov    %eax,%edi
call   1030 <atof@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
imul   (%rcx),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%rdx
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     122f <readData+0xcf>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
jmp    11fc <readData+0x9c>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x40(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readData>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
lea    0xe87(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
lea    0x6(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
lea    0xe65(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strtok@plt>
mov    %eax,%edi
call   1030 <atof@plt>
mov    %eax,(%r15)
lea    0xe4e(%rip),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
mov    %eax,%edi
call   1030 <atof@plt>
mov    %eax,%ebp
mov    %eax,(%r14)
imul   (%r15),%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1208 <readData+0xa8>
mov    %r15,%rbx
nopl   0x0(%rax)
movslq (%r14),%rax
add    %rax,%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11f0 <readData+0x90>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [4 x i8] c" \0D\0A\00"
define i8* @readData(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [10 x i8]
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %8
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%15 = load i32*, i32** %8
%16 = call i32* @fgets(i8* %14, i32 10, i32* %15)
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%18 = call i32 @strtok(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @atof(i32 %18)
%20 = load i32*, i32** %5
store i32 %19, i32* %20
%21 = call i32 @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @atof(i32 %21)
%23 = load i32*, i32** %6
store i32 %22, i32* %23
%24 = load i32*, i32** %5
%25 = load i32, i32* %24
%26 = load i32*, i32** %6
%27 = load i32, i32* %26
%28 = mul nsw i32 %25, %27
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = call i8* @malloc(i32 %29)
store i8* %30, i8** %10
%31 = load i8*, i8** %10
store i8* %31, i8** %11
br label %32
32: ; preds = %38, %3
%33 = load i8*, i8** %11
%34 = load i32, i32* %9
%35 = load i32*, i32** %8
%36 = call i32* @fgets(i8* %33, i32 %34, i32* %35)
%37 = icmp ne i32* %36, null
br i1 %37, label %38, label %44
38: ; preds = %32
%39 = load i32*, i32** %6
%40 = load i32, i32* %39
%41 = load i8*, i8** %11
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds i8, i8* %41, i64 %42
store i8* %43, i8** %11
br label %32
44: ; preds = %32
%45 = load i32*, i32** %8
%46 = call i32 @fclose(i32* %45)
%47 = load i8*, i8** %10
ret i8* %47
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [4 x i8] c" \0D\0A\00"
define i8* @readData(i8* nocapture %0, i32* nocapture %1, i32* nocapture %2) {
%4 = alloca [10 x i8]
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = call i32* @fgets(i8* %5, i32 10, i32* %6)
%8 = call i32 @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @atof(i32 %8)
store i32 %9, i32* %1
%10 = call i32 @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @atof(i32 %10)
store i32 %11, i32* %2
%12 = load i32, i32* %1
%13 = mul nsw i32 %12, %11
%14 = call i8* @malloc(i32 %13)
%15 = call i32* @fgets(i8* %14, i32 %13, i32* %6)
%16 = icmp eq i32* %15, null
br i1 %16, label %24, label %17
17: ; preds = %3, %17
%18 = phi i8* [ %21, %17 ], [ %14, %3 ]
%19 = load i32, i32* %2
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = call i32* @fgets(i8* %21, i32 %13, i32* %6)
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %17
24: ; preds = %17, %3
%25 = call i32 @fclose(i32* %6)
ret i8* %14
}