#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*/ ancestrymap2geno(char *, char *, int *, int *);
int /*<<< orphan*/ ancestrymap2lfmm(char *, char *, int *, int *);
scalar_t__ atoi(char *);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int nb_ind_ancestrymap(char *);
int /*<<< orphan*/ printf(char *, int, int, ...);
int /*<<< orphan*/ read_ancestrymap(char *, int, int, int *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ write_data_int(char *, int, int, int *);
int main(int argc, char *argv[]) {
  char input_file[512];
  char output_file1[512];
  char output_file2[512];
  char output_file3[512];
  int N, M;
  int test_N, test_M;
  int test_n, test_m;
  int *data;
  strcpy(input_file, argv[1]);
  N = (int)atoi(argv[2]);
  M = (int)atoi(argv[3]);
  strcpy(output_file1, argv[4]);
  strcpy(output_file2, argv[5]);
  strcpy(output_file3, argv[6]);
  data = (int *)malloc(N * M * sizeof(int));
  read_ancestrymap(input_file, N, M, data);
  write_data_int(output_file1, N, M, data);
  test_N = nb_ind_ancestrymap(input_file);
  if (test_N != N) {
    printf("Test ERROR: incorrect N detected, %d instead of %d!\n", test_N, N);
    return 1;
  }
  ancestrymap2geno(input_file, output_file2, &test_N, &test_M);
  if (N != test_N || M != test_M) {
    printf(
        "Test ERROR: incorrect N or M detected, %d (%d) instead of %d (%d) !\n",
        test_N, test_M, N, M);
    return 1;
  }
  ancestrymap2lfmm(input_file, output_file3, &test_n, &test_m);
  if (N != test_n || M != test_m) {
    printf(
        "Test ERROR: incorrect N or M detected, %d (%d) instead of %d (%d) !\n",
        test_n, test_m, N, M);
    return 1;
  }
  free(data);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x814(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x818(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rsi
call   1040 <strcpy@plt>
lea    -0x610(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rsi
call   1040 <strcpy@plt>
lea    -0x810(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x814(%rbp),%eax
imul   -0x818(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x830(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x814(%rbp),%esi
mov    -0x818(%rbp),%edx
mov    -0x830(%rbp),%rcx
call   1080 <read_ancestrymap@plt>
lea    -0x410(%rbp),%rdi
mov    -0x814(%rbp),%esi
mov    -0x818(%rbp),%edx
mov    -0x830(%rbp),%rcx
call   1070 <write_data_int@plt>
lea    -0x210(%rbp),%rdi
call   10a0 <nb_ind_ancestrymap@plt>
mov    %eax,-0x81c(%rbp)
mov    -0x81c(%rbp),%eax
cmp    -0x814(%rbp),%eax
je     12d8 <main+0x138>
mov    -0x81c(%rbp),%esi
mov    -0x814(%rbp),%edx
lea    0xd3b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13db <main+0x23b>
lea    -0x210(%rbp),%rdi
lea    -0x610(%rbp),%rsi
lea    -0x81c(%rbp),%rdx
lea    -0x820(%rbp),%rcx
call   10b0 <ancestrymap2geno@plt>
mov    -0x814(%rbp),%eax
cmp    -0x81c(%rbp),%eax
jne    131d <main+0x17d>
mov    -0x818(%rbp),%eax
cmp    -0x820(%rbp),%eax
je     1350 <main+0x1b0>
mov    -0x81c(%rbp),%esi
mov    -0x820(%rbp),%edx
mov    -0x814(%rbp),%ecx
mov    -0x818(%rbp),%r8d
lea    0xcf8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13db <main+0x23b>
lea    -0x210(%rbp),%rdi
lea    -0x810(%rbp),%rsi
lea    -0x824(%rbp),%rdx
lea    -0x828(%rbp),%rcx
call   1050 <ancestrymap2lfmm@plt>
mov    -0x814(%rbp),%eax
cmp    -0x824(%rbp),%eax
jne    1395 <main+0x1f5>
mov    -0x818(%rbp),%eax
cmp    -0x828(%rbp),%eax
je     13c8 <main+0x228>
mov    -0x824(%rbp),%esi
mov    -0x828(%rbp),%edx
mov    -0x814(%rbp),%ecx
mov    -0x818(%rbp),%r8d
lea    0xc80(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13db <main+0x23b>
mov    -0x830(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rsi
lea    0x10(%rsp),%r12
mov    %r12,%rdi
call   1040 <strcpy@plt>
mov    0x10(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %rax,%r13
mov    0x18(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %rax,%r14
mov    0x20(%rbx),%rsi
lea    0x610(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strcpy@plt>
mov    0x28(%rbx),%rsi
lea    0x410(%rsp),%rdi
call   1040 <strcpy@plt>
mov    0x30(%rbx),%rsi
lea    0x210(%rsp),%rdi
call   1040 <strcpy@plt>
mov    %r14d,%edi
imul   %r13d,%edi
shl    $0x2,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    %r12,%rdi
mov    %r13d,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   1080 <read_ancestrymap@plt>
mov    %rbp,%rdi
mov    %r13d,%esi
mov    %r14d,%edx
mov    %r15,%rcx
call   1070 <write_data_int@plt>
mov    %r12,%rdi
call   10a0 <nb_ind_ancestrymap@plt>
mov    %eax,(%rsp)
cmp    %r13d,%eax
jne    12bc <main+0x11c>
lea    0x10(%rsp),%rdi
lea    0x410(%rsp),%rsi
mov    %rsp,%rdx
lea    0xc(%rsp),%rcx
call   10b0 <ancestrymap2geno@plt>
mov    (%rsp),%esi
mov    0xc(%rsp),%edx
cmp    %r13d,%esi
jne    12d1 <main+0x131>
cmp    %r14d,%edx
jne    12d1 <main+0x131>
lea    0x10(%rsp),%rdi
lea    0x210(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
call   1050 <ancestrymap2lfmm@plt>
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
cmp    %r13d,%esi
jne    12d1 <main+0x131>
cmp    %r14d,%edx
jne    12d1 <main+0x131>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    12ea <main+0x14a>
lea    0xd3d(%rip),%rdi
mov    %eax,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12e5 <main+0x145>
lea    0xd5d(%rip),%rdi
mov    %r13d,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [53 x i8] c"Test ERROR: incorrect N detected, %d instead of %d!\0A\00"
@.str.1 = [69 x i8] c"Test ERROR: incorrect N or M detected, %d (%d) instead of %d (%d) !\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
%7 = alloca [512 x i8]
%8 = alloca [512 x i8]
%9 = alloca [512 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strcpy(i8* %17, i8* %20)
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i64 @atoi(i8* %24)
%26 = trunc i64 %25 to i32
store i32 %26, i32* %10
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 3
%29 = load i8*, i8** %28
%30 = call i64 @atoi(i8* %29)
%31 = trunc i64 %30 to i32
store i32 %31, i32* %11
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 4
%35 = load i8*, i8** %34
%36 = call i32 @strcpy(i8* %32, i8* %35)
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 5
%40 = load i8*, i8** %39
%41 = call i32 @strcpy(i8* %37, i8* %40)
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 6
%45 = load i8*, i8** %44
%46 = call i32 @strcpy(i8* %42, i8* %45)
%47 = load i32, i32* %10
%48 = load i32, i32* %11
%49 = mul nsw i32 %47, %48
%50 = sext i32 %49 to i64
%51 = mul i64 %50, 4
%52 = trunc i64 %51 to i32
%53 = call i64 @malloc(i32 %52)
%54 = inttoptr i64 %53 to i32*
store i32* %54, i32** %16
%55 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%56 = load i32, i32* %10
%57 = load i32, i32* %11
%58 = load i32*, i32** %16
%59 = call i32 @read_ancestrymap(i8* %55, i32 %56, i32 %57, i32* %58)
%60 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%61 = load i32, i32* %10
%62 = load i32, i32* %11
%63 = load i32*, i32** %16
%64 = call i32 @write_data_int(i8* %60, i32 %61, i32 %62, i32* %63)
%65 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%66 = call i32 @nb_ind_ancestrymap(i8* %65)
store i32 %66, i32* %12
%67 = load i32, i32* %12
%68 = load i32, i32* %10
%69 = icmp ne i32 %67, %68
br i1 %69, label %70, label %74
70: ; preds = %2
%71 = load i32, i32* %12
%72 = load i32, i32* %10
%73 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %71, i32 %72)
store i32 1, i32* %3
br label %111
74: ; preds = %2
%75 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%76 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%77 = call i32 @ancestrymap2geno(i8* %75, i8* %76, i32* %12, i32* %13)
%78 = load i32, i32* %10
%79 = load i32, i32* %12
%80 = icmp ne i32 %78, %79
br i1 %80, label %85, label %81
81: ; preds = %74
%82 = load i32, i32* %11
%83 = load i32, i32* %13
%84 = icmp ne i32 %82, %83
br i1 %84, label %85, label %91
85: ; preds = %81, %74
%86 = load i32, i32* %12
%87 = load i32, i32* %13
%88 = load i32, i32* %10
%89 = load i32, i32* %11
%90 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i32 %86, i32 %87, i32 %88, i32 %89)
store i32 1, i32* %3
br label %111
91: ; preds = %81
%92 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%93 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%94 = call i32 @ancestrymap2lfmm(i8* %92, i8* %93, i32* %14, i32* %15)
%95 = load i32, i32* %10
%96 = load i32, i32* %14
%97 = icmp ne i32 %95, %96
br i1 %97, label %102, label %98
98: ; preds = %91
%99 = load i32, i32* %11
%100 = load i32, i32* %15
%101 = icmp ne i32 %99, %100
br i1 %101, label %102, label %108
102: ; preds = %98, %91
%103 = load i32, i32* %14
%104 = load i32, i32* %15
%105 = load i32, i32* %10
%106 = load i32, i32* %11
%107 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i32 %103, i32 %104, i32 %105, i32 %106)
store i32 1, i32* %3
br label %111
108: ; preds = %98
%109 = load i32*, i32** %16
%110 = call i32 @free(i32* %109)
store i32 0, i32* %3
br label %111
111: ; preds = %108, %102, %85, %70
%112 = load i32, i32* %3
ret i32 %112
}

LLVM IR (-O2):
@.str = [53 x i8] c"Test ERROR: incorrect N detected, %d instead of %d!\0A\00"
@.str.1 = [69 x i8] c"Test ERROR: incorrect N or M detected, %d (%d) instead of %d (%d) !\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = alloca [512 x i8]
%5 = alloca [512 x i8]
%6 = alloca [512 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%15 = bitcast i32* %7 to i8*
%16 = bitcast i32* %8 to i8*
%17 = bitcast i32* %9 to i8*
%18 = bitcast i32* %10 to i8*
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strcpy(i8* %11, i8* %20)
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = call i64 @atoi(i8* %23)
%25 = trunc i64 %24 to i32
%26 = getelementptr inbounds i8*, i8** %1, i64 3
%27 = load i8*, i8** %26
%28 = call i64 @atoi(i8* %27)
%29 = trunc i64 %28 to i32
%30 = getelementptr inbounds i8*, i8** %1, i64 4
%31 = load i8*, i8** %30
%32 = call i32 @strcpy(i8* %12, i8* %31)
%33 = getelementptr inbounds i8*, i8** %1, i64 5
%34 = load i8*, i8** %33
%35 = call i32 @strcpy(i8* %13, i8* %34)
%36 = getelementptr inbounds i8*, i8** %1, i64 6
%37 = load i8*, i8** %36
%38 = call i32 @strcpy(i8* %14, i8* %37)
%39 = mul i64 %28, %24
%40 = trunc i64 %39 to i32
%41 = shl i32 %40, 2
%42 = call i64 @malloc(i32 %41)
%43 = inttoptr i64 %42 to i32*
%44 = call i32 @read_ancestrymap(i8* %11, i32 %25, i32 %29, i32* %43)
%45 = call i32 @write_data_int(i8* %12, i32 %25, i32 %29, i32* %43)
%46 = call i32 @nb_ind_ancestrymap(i8* %11)
store i32 %46, i32* %7
%47 = icmp eq i32 %46, %25
br i1 %47, label %50, label %48
48: ; preds = %2
%49 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %46, i32 %25)
br label %70
50: ; preds = %2
%51 = call i32 @ancestrymap2geno(i8* %11, i8* %13, i32* %7, i32* %8)
%52 = load i32, i32* %7
%53 = icmp eq i32 %52, %25
%54 = load i32, i32* %8
%55 = icmp eq i32 %54, %29
%56 = select i1 %53, i1 %55, i1 false
br i1 %56, label %59, label %57
57: ; preds = %50
%58 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i32 %52, i32 %54, i32 %25, i32 %29)
br label %70
59: ; preds = %50
%60 = call i32 @ancestrymap2lfmm(i8* %11, i8* %14, i32* %9, i32* %10)
%61 = load i32, i32* %9
%62 = icmp eq i32 %61, %25
%63 = load i32, i32* %10
%64 = icmp eq i32 %63, %29
%65 = select i1 %62, i1 %64, i1 false
br i1 %65, label %68, label %66
66: ; preds = %59
%67 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i32 %61, i32 %63, i32 %25, i32 %29)
br label %70
68: ; preds = %59
%69 = call i32 @free(i32* %43)
br label %70
70: ; preds = %68, %66, %57, %48
%71 = phi i32 [ 1, %48 ], [ 1, %57 ], [ 1, %66 ], [ 0, %68 ]
ret i32 %71
}