#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 */
char *build_consensus(int **, int, int, double, int);
char *build_consensus_duplex(int **, int **, int, double);
char *build_consensus_duplex_simple(char *, char *, int);
int /*<<< orphan*/ free_votes(int **, int);
int **get_votes_qual(char **, char **, int, int, char);
int **get_votes_simple(char **, int, int);
char *rm_gaps(char *, int);
int /*<<< orphan*/ strncmp(char *, char *, int);
char *get_consensus_duplex(char *align1[], char *align2[], char *quals1[],
                           char *quals2[], int n_seqs1, int n_seqs2,
                           int seq_len, double cons_thres, int min_reads,
                           char qual_thres, int gapped, char *method) {
  if (cons_thres == -1.0) {
    cons_thres = 0.5;
  }
  int **votes1;
  int **votes2;
  if (quals1 == 0 || quals2 == 0) {
    votes1 = get_votes_simple(align1, n_seqs1, seq_len);
    votes2 = get_votes_simple(align2, n_seqs2, seq_len);
  } else {
    votes1 = get_votes_qual(align1, quals1, n_seqs1, seq_len, qual_thres);
    votes2 = get_votes_qual(align2, quals2, n_seqs2, seq_len, qual_thres);
  }
  char *consensus_gapped;
  if (!strncmp(method, "freq", 4)) {
    consensus_gapped =
        build_consensus_duplex(votes1, votes2, seq_len, cons_thres);
  } else if (!strncmp(method, "iupac", 5)) {
    char *cons1 =
        build_consensus(votes1, n_seqs1, seq_len, cons_thres, min_reads);
    char *cons2 =
        build_consensus(votes2, n_seqs2, seq_len, cons_thres, min_reads);
    consensus_gapped = build_consensus_duplex_simple(cons1, cons2, 1);
  } else {
    return "";
  }
  char *consensus;
  if (gapped) {
    consensus = consensus_gapped;
  } else {
    consensus = rm_gaps(consensus_gapped, seq_len);
  }
  free_votes(votes1, seq_len);
  free_votes(votes2, seq_len);
  return consensus;
}


