#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 */

/* Variables and functions */
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int nb_cols_lfmm(char *);
int nb_lines(char *, int);
int /*<<< orphan*/ read_data_int(char *, int, int, int *);
int /*<<< orphan*/ write_geno(char *, int, int, int *);
void lfmm2geno(char *input_file, char *output_file, int *N, int *M) {
  int *data;
  *M = nb_cols_lfmm(input_file);
  *N = nb_lines(input_file, *M);
  data = (int *)malloc((*N) * (*M) * sizeof(int));
  read_data_int(input_file, *N, *M, data);
  write_geno(output_file, *N, *M, data);
  free(data);
}


x86 assembly (clang, -O0):
<lfmm2geno>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <nb_cols_lfmm@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1050 <nb_lines@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x20(%rbp),%rcx
imul   (%rcx),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x28(%rbp),%rcx
call   1060 <read_data_int@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x28(%rbp),%rcx
call   1030 <write_geno@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lfmm2geno>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r13
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
call   1080 <nb_cols_lfmm@plt>
mov    %eax,0x0(%r13)
mov    %r12,%rdi
mov    %eax,%esi
call   1050 <nb_lines@plt>
mov    %eax,(%r15)
imul   0x0(%r13),%eax
lea    0x0(,%rax,4),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    (%r15),%esi
mov    0x0(%r13),%edx
mov    %r12,%rdi
mov    %rax,%rcx
call   1060 <read_data_int@plt>
mov    (%r15),%esi
mov    0x0(%r13),%edx
mov    %r14,%rdi
mov    %rbx,%rcx
call   1030 <write_geno@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <free@plt>

LLVM IR (-O0):
define void @lfmm2geno(i8* %0, i8* %1, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%10 = load i8*, i8** %5
%11 = call i32 @nb_cols_lfmm(i8* %10)
%12 = load i32*, i32** %8
store i32 %11, i32* %12
%13 = load i8*, i8** %5
%14 = load i32*, i32** %8
%15 = load i32, i32* %14
%16 = call i32 @nb_lines(i8* %13, i32 %15)
%17 = load i32*, i32** %7
store i32 %16, i32* %17
%18 = load i32*, i32** %7
%19 = load i32, i32* %18
%20 = load i32*, i32** %8
%21 = load i32, i32* %20
%22 = mul nsw i32 %19, %21
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 4
%25 = trunc i64 %24 to i32
%26 = call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to i32*
store i32* %27, i32** %9
%28 = load i8*, i8** %5
%29 = load i32*, i32** %7
%30 = load i32, i32* %29
%31 = load i32*, i32** %8
%32 = load i32, i32* %31
%33 = load i32*, i32** %9
%34 = call i32 @read_data_int(i8* %28, i32 %30, i32 %32, i32* %33)
%35 = load i8*, i8** %6
%36 = load i32*, i32** %7
%37 = load i32, i32* %36
%38 = load i32*, i32** %8
%39 = load i32, i32* %38
%40 = load i32*, i32** %9
%41 = call i32 @write_geno(i8* %35, i32 %37, i32 %39, i32* %40)
%42 = load i32*, i32** %9
%43 = call i32 @free(i32* %42)
ret void
}

LLVM IR (-O2):
define void @lfmm2geno(i8* %0, i8* %1, i32* nocapture %2, i32* nocapture %3) {
%5 = tail call i32 @nb_cols_lfmm(i8* %0)
store i32 %5, i32* %3
%6 = tail call i32 @nb_lines(i8* %0, i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* %3
%8 = shl i32 %6, 2
%9 = mul i32 %8, %7
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i32*
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = tail call i32 @read_data_int(i8* %0, i32 %12, i32 %13, i32* %11)
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = tail call i32 @write_geno(i8* %1, i32 %15, i32 %16, i32* %11)
%18 = tail call i32 @free(i32* %11)
ret void
}