#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen_read(char *);
int /*<<< orphan*/ read_line_ancestrymap(char *, int *, char *, int, int,
                                         char *, int *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ test_column(char *, int /*<<< orphan*/ *, int, int, int,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ test_line(char *, int /*<<< orphan*/ *, int, int);
void read_ancestrymap(char *input_file, int N, int M, int *data) {
  FILE *File = NULL;
  int i, j, allele;
  char tmp[512] = "";
  char ref[512] = "";
  int max_char_per_line = 1000;
  char szbuff[max_char_per_line];
  int warning = 0;
  File = fopen_read(input_file);
  j = 0;
  i = 0;
  while (fgets(szbuff, max_char_per_line, File) &&
         (j < M - 1 || (j == (M - 1) && i < N))) {
    read_line_ancestrymap(szbuff, &allele, tmp, i + 1, j + 1, input_file,
                          &warning);
    if (j == 0 && i == 0)
      strcpy(ref, tmp);
    if (strcmp(ref, tmp) != 0) {
      test_column(input_file, File, i, j + 1, N, NULL);
      i = 0;
      j++;
      strcpy(ref, tmp);
    }
    data[i * M + j] = allele;
    i++;
  }
  test_column(input_file, File, i, j + 1, N, NULL);
  test_line(input_file, File, j + 1, M);
  fclose(File);
}


x86 assembly (clang, -O0):
<read_ancestrymap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x230(%rbp),%rdi
xor    %esi,%esi
mov    %esi,-0x464(%rbp)
mov    $0x200,%edx
mov    %rdx,-0x460(%rbp)
call   1060 <memset@plt>
mov    -0x464(%rbp),%esi
mov    -0x460(%rbp),%rdx
lea    -0x430(%rbp),%rdi
call   1060 <memset@plt>
movl   $0x3e8,-0x434(%rbp)
mov    -0x434(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x440(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x458(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x448(%rbp)
movl   $0x0,-0x44c(%rbp)
mov    -0x8(%rbp),%rdi
call   10a0 <fopen_read@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x458(%rbp),%rdi
mov    -0x434(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1070 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x465(%rbp)
je     12cf <read_ancestrymap+0x13f>
mov    -0x28(%rbp),%ecx
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
mov    $0x1,%al
cmp    %edx,%ecx
mov    %al,-0x466(%rbp)
jl     12c3 <read_ancestrymap+0x133>
mov    -0x28(%rbp),%ecx
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x467(%rbp)
jne    12b7 <read_ancestrymap+0x127>
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
setl   %al
mov    %al,-0x467(%rbp)
mov    -0x467(%rbp),%al
mov    %al,-0x466(%rbp)
mov    -0x466(%rbp),%al
mov    %al,-0x465(%rbp)
mov    -0x465(%rbp),%al
test   $0x1,%al
jne    12e2 <read_ancestrymap+0x152>
jmp    13c9 <read_ancestrymap+0x239>
mov    -0x458(%rbp),%rdi
lea    -0x230(%rbp),%rdx
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    -0x28(%rbp),%r8d
add    $0x1,%r8d
mov    -0x8(%rbp),%r9
lea    -0x2c(%rbp),%rsi
lea    -0x44c(%rbp),%rax
sub    $0x10,%rsp
mov    %rax,(%rsp)
call   1050 <read_line_ancestrymap@plt>
add    $0x10,%rsp
cmpl   $0x0,-0x28(%rbp)
jne    1345 <read_ancestrymap+0x1b5>
cmpl   $0x0,-0x24(%rbp)
jne    1345 <read_ancestrymap+0x1b5>
lea    -0x430(%rbp),%rdi
lea    -0x230(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x430(%rbp),%rdi
lea    -0x230(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     13a4 <read_ancestrymap+0x214>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
mov    -0xc(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%r9d
call   1090 <test_column@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
lea    -0x430(%rbp),%rdi
lea    -0x230(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x2c(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x10(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    124b <read_ancestrymap+0xbb>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
mov    -0xc(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%r9d
call   1090 <test_column@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%ecx
call   10b0 <test_line@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x440(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_ancestrymap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x838,%rsp
mov    %rcx,0x48(%rsp)
mov    %rdx,0x20(%rsp)
mov    %esi,0x14(%rsp)
mov    %rdi,%rbp
lea    0x250(%rsp),%rdi
xor    %ebx,%ebx
mov    $0x200,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0x50(%rsp),%rdi
mov    $0x200,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    %rsp,0x40(%rsp)
movl   $0x0,0x38(%rsp)
mov    %rbp,0x28(%rsp)
mov    %rbp,%rdi
call   10a0 <fopen_read@plt>
lea    0x450(%rsp),%rdi
mov    $0x3e8,%esi
mov    %rax,0x18(%rsp)
mov    %rax,%rdx
call   1070 <fgets@plt>
mov    $0x0,%r14d
test   %rax,%rax
je     1340 <read_ancestrymap+0x1b0>
mov    0x20(%rsp),%rax
add    $0xffffffff,%eax
mov    %eax,0x34(%rsp)
xor    %r14d,%r14d
lea    0x250(%rsp),%r15
xor    %r12d,%r12d
jmp    12c8 <read_ancestrymap+0x138>
nopl   0x0(%rax,%rax,1)
lea    0x50(%rsp),%r13
mov    %r13,%rdi
mov    %r15,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1330 <read_ancestrymap+0x1a0>
mov    0x28(%rsp),%rdi
mov    0x18(%rsp),%rbp
mov    %rbp,%rsi
mov    %r14d,%edx
mov    %ebx,%ecx
mov    0x14(%rsp),%r8d
xor    %r9d,%r9d
call   1090 <test_column@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
xor    %r14d,%r14d
mov    0x3c(%rsp),%eax
mov    %r14d,%ecx
imul   0x20(%rsp),%ecx
add    %ebx,%ecx
movslq %ecx,%rcx
mov    0x48(%rsp),%rdx
mov    %eax,(%rdx,%rcx,4)
add    $0x1,%r14d
lea    0x450(%rsp),%rdi
mov    $0x3e8,%esi
mov    %rbp,%rdx
call   1070 <fgets@plt>
mov    %ebx,%r12d
test   %rax,%rax
lea    0x250(%rsp),%r15
je     1340 <read_ancestrymap+0x1b0>
cmp    0x34(%rsp),%r12d
jl     12d8 <read_ancestrymap+0x148>
jne    133d <read_ancestrymap+0x1ad>
cmp    0x14(%rsp),%r14d
jge    133d <read_ancestrymap+0x1ad>
lea    0x1(%r14),%ecx
lea    0x1(%r12),%r8d
lea    0x38(%rsp),%rax
mov    %rax,(%rsp)
lea    0x450(%rsp),%rdi
lea    0x3c(%rsp),%rsi
mov    %r15,%rdx
mov    %r8d,%ebx
mov    0x28(%rsp),%r9
call   1050 <read_line_ancestrymap@plt>
mov    %r12d,%eax
or     %r14d,%eax
jne    1240 <read_ancestrymap+0xb0>
lea    0x50(%rsp),%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
jmp    1240 <read_ancestrymap+0xb0>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12d,%ebx
mov    0x18(%rsp),%rbp
jmp    1286 <read_ancestrymap+0xf6>
mov    %r12d,%ebx
add    $0x1,%ebx
mov    0x28(%rsp),%r15
mov    %r15,%rdi
mov    0x18(%rsp),%rbp
mov    %rbp,%rsi
mov    %r14d,%edx
mov    %ebx,%ecx
mov    0x14(%rsp),%r8d
xor    %r9d,%r9d
call   1090 <test_column@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
mov    0x20(%rsp),%rcx
call   10b0 <test_line@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    0x40(%rsp),%rsp
add    $0x838,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @read_ancestrymap(i8* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [512 x i8]
%14 = alloca [512 x i8]
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
store i32* null, i32** %9
%19 = bitcast [512 x i8]* %13 to i8*
%20 = bitcast [512 x i8]* %14 to i8*
store i32 1000, i32* %15
%21 = load i32, i32* %15
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %16
%24 = alloca i8, i64 %22
store i64 %22, i64* %17
store i32 0, i32* %18
%25 = load i8*, i8** %5
%26 = call i32* @fopen_read(i8* %25)
store i32* %26, i32** %9
store i32 0, i32* %11
store i32 0, i32* %10
br label %27
27: ; preds = %87, %4
%28 = load i32, i32* %15
%29 = load i32*, i32** %9
%30 = call i64 @fgets(i8* %24, i32 %28, i32* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %50
32: ; preds = %27
%33 = load i32, i32* %11
%34 = load i32, i32* %7
%35 = sub nsw i32 %34, 1
%36 = icmp slt i32 %33, %35
br i1 %36, label %48, label %37
37: ; preds = %32
%38 = load i32, i32* %11
%39 = load i32, i32* %7
%40 = sub nsw i32 %39, 1
%41 = icmp eq i32 %38, %40
br i1 %41, label %42, label %46
42: ; preds = %37
%43 = load i32, i32* %10
%44 = load i32, i32* %6
%45 = icmp slt i32 %43, %44
br label %46
46: ; preds = %42, %37
%47 = phi i1 [ false, %37 ], [ %45, %42 ]
br label %48
48: ; preds = %46, %32
%49 = phi i1 [ true, %32 ], [ %47, %46 ]
br label %50
50: ; preds = %48, %27
%51 = phi i1 [ false, %27 ], [ %49, %48 ]
br i1 %51, label %52, label %99
52: ; preds = %50
%53 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
%56 = load i32, i32* %11
%57 = add nsw i32 %56, 1
%58 = load i8*, i8** %5
%59 = call i32 @read_line_ancestrymap(i8* %24, i32* %12, i8* %53, i32 %55, i32 %57, i8* %58, i32* %18)
%60 = load i32, i32* %11
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %69
62: ; preds = %52
%63 = load i32, i32* %10
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %62
%66 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%67 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%68 = call i32 @strcpy(i8* %66, i8* %67)
br label %69
69: ; preds = %65, %62, %52
%70 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%71 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%72 = call i64 @strcmp(i8* %70, i8* %71)
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %87
74: ; preds = %69
%75 = load i8*, i8** %5
%76 = load i32*, i32** %9
%77 = load i32, i32* %10
%78 = load i32, i32* %11
%79 = add nsw i32 %78, 1
%80 = load i32, i32* %6
%81 = call i32 @test_column(i8* %75, i32* %76, i32 %77, i32 %79, i32 %80, i32* null)
store i32 0, i32* %10
%82 = load i32, i32* %11
%83 = add nsw i32 %82, 1
store i32 %83, i32* %11
%84 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%85 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%86 = call i32 @strcpy(i8* %84, i8* %85)
br label %87
87: ; preds = %74, %69
%88 = load i32, i32* %12
%89 = load i32*, i32** %8
%90 = load i32, i32* %10
%91 = load i32, i32* %7
%92 = mul nsw i32 %90, %91
%93 = load i32, i32* %11
%94 = add nsw i32 %92, %93
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i32, i32* %89, i64 %95
store i32 %88, i32* %96
%97 = load i32, i32* %10
%98 = add nsw i32 %97, 1
store i32 %98, i32* %10
br label %27
99: ; preds = %50
%100 = load i8*, i8** %5
%101 = load i32*, i32** %9
%102 = load i32, i32* %10
%103 = load i32, i32* %11
%104 = add nsw i32 %103, 1
%105 = load i32, i32* %6
%106 = call i32 @test_column(i8* %100, i32* %101, i32 %102, i32 %104, i32 %105, i32* null)
%107 = load i8*, i8** %5
%108 = load i32*, i32** %9
%109 = load i32, i32* %11
%110 = add nsw i32 %109, 1
%111 = load i32, i32* %7
%112 = call i32 @test_line(i8* %107, i32* %108, i32 %110, i32 %111)
%113 = load i32*, i32** %9
%114 = call i32 @fclose(i32* %113)
%115 = load i8*, i8** %16
ret void
}

LLVM IR (-O2):
define void @read_ancestrymap(i8* %0, i32 %1, i32 %2, i32* nocapture writeonly %3) {
%5 = alloca i32
%6 = alloca [512 x i8]
%7 = alloca [512 x i8]
%8 = alloca i32
%9 = bitcast i32* %5 to i8*
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%12 = tail call i8* @llvm.stacksave()
%13 = alloca [1000 x i8]
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 0
%15 = bitcast i32* %8 to i8*
store i32 0, i32* %8
%16 = tail call i32* @fopen_read(i8* %0)
%17 = call i64 @fgets(i8* %14, i32 1000, i32* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %55, label %19
19: ; preds = %4
%20 = add nsw i32 %2, -1
br label %21
21: ; preds = %19, %44
%22 = phi i32 [ 0, %19 ], [ %52, %44 ]
%23 = phi i32 [ 0, %19 ], [ %45, %44 ]
%24 = icmp slt i32 %23, %20
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = icmp eq i32 %23, %20
%27 = icmp slt i32 %22, %1
%28 = select i1 %26, i1 %27, i1 false
br i1 %28, label %29, label %55
29: ; preds = %21, %25
%30 = add nsw i32 %22, 1
%31 = add nsw i32 %23, 1
%32 = call i32 @read_line_ancestrymap(i8* %14, i32* %5, i8* %10, i32 %30, i32 %31, i8* %0, i32* %8)
%33 = icmp eq i32 %23, 0
%34 = icmp eq i32 %22, 0
%35 = select i1 %33, i1 %34, i1 false
br i1 %35, label %36, label %38
36: ; preds = %29
%37 = call i32 @strcpy(i8* %11, i8* %10)
br label %38
38: ; preds = %36, %29
%39 = call i64 @strcmp(i8* %11, i8* %10)
%40 = icmp eq i64 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = call i32 @test_column(i8* %0, i32* %16, i32 %22, i32 %31, i32 %1, i32* null)
%43 = call i32 @strcpy(i8* %11, i8* %10)
br label %44
44: ; preds = %41, %38
%45 = phi i32 [ %31, %41 ], [ %23, %38 ]
%46 = phi i32 [ 0, %41 ], [ %22, %38 ]
%47 = load i32, i32* %5
%48 = mul nsw i32 %46, %2
%49 = add nsw i32 %48, %45
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i32, i32* %3, i64 %50
store i32 %47, i32* %51
%52 = add nsw i32 %46, 1
%53 = call i64 @fgets(i8* %14, i32 1000, i32* %16)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %21
55: ; preds = %25, %44, %4
%56 = phi i32 [ 0, %4 ], [ %45, %44 ], [ %23, %25 ]
%57 = phi i32 [ 0, %4 ], [ %52, %44 ], [ %22, %25 ]
%58 = add nsw i32 %56, 1
%59 = call i32 @test_column(i8* %0, i32* %16, i32 %57, i32 %58, i32 %1, i32* null)
%60 = call i32 @test_line(i8* %0, i32* %16, i32 %58, i32 %2)
%61 = call i32 @fclose(i32* %16)
ret void
}