x86 assembly (clang, -O0):
<get_consensus_duplex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x30(%rbp),%rax
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%al
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9d,-0x30(%rbp)
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe3e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11df <get_consensus_duplex+0x5f>
jp     11df <get_consensus_duplex+0x5f>
movsd  0xe2e(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f5 <get_consensus_duplex+0x75>
cmpq   $0x0,-0x28(%rbp)
jne    1220 <get_consensus_duplex+0xa0>
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    0x10(%rbp),%edx
call   1090 <get_votes_simple@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    0x10(%rbp),%edx
call   1090 <get_votes_simple@plt>
mov    %rax,-0x48(%rbp)
jmp    1258 <get_consensus_duplex+0xd8>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    0x10(%rbp),%ecx
movsbl 0x20(%rbp),%r8d
call   1030 <get_votes_qual@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%edx
mov    0x10(%rbp),%ecx
movsbl 0x20(%rbp),%r8d
call   1030 <get_votes_qual@plt>
mov    %rax,-0x48(%rbp)
mov    0x30(%rbp),%rdi
lea    0xdad(%rip),%rsi
mov    $0x4,%edx
call   1060 <strncmp@plt>
cmp    $0x0,%eax
jne    1294 <get_consensus_duplex+0x114>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    0x10(%rbp),%edx
movsd  -0x38(%rbp),%xmm0
call   1080 <build_consensus_duplex@plt>
mov    %rax,-0x50(%rbp)
jmp    1318 <get_consensus_duplex+0x198>
mov    0x30(%rbp),%rdi
lea    0xd76(%rip),%rsi
mov    $0x5,%edx
call   1060 <strncmp@plt>
cmp    $0x0,%eax
jne    1303 <get_consensus_duplex+0x183>
mov    -0x40(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    0x10(%rbp),%edx
movsd  -0x38(%rbp),%xmm0
mov    0x18(%rbp),%ecx
call   1050 <build_consensus@plt>
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    0x10(%rbp),%edx
movsd  -0x38(%rbp),%xmm0
mov    0x18(%rbp),%ecx
call   1050 <build_consensus@plt>
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    $0x1,%edx
call   10a0 <build_consensus_duplex_simple@plt>
mov    %rax,-0x50(%rbp)
jmp    1313 <get_consensus_duplex+0x193>
lea    0xd10(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    135f <get_consensus_duplex+0x1df>
jmp    1318 <get_consensus_duplex+0x198>
cmpl   $0x0,0x28(%rbp)
je     132f <get_consensus_duplex+0x1af>
mov    -0x50(%rbp),%rax
mov    %rax,-0x68(%rbp)
jmp    133f <get_consensus_duplex+0x1bf>
mov    -0x50(%rbp),%rdi
mov    0x10(%rbp),%esi
call   1070 <rm_gaps@plt>
mov    %rax,-0x68(%rbp)
mov    -0x40(%rbp),%rdi
mov    0x10(%rbp),%esi
call   1040 <free_votes@plt>
mov    -0x48(%rbp),%rdi
mov    0x10(%rbp),%esi
call   1040 <free_votes@plt>
mov    -0x68(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_consensus_duplex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%r12d
mov    %rsi,%r15
mov    0x80(%rsp),%rbp
mov    0x60(%rsp),%ebx
movsd  0xe58(%rip),%xmm2
cmpeqsd %xmm0,%xmm2
movsd  0xe53(%rip),%xmm1
andpd  %xmm2,%xmm1
andnpd %xmm0,%xmm2
orpd   %xmm1,%xmm2
movapd %xmm2,0x10(%rsp)
test   %rdx,%rdx
mov    %r8d,0xc(%rsp)
je     120b <get_consensus_duplex+0x8b>
mov    %rcx,%r13
test   %rcx,%rcx
je     120b <get_consensus_duplex+0x8b>
movsbl 0x70(%rsp),%r14d
mov    %rdx,%rsi
mov    %r8d,%edx
mov    %ebx,%ecx
mov    %r14d,%r8d
call   1030 <get_votes_qual@plt>
mov    %rax,(%rsp)
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r12d,%r15d
mov    %r12d,%edx
mov    %ebx,%ecx
mov    %r14d,%r8d
call   1030 <get_votes_qual@plt>
jmp    1229 <get_consensus_duplex+0xa9>
mov    %r8d,%esi
mov    %ebx,%edx
call   1090 <get_votes_simple@plt>
mov    %rax,(%rsp)
mov    %r15,%rdi
mov    %r12d,%r15d
mov    %r12d,%esi
mov    %ebx,%edx
call   1090 <get_votes_simple@plt>
mov    %rax,%r13
lea    0xddd(%rip),%rsi
mov    %rbp,%rdi
mov    $0x4,%edx
call   1060 <strncmp@plt>
test   %eax,%eax
je     1268 <get_consensus_duplex+0xe8>
lea    0xdca(%rip),%rsi
mov    %rbp,%rdi
mov    $0x5,%edx
call   1060 <strncmp@plt>
test   %eax,%eax
je     1281 <get_consensus_duplex+0x101>
lea    0xdb7(%rip),%rbp
jmp    12f4 <get_consensus_duplex+0x174>
mov    (%rsp),%r12
mov    %r12,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
movapd 0x10(%rsp),%xmm0
call   1080 <build_consensus_duplex@plt>
jmp    12c9 <get_consensus_duplex+0x149>
mov    0x68(%rsp),%r14d
mov    (%rsp),%r12
mov    %r12,%rdi
mov    0xc(%rsp),%esi
mov    %ebx,%edx
movaps 0x10(%rsp),%xmm0
mov    %r14d,%ecx
call   1050 <build_consensus@plt>
mov    %rax,%rbp
mov    %r13,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
movapd 0x10(%rsp),%xmm0
mov    %r14d,%ecx
call   1050 <build_consensus@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
mov    $0x1,%edx
call   10a0 <build_consensus_duplex_simple@plt>
mov    %rax,%rbp
cmpl   $0x0,0x78(%rsp)
jne    12e0 <get_consensus_duplex+0x160>
mov    %rbp,%rdi
mov    %ebx,%esi
call   1070 <rm_gaps@plt>
mov    %rax,%rbp
mov    %r12,%rdi
mov    %ebx,%esi
call   1040 <free_votes@plt>
mov    %r13,%rdi
mov    %ebx,%esi
call   1040 <free_votes@plt>
mov    %rbp,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"freq\00"
@.str.1 = [6 x i8] c"iupac\00"
@.str.2 = [1 x i8] zeroinitializer
define i8* @get_consensus_duplex(i8** %0, i8** %1, i8** %2, i8** %3, i32 %4, i32 %5, i32 %6, double %7, i32 %8, i8 signext %9, i32 %10, i8* %11) {
%13 = alloca i8*
%14 = alloca i8**
%15 = alloca i8**
%16 = alloca i8**
%17 = alloca i8**
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca double
%22 = alloca i32
%23 = alloca i8
%24 = alloca i32
%25 = alloca i8*
%26 = alloca i32**
%27 = alloca i32**
%28 = alloca i8*
%29 = alloca i8*
%30 = alloca i8*
%31 = alloca i8*
store i8** %0, i8*** %14
store i8** %1, i8*** %15
store i8** %2, i8*** %16
store i8** %3, i8*** %17
store i32 %4, i32* %18
store i32 %5, i32* %19
store i32 %6, i32* %20
store double %7, double* %21
store i32 %8, i32* %22
store i8 %9, i8* %23
store i32 %10, i32* %24
store i8* %11, i8** %25
%32 = load double, double* %21
%33 = fcmp oeq double %32, -1.000000e+00
br i1 %33, label %34, label %35
34: ; preds = %12
store double 5.000000e-01, double* %21
br label %35
35: ; preds = %34, %12
%36 = load i8**, i8*** %16
%37 = icmp eq i8** %36, null
br i1 %37, label %41, label %38
38: ; preds = %35
%39 = load i8**, i8*** %17
%40 = icmp eq i8** %39, null
br i1 %40, label %41, label %50
41: ; preds = %38, %35
%42 = load i8**, i8*** %14
%43 = load i32, i32* %18
%44 = load i32, i32* %20
%45 = call i32** @get_votes_simple(i8** %42, i32 %43, i32 %44)
store i32** %45, i32*** %26
%46 = load i8**, i8*** %15
%47 = load i32, i32* %19
%48 = load i32, i32* %20
%49 = call i32** @get_votes_simple(i8** %46, i32 %47, i32 %48)
store i32** %49, i32*** %27
br label %63
50: ; preds = %38
%51 = load i8**, i8*** %14
%52 = load i8**, i8*** %16
%53 = load i32, i32* %18
%54 = load i32, i32* %20
%55 = load i8, i8* %23
%56 = call i32** @get_votes_qual(i8** %51, i8** %52, i32 %53, i32 %54, i8 signext %55)
store i32** %56, i32*** %26
%57 = load i8**, i8*** %15
%58 = load i8**, i8*** %17
%59 = load i32, i32* %19
%60 = load i32, i32* %20
%61 = load i8, i8* %23
%62 = call i32** @get_votes_qual(i8** %57, i8** %58, i32 %59, i32 %60, i8 signext %61)
store i32** %62, i32*** %27
br label %63
63: ; preds = %50, %41
%64 = load i8*, i8** %25
%65 = call i32 @strncmp(i8* %64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%66 = icmp ne i32 %65, 0
br i1 %66, label %73, label %67
67: ; preds = %63
%68 = load i32**, i32*** %26
%69 = load i32**, i32*** %27
%70 = load i32, i32* %20
%71 = load double, double* %21
%72 = call i8* @build_consensus_duplex(i32** %68, i32** %69, i32 %70, double %71)
store i8* %72, i8** %28
br label %95
73: ; preds = %63
%74 = load i8*, i8** %25
%75 = call i32 @strncmp(i8* %74, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%76 = icmp ne i32 %75, 0
br i1 %76, label %93, label %77
77: ; preds = %73
%78 = load i32**, i32*** %26
%79 = load i32, i32* %18
%80 = load i32, i32* %20
%81 = load double, double* %21
%82 = load i32, i32* %22
%83 = call i8* @build_consensus(i32** %78, i32 %79, i32 %80, double %81, i32 %82)
store i8* %83, i8** %29
%84 = load i32**, i32*** %27
%85 = load i32, i32* %19
%86 = load i32, i32* %20
%87 = load double, double* %21
%88 = load i32, i32* %22
%89 = call i8* @build_consensus(i32** %84, i32 %85, i32 %86, double %87, i32 %88)
store i8* %89, i8** %30
%90 = load i8*, i8** %29
%91 = load i8*, i8** %30
%92 = call i8* @build_consensus_duplex_simple(i8* %90, i8* %91, i32 1)
store i8* %92, i8** %28
br label %94
93: ; preds = %73
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8** %13
br label %112
94: ; preds = %77
br label %95
95: ; preds = %94, %67
%96 = load i32, i32* %24
%97 = icmp ne i32 %96, 0
br i1 %97, label %98, label %100
98: ; preds = %95
%99 = load i8*, i8** %28
store i8* %99, i8** %31
br label %104
100: ; preds = %95
%101 = load i8*, i8** %28
%102 = load i32, i32* %20
%103 = call i8* @rm_gaps(i8* %101, i32 %102)
store i8* %103, i8** %31
br label %104
104: ; preds = %100, %98
%105 = load i32**, i32*** %26
%106 = load i32, i32* %20
%107 = call i32 @free_votes(i32** %105, i32 %106)
%108 = load i32**, i32*** %27
%109 = load i32, i32* %20
%110 = call i32 @free_votes(i32** %108, i32 %109)
%111 = load i8*, i8** %31
store i8* %111, i8** %13
br label %112
112: ; preds = %104, %93
%113 = load i8*, i8** %13
ret i8* %113
}

LLVM IR (-O2):
@.str = [5 x i8] c"freq\00"
@.str.1 = [6 x i8] c"iupac\00"
@.str.2 = [1 x i8] zeroinitializer
define i8* @get_consensus_duplex(i8** %0, i8** %1, i8** %2, i8** %3, i32 %4, i32 %5, i32 %6, double %7, i32 %8, i8 signext %9, i32 %10, i8* %11) {
%13 = fcmp oeq double %7, -1.000000e+00
%14 = select i1 %13, double 5.000000e-01, double %7
%15 = icmp eq i8** %2, null
%16 = icmp eq i8** %3, null
%17 = or i1 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = tail call i32** @get_votes_simple(i8** %0, i32 %4, i32 %6)
%20 = tail call i32** @get_votes_simple(i8** %1, i32 %5, i32 %6)
br label %24
21: ; preds = %12
%22 = tail call i32** @get_votes_qual(i8** %0, i8** %2, i32 %4, i32 %6, i8 signext %9)
%23 = tail call i32** @get_votes_qual(i8** %1, i8** %3, i32 %5, i32 %6, i8 signext %9)
br label %24
24: ; preds = %21, %18
%25 = phi i32** [ %19, %18 ], [ %22, %21 ]
%26 = phi i32** [ %20, %18 ], [ %23, %21 ]
%27 = tail call i32 @strncmp(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = tail call i8* @build_consensus_duplex(i32** %25, i32** %26, i32 %6, double %14)
br label %38
31: ; preds = %24
%32 = tail call i32 @strncmp(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %47
34: ; preds = %31
%35 = tail call i8* @build_consensus(i32** %25, i32 %4, i32 %6, double %14, i32 %8)
%36 = tail call i8* @build_consensus(i32** %26, i32 %5, i32 %6, double %14, i32 %8)
%37 = tail call i8* @build_consensus_duplex_simple(i8* %35, i8* %36, i32 1)
br label %38
38: ; preds = %34, %29
%39 = phi i8* [ %37, %34 ], [ %30, %29 ]
%40 = icmp eq i32 %10, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = tail call i8* @rm_gaps(i8* %39, i32 %6)
br label %43
43: ; preds = %38, %41
%44 = phi i8* [ %42, %41 ], [ %39, %38 ]
%45 = tail call i32 @free_votes(i32** %25, i32 %6)
%46 = tail call i32 @free_votes(i32** %26, i32 %6)
br label %47
47: ; preds = %31, %43
%48 = phi i8* [ %44, %43 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %31 ]
ret i8* %48
}