#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*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
void create_fasta_of_snp_sites(char filename[], int number_of_snps,
                               char **bases_for_snps, char **sequence_names,
                               int number_of_samples, int output_reference,
                               char *pseudo_reference_sequence,
                               int snp_locations[]) {
  FILE *fasta_file_pointer;
  int sample_counter;
  int snp_counter;
  fasta_file_pointer = fopen(filename, "w");
  if (output_reference == 1) {
    fprintf(fasta_file_pointer, ">pseudo_reference_sequence\n");
    for (snp_counter = 0; snp_counter < number_of_snps; snp_counter++) {
      fputc(pseudo_reference_sequence[snp_locations[snp_counter]],
            fasta_file_pointer);
    }
    fprintf(fasta_file_pointer, "\n");
  }
  for (sample_counter = 0; sample_counter < number_of_samples;
       sample_counter++) {
    fprintf(fasta_file_pointer, ">%s\n", sequence_names[sample_counter]);
    for (snp_counter = 0; snp_counter < number_of_snps; snp_counter++) {
      fputc(bases_for_snps[snp_counter][sample_counter], fasta_file_pointer);
    }
    fprintf(fasta_file_pointer, "\n");
  }
  fclose(fasta_file_pointer);
}


x86 assembly (clang, -O0):
<create_fasta_of_snp_sites>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x1,-0x28(%rbp)
jne    11e9 <create_fasta_of_snp_sites+0xa9>
mov    -0x30(%rbp),%rdi
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d7 <create_fasta_of_snp_sites+0x97>
mov    0x10(%rbp),%rax
mov    0x18(%rbp),%rcx
movslq -0x38(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x30(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    119e <create_fasta_of_snp_sites+0x5e>
mov    -0x30(%rbp),%rdi
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    127a <create_fasta_of_snp_sites+0x13a>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    125a <create_fasta_of_snp_sites+0x11a>
mov    -0x18(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x30(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1221 <create_fasta_of_snp_sites+0xe1>
mov    -0x30(%rbp),%rdi
lea    0xdb7(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11f0 <create_fasta_of_snp_sites+0xb0>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_fasta_of_snp_sites>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%r12d
mov    %r8d,%r15d
mov    %rcx,0x10(%rsp)
mov    %rdx,%rbx
mov    %esi,0x8(%rsp)
mov    0x58(%rsp),%r14
mov    0x50(%rsp),%r13
lea    0xe7f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbp
cmp    $0x1,%r12d
jne    11ed <create_fasta_of_snp_sites+0x9d>
mov    %r15d,0xc(%rsp)
lea    0xe67(%rip),%rdi
mov    $0x1b,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1070 <fwrite@plt>
cmpl   $0x0,0x8(%rsp)
jle    11db <create_fasta_of_snp_sites+0x8b>
mov    %r14,%r15
mov    0x8(%rsp),%r14d
xor    %r12d,%r12d
nop
movslq (%r15,%r12,4),%rax
movsbl 0x0(%r13,%rax,1),%edi
mov    %rbp,%rsi
call   1040 <fputc@plt>
add    $0x1,%r12
cmp    %r12,%r14
jne    11c0 <create_fasta_of_snp_sites+0x70>
mov    $0xa,%edi
mov    %rbp,%rsi
call   1040 <fputc@plt>
mov    0xc(%rsp),%r15d
test   %r15d,%r15d
jle    125c <create_fasta_of_snp_sites+0x10c>
mov    %r15d,%r13d
mov    0x8(%rsp),%r12d
xor    %r14d,%r14d
jmp    1216 <create_fasta_of_snp_sites+0xc6>
nop
mov    $0xa,%edi
mov    %rbp,%rsi
call   1040 <fputc@plt>
add    $0x1,%r14
cmp    %r13,%r14
je     125c <create_fasta_of_snp_sites+0x10c>
mov    0x10(%rsp),%rax
mov    (%rax,%r14,8),%rdx
mov    %rbp,%rdi
lea    0xdf5(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
cmpl   $0x0,0x8(%rsp)
jle    1200 <create_fasta_of_snp_sites+0xb0>
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    (%rbx,%r15,8),%rax
movsbl (%rax,%r14,1),%edi
mov    %rbp,%rsi
call   1040 <fputc@plt>
add    $0x1,%r15
cmp    %r15,%r12
jne    1240 <create_fasta_of_snp_sites+0xf0>
jmp    1200 <create_fasta_of_snp_sites+0xb0>
mov    %rbp,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [28 x i8] c">pseudo_reference_sequence\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [5 x i8] c">%s\0A\00"
define void @create_fasta_of_snp_sites(i8* %0, i32 %1, i8** %2, i8** %3, i32 %4, i32 %5, i8* %6, i32* %7) {
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8**
%12 = alloca i8**
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i32
%19 = alloca i32
store i8* %0, i8** %9
store i32 %1, i32* %10
store i8** %2, i8*** %11
store i8** %3, i8*** %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i8* %6, i8** %15
store i32* %7, i32** %16
%20 = load i8*, i8** %9
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %17
%22 = load i32, i32* %14
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %49
24: ; preds = %8
%25 = load i32*, i32** %17
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %19
br label %27
27: ; preds = %43, %24
%28 = load i32, i32* %19
%29 = load i32, i32* %10
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %46
31: ; preds = %27
%32 = load i8*, i8** %15
%33 = load i32*, i32** %16
%34 = load i32, i32* %19
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %32, i64 %38
%40 = load i8, i8* %39
%41 = load i32*, i32** %17
%42 = call i32 @fputc(i8 signext %40, i32* %41)
br label %43
43: ; preds = %31
%44 = load i32, i32* %19
%45 = add nsw i32 %44, 1
store i32 %45, i32* %19
br label %27
46: ; preds = %27
%47 = load i32*, i32** %17
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %49
49: ; preds = %46, %8
store i32 0, i32* %18
br label %50
50: ; preds = %84, %49
%51 = load i32, i32* %18
%52 = load i32, i32* %13
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %87
54: ; preds = %50
%55 = load i32*, i32** %17
%56 = load i8**, i8*** %12
%57 = load i32, i32* %18
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %56, i64 %58
%60 = load i8*, i8** %59
%61 = call i32 (i32*, i8*, ...) @fprintf(i32* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %60)
store i32 0, i32* %19
br label %62
62: ; preds = %78, %54
%63 = load i32, i32* %19
%64 = load i32, i32* %10
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %81
66: ; preds = %62
%67 = load i8**, i8*** %11
%68 = load i32, i32* %19
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8*, i8** %67, i64 %69
%71 = load i8*, i8** %70
%72 = load i32, i32* %18
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %71, i64 %73
%75 = load i8, i8* %74
%76 = load i32*, i32** %17
%77 = call i32 @fputc(i8 signext %75, i32* %76)
br label %78
78: ; preds = %66
%79 = load i32, i32* %19
%80 = add nsw i32 %79, 1
store i32 %80, i32* %19
br label %62
81: ; preds = %62
%82 = load i32*, i32** %17
%83 = call i32 (i32*, i8*, ...) @fprintf(i32* %82, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %84
84: ; preds = %81
%85 = load i32, i32* %18
%86 = add nsw i32 %85, 1
store i32 %86, i32* %18
br label %50
87: ; preds = %50
%88 = load i32*, i32** %17
%89 = call i32 @fclose(i32* %88)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [28 x i8] c">pseudo_reference_sequence\0A\00"
@.str.3 = [5 x i8] c">%s\0A\00"
define void @create_fasta_of_snp_sites(i8* nocapture %0, i32 %1, i8** nocapture %2, i8** nocapture %3, i32 %4, i32 %5, i8* nocapture %6, i32* nocapture %7) {
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %5, 1
br i1 %10, label %11, label %28
11: ; preds = %8
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i64 27, i64 1, i32* %9)
%13 = icmp sgt i32 %1, 0
br i1 %13, label %14, label %26
14: ; preds = %11
%15 = zext i32 %1 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 0, %14 ], [ %24, %16 ]
%18 = getelementptr inbounds i32, i32* %7, i64 %17
%19 = load i32, i32* %18
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %6, i64 %20
%22 = load i8, i8* %21
%23 = tail call i32 @fputc(i8 signext %22, i32* %9)
%24 = add nuw nsw i64 %17, 1
%25 = icmp eq i64 %24, %15
br i1 %25, label %26, label %16
26: ; preds = %16, %11
%27 = tail call i32 bitcast (i32 (i8, i32*)* @fputc to i32 (i32, i32*)*)(i32 10, i32* %9)
br label %28
28: ; preds = %26, %8
%29 = icmp sgt i32 %4, 0
br i1 %29, label %30, label %52
30: ; preds = %28
%31 = icmp sgt i32 %1, 0
%32 = zext i32 %4 to i64
%33 = zext i32 %1 to i64
br label %34
34: ; preds = %30, %48
%35 = phi i64 [ 0, %30 ], [ %50, %48 ]
%36 = getelementptr inbounds i8*, i8** %3, i64 %35
%37 = load i8*, i8** %36
%38 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %37)
br i1 %31, label %39, label %48
39: ; preds = %34, %39
%40 = phi i64 [ %46, %39 ], [ 0, %34 ]
%41 = getelementptr inbounds i8*, i8** %2, i64 %40
%42 = load i8*, i8** %41
%43 = getelementptr inbounds i8, i8* %42, i64 %35
%44 = load i8, i8* %43
%45 = tail call i32 @fputc(i8 signext %44, i32* %9)
%46 = add nuw nsw i64 %40, 1
%47 = icmp eq i64 %46, %33
br i1 %47, label %48, label %39
48: ; preds = %39, %34
%49 = tail call i32 bitcast (i32 (i8, i32*)* @fputc to i32 (i32, i32*)*)(i32 10, i32* %9)
%50 = add nuw nsw i64 %35, 1
%51 = icmp eq i64 %50, %32
br i1 %51, label %52, label %34
52: ; preds = %48, %28
%53 = tail call i32 @fclose(i32* %9)
ret void
}