#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*/ exit(int);
double floor(double);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int nb_ind_ancestrymap(char *);
int nb_lines(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read_ancestrymap(char *, int, int, int *);
int /*<<< orphan*/ write_geno(char *, int, int, int *);
void ancestrymap2geno(char *input_file, char *output_file, int *N, int *M) {
  int *data;
  int nb;
  double tmp;
  *N = nb_ind_ancestrymap(input_file);
  nb = nb_lines(input_file, 1000);
  tmp = (double)nb / (double)(*N);
  if (tmp != floor(tmp)) {
    printf("Error: incorrect number of lines in %s.\n", input_file);
    exit(1);
  }
  *M = (int)tmp;
  data = (int *)malloc((*N) * (*M) * sizeof(int));
  read_ancestrymap(input_file, *N, *M, data);
  write_geno(output_file, *N, *M, data);
  free(data);
}


x86 assembly (clang, -O0):
<ancestrymap2geno>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <nb_ind_ancestrymap@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x3e8,%esi
call   1050 <nb_lines@plt>
mov    %eax,-0x2c(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
cvtsi2sdl (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
call   10b0 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jne    1211 <ancestrymap2geno+0x81>
jp     1211 <ancestrymap2geno+0x81>
jmp    122b <ancestrymap2geno+0x9b>
mov    -0x8(%rbp),%rsi
lea    0xde4(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
cvttsd2si -0x38(%rbp),%ecx
mov    -0x20(%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   1080 <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   1070 <read_ancestrymap@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    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ancestrymap2geno>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r15
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r12
call   1090 <nb_ind_ancestrymap@plt>
mov    %eax,0x0(%r13)
mov    %r12,%rdi
mov    $0x3e8,%esi
call   1050 <nb_lines@plt>
cvtsi2sd %eax,%xmm0
cvtsi2sdl 0x0(%r13),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
call   10b0 <floor@plt>
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jne    1236 <ancestrymap2geno+0xa6>
jp     1236 <ancestrymap2geno+0xa6>
cvttsd2si %xmm1,%edi
mov    %edi,(%r15)
imul   0x0(%r13),%edi
shl    $0x2,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    0x0(%r13),%esi
mov    (%r15),%edx
mov    %r12,%rdi
mov    %rax,%rcx
call   1070 <read_ancestrymap@plt>
mov    0x0(%r13),%esi
mov    (%r15),%edx
mov    %r14,%rdi
mov    %rbx,%rcx
call   1030 <write_geno@plt>
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <free@plt>
lea    0xdc3(%rip),%rdi
mov    %r12,%rsi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"Error: incorrect number of lines in %s.\0A\00"
define void @ancestrymap2geno(i8* %0, i8* %1, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca double
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%12 = load i8*, i8** %5
%13 = call i32 @nb_ind_ancestrymap(i8* %12)
%14 = load i32*, i32** %7
store i32 %13, i32* %14
%15 = load i8*, i8** %5
%16 = call i32 @nb_lines(i8* %15, i32 1000)
store i32 %16, i32* %10
%17 = load i32, i32* %10
%18 = sitofp i32 %17 to double
%19 = load i32*, i32** %7
%20 = load i32, i32* %19
%21 = sitofp i32 %20 to double
%22 = fdiv double %18, %21
store double %22, double* %11
%23 = load double, double* %11
%24 = load double, double* %11
%25 = call double @llvm.floor.f64(double %24)
%26 = fcmp une double %23, %25
br i1 %26, label %27, label %31
27: ; preds = %4
%28 = load i8*, i8** %5
%29 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %4
%32 = load double, double* %11
%33 = fptosi double %32 to i32
%34 = load i32*, i32** %8
store i32 %33, i32* %34
%35 = load i32*, i32** %7
%36 = load i32, i32* %35
%37 = load i32*, i32** %8
%38 = load i32, i32* %37
%39 = mul nsw i32 %36, %38
%40 = sext i32 %39 to i64
%41 = mul i64 %40, 4
%42 = trunc i64 %41 to i32
%43 = call i64 @malloc(i32 %42)
%44 = inttoptr i64 %43 to i32*
store i32* %44, i32** %9
%45 = load i8*, i8** %5
%46 = load i32*, i32** %7
%47 = load i32, i32* %46
%48 = load i32*, i32** %8
%49 = load i32, i32* %48
%50 = load i32*, i32** %9
%51 = call i32 @read_ancestrymap(i8* %45, i32 %47, i32 %49, i32* %50)
%52 = load i8*, i8** %6
%53 = load i32*, i32** %7
%54 = load i32, i32* %53
%55 = load i32*, i32** %8
%56 = load i32, i32* %55
%57 = load i32*, i32** %9
%58 = call i32 @write_geno(i8* %52, i32 %54, i32 %56, i32* %57)
%59 = load i32*, i32** %9
%60 = call i32 @free(i32* %59)
ret void
}

LLVM IR (-O2):
@.str = [41 x i8] c"Error: incorrect number of lines in %s.\0A\00"
define void @ancestrymap2geno(i8* %0, i8* %1, i32* nocapture %2, i32* nocapture %3) {
%5 = tail call i32 @nb_ind_ancestrymap(i8* %0)
store i32 %5, i32* %2
%6 = tail call i32 @nb_lines(i8* %0, i32 1000)
%7 = sitofp i32 %6 to double
%8 = load i32, i32* %2
%9 = sitofp i32 %8 to double
%10 = fdiv double %7, %9
%11 = tail call double @llvm.floor.f64(double %10)
%12 = fcmp une double %10, %11
br i1 %12, label %13, label %16
13: ; preds = %4
%14 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %0)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %4
%17 = fptosi double %10 to i32
store i32 %17, i32* %3
%18 = load i32, i32* %2
%19 = shl i32 %17, 2
%20 = mul i32 %19, %18
%21 = tail call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i32*
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = tail call i32 @read_ancestrymap(i8* %0, i32 %23, i32 %24, i32* %22)
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = tail call i32 @write_geno(i8* %1, i32 %26, i32 %27, i32* %22)
%29 = tail call i32 @free(i32* %22)
ret void
}