#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 */
unsigned char aatoi(char);
int /*<<< orphan*/ exit(int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int strlen(char *);
scalar_t__ strstr(char *, char *);
int /*<<< orphan*/ trim_right(char *);
unsigned char *read_msa(FILE *f, int *ncol, int *nrow) {
  char buf[8192];
  int nc;
  *nrow = 0;
  *ncol = 0;
  while (fgets(buf, 8192, f)) {
    (*nrow)++;
    trim_right(buf);
    if (strstr(buf, ">")) {
      printf("ERROR: The alignment file seems to be in a3m or fasta "
             "format!\nPlease reformat the alignment to PSICOV format!\n\n");
      exit(100);
    }
    nc = strlen(buf);
    *ncol = nc > *ncol ? nc : *ncol;
  }
  unsigned char *out =
      (unsigned char *)malloc(sizeof(unsigned char) * (*ncol * *nrow));
  rewind(f);
  for (int i = 0; i < *nrow; i++) {
    fgets(buf, 8192, f);
    for (int j = 0; j < *ncol; j++) {
      out[i * *ncol + j] = aatoi(buf[j]);
    }
  }
  return out;
}


x86 assembly (clang, -O0):
<read_msa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2040,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
lea    -0x2020(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x2000,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     1276 <read_msa+0xe6>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
lea    -0x2020(%rbp),%rdi
call   1030 <trim_right@plt>
lea    -0x2020(%rbp),%rdi
lea    0xe01(%rip),%rsi
call   10b0 <strstr@plt>
cmp    $0x0,%rax
je     1224 <read_msa+0x94>
lea    0xded(%rip),%rdi
call   1050 <printf@plt>
mov    $0x64,%edi
call   10a0 <exit@plt>
lea    -0x2020(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2024(%rbp)
mov    -0x2024(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jle    1259 <read_msa+0xc9>
mov    -0x2024(%rbp),%eax
mov    %eax,-0x203c(%rbp)
jmp    1265 <read_msa+0xd5>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x203c(%rbp)
mov    -0x203c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    11bb <read_msa+0x2b>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
imul   (%rcx),%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x2030(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <rewind@plt>
movl   $0x0,-0x2034(%rbp)
mov    -0x2034(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    1350 <read_msa+0x1c0>
lea    -0x2020(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x2000,%esi
call   1080 <fgets@plt>
movl   $0x0,-0x2038(%rbp)
mov    -0x2038(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    1337 <read_msa+0x1a7>
movslq -0x2038(%rbp),%rax
movsbl -0x2020(%rbp,%rax,1),%edi
ff
call   1070 <aatoi@plt>
mov    %al,%dl
mov    -0x2030(%rbp),%rax
mov    -0x2034(%rbp),%ecx
mov    -0x10(%rbp),%rsi
imul   (%rsi),%ecx
add    -0x2038(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x2038(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2038(%rbp)
jmp    12db <read_msa+0x14b>
jmp    133c <read_msa+0x1ac>
mov    -0x2034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2034(%rbp)
jmp    12aa <read_msa+0x11a>
mov    -0x2030(%rbp),%rax
add    $0x2040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_msa>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2008,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
movl   $0x0,(%rdx)
movl   $0x0,(%rsi)
mov    %rsp,%rdi
mov    $0x2000,%esi
mov    %r15,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1226 <read_msa+0x96>
mov    %rsp,%r12
lea    0xe2b(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
addl   $0x1,(%r14)
mov    %r12,%rdi
call   1040 <trim_right@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
jne    12af <read_msa+0x11f>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    (%rbx),%ecx
cmp    %ecx,%eax
cmovg  %eax,%ecx
mov    %ecx,(%rbx)
mov    %r12,%rdi
mov    $0x2000,%esi
mov    %r15,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
jne    11e0 <read_msa+0x50>
mov    (%r14),%edi
imul   (%rbx),%edi
call   1090 <malloc@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1060 <rewind@plt>
cmpl   $0x0,(%r14)
jle    129a <read_msa+0x10a>
xor    %ebp,%ebp
jmp    1258 <read_msa+0xc8>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    (%r14),%ebp
jge    129a <read_msa+0x10a>
mov    %rsp,%rdi
mov    $0x2000,%esi
mov    %r15,%rdx
call   1080 <fgets@plt>
cmpl   $0x0,(%rbx)
jle    1250 <read_msa+0xc0>
xor    %r13d,%r13d
movsbl (%rsp,%r13,1),%edi
call   1070 <aatoi@plt>
movslq (%rbx),%rcx
movslq %ebp,%rdx
imul   %rcx,%rdx
add    %r12,%rdx
mov    %al,0x0(%r13,%rdx,1)
add    $0x1,%r13
movslq (%rbx),%rax
cmp    %rax,%r13
jl     1270 <read_msa+0xe0>
jmp    1250 <read_msa+0xc0>
mov    %r12,%rax
add    $0x2008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd4c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x64,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c">\00"
@.str.1 = [112 x i8] c"ERROR: The alignment file seems to be in a3m or fasta format!\0APlease reformat the alignment to PSICOV format!\0A\0A\00"
define i8* @read_msa(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [8192 x i8]
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%12 = load i32*, i32** %6
store i32 0, i32* %12
%13 = load i32*, i32** %5
store i32 0, i32* %13
br label %14
14: ; preds = %43, %3
%15 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%16 = load i32*, i32** %4
%17 = call i64 @fgets(i8* %15, i32 8192, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %46
19: ; preds = %14
%20 = load i32*, i32** %6
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1
store i32 %22, i32* %20
%23 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%24 = call i32 @trim_right(i8* %23)
%25 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%26 = call i64 @strstr(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %19
%29 = call i32 @printf(i8* getelementptr inbounds ([112 x i8], [112 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 100)
unreachable
31: ; preds = %19
%32 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = load i32*, i32** %5
%36 = load i32, i32* %35
%37 = icmp sgt i32 %34, %36
br i1 %37, label %38, label %40
38: ; preds = %31
%39 = load i32, i32* %8
br label %43
40: ; preds = %31
%41 = load i32*, i32** %5
%42 = load i32, i32* %41
br label %43
43: ; preds = %40, %38
%44 = phi i32 [ %39, %38 ], [ %42, %40 ]
%45 = load i32*, i32** %5
store i32 %44, i32* %45
br label %14
46: ; preds = %14
%47 = load i32*, i32** %5
%48 = load i32, i32* %47
%49 = load i32*, i32** %6
%50 = load i32, i32* %49
%51 = mul nsw i32 %48, %50
%52 = sext i32 %51 to i64
%53 = mul i64 1, %52
%54 = trunc i64 %53 to i32
%55 = call i64 @malloc(i32 %54)
%56 = inttoptr i64 %55 to i8*
store i8* %56, i8** %9
%57 = load i32*, i32** %4
%58 = call i32 @rewind(i32* %57)
store i32 0, i32* %10
br label %59
59: ; preds = %92, %46
%60 = load i32, i32* %10
%61 = load i32*, i32** %6
%62 = load i32, i32* %61
%63 = icmp slt i32 %60, %62
br i1 %63, label %64, label %95
64: ; preds = %59
%65 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%66 = load i32*, i32** %4
%67 = call i64 @fgets(i8* %65, i32 8192, i32* %66)
store i32 0, i32* %11
br label %68
68: ; preds = %88, %64
%69 = load i32, i32* %11
%70 = load i32*, i32** %5
%71 = load i32, i32* %70
%72 = icmp slt i32 %69, %71
br i1 %72, label %73, label %91
73: ; preds = %68
%74 = load i32, i32* %11
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 %75
%77 = load i8, i8* %76
%78 = call zeroext i8 @aatoi(i8 signext %77)
%79 = load i8*, i8** %9
%80 = load i32, i32* %10
%81 = load i32*, i32** %5
%82 = load i32, i32* %81
%83 = mul nsw i32 %80, %82
%84 = load i32, i32* %11
%85 = add nsw i32 %83, %84
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %79, i64 %86
store i8 %78, i8* %87
br label %88
88: ; preds = %73
%89 = load i32, i32* %11
%90 = add nsw i32 %89, 1
store i32 %90, i32* %11
br label %68
91: ; preds = %68
br label %92
92: ; preds = %91
%93 = load i32, i32* %10
%94 = add nsw i32 %93, 1
store i32 %94, i32* %10
br label %59
95: ; preds = %59
%96 = load i8*, i8** %9
ret i8* %96
}

LLVM IR (-O2):
@.str = [2 x i8] c">\00"
@str = [111 x i8] c"ERROR: The alignment file seems to be in a3m or fasta format!\0APlease reformat the alignment to PSICOV format!\0A\00"
define i8* @read_msa(i32* nocapture %0, i32* nocapture %1, i32* nocapture %2) {
%4 = alloca [8192 x i8]
%5 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
store i32 0, i32* %2
store i32 0, i32* %1
%6 = call i64 @fgets(i8* %5, i32 8192, i32* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %24, label %8
8: ; preds = %3, %17
%9 = load i32, i32* %2
%10 = add nsw i32 %9, 1
store i32 %10, i32* %2
%11 = call i32 @trim_right(i8* %5)
%12 = call i64 @strstr(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %8
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([111 x i8], [111 x i8]* @str, i64 0, i64 0))
%16 = call i32 @exit(i32 100)
unreachable
17: ; preds = %8
%18 = call i32 @strlen(i8* %5)
%19 = load i32, i32* %1
%20 = icmp sgt i32 %18, %19
%21 = select i1 %20, i32 %18, i32 %19
store i32 %21, i32* %1
%22 = call i64 @fgets(i8* %5, i32 8192, i32* %0)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %8
24: ; preds = %17, %3
%25 = load i32, i32* %1
%26 = load i32, i32* %2
%27 = mul nsw i32 %26, %25
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i8*
%30 = call i32 @rewind(i32* %0)
%31 = load i32, i32* %2
%32 = icmp sgt i32 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %39, %24
ret i8* %29
34: ; preds = %24, %39
%35 = phi i32 [ %40, %39 ], [ 0, %24 ]
%36 = call i64 @fgets(i8* %5, i32 8192, i32* %0)
%37 = load i32, i32* %1
%38 = icmp sgt i32 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %43, %34
%40 = add nuw nsw i32 %35, 1
%41 = load i32, i32* %2
%42 = icmp slt i32 %40, %41
br i1 %42, label %34, label %33
43: ; preds = %34, %43
%44 = phi i64 [ %54, %43 ], [ 0, %34 ]
%45 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = call zeroext i8 @aatoi(i8 signext %46)
%48 = load i32, i32* %1
%49 = mul nsw i32 %48, %35
%50 = trunc i64 %44 to i32
%51 = add nsw i32 %49, %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %29, i64 %52
store i8 %47, i8* %53
%54 = add nuw nsw i64 %44, 1
%55 = load i32, i32* %1
%56 = sext i32 %55 to i64
%57 = icmp slt i64 %54, %56
br i1 %57, label %43, label %39
}