#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 EOF;
int /*<<< orphan*/ assert(int);
int atoi(char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int getchar();
char *malloc(int);
int /*<<< orphan*/ print_clean_header(char *, int);
int /*<<< orphan*/ print_sequence(char *, int, int);
char *realloc(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int wrap_length = atoi(argv[1]);
  assert(wrap_length > 0);
  int c = 0;
  int line_idx = 0;
  int first_char = 1;
  int in_header = 0;
  int line_size = 10000;
  char *line = malloc(sizeof(char) * line_size);
  while ((c = getchar())) {
    if (line_idx >= line_size) {
      line_size *= 2;
      char *tmp = realloc(line, sizeof(char) * line_size);
      assert(tmp != NULL);
      line = tmp;
      assert(line != NULL);
    }
    if (first_char == 1) {
      if (c == '>') {
        first_char = 0;
        in_header = 1;
      } else {
        fputs("ERROR: data doesn't look like a fasta file!\n", stderr);
        return 1;
      }
    }
    if (c == EOF) {
      line[line_idx] = '\0';
      print_sequence(line, line_idx, wrap_length);
      free(line);
      return 0;
    }
    if (c == '\n' && in_header == 1) {
      line[line_idx] = '\0';
      print_clean_header(line, line_idx);
      in_header = 0;
      line_idx = 0;
    } else if (c == '>' && in_header == 0) {
      line[line_idx] = '\0';
      print_sequence(line, line_idx, wrap_length);
      in_header = 1;
      line[0] = '>';
      line_idx = 1;
    } else if (c != '\n') {
      line[line_idx] = c;
      line_idx += 1;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x2710,-0x28(%rbp)
movslq -0x28(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     13b1 <main+0x221>
mov    -0x1c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jl     1268 <main+0xd8>
mov    -0x28(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
movslq -0x28(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%esi
call   10a0 <realloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
cmpl   $0x1,-0x20(%rbp)
jne    12b5 <main+0x125>
cmpl   $0x3e,-0x18(%rbp)
jne    128f <main+0xff>
movl   $0x0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    12b0 <main+0x120>
mov    0x2d42(%rip),%rax
mov    (%rax),%esi
lea    0xd61(%rip),%rdi
call   1040 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    13b1 <main+0x221>
jmp    12b5 <main+0x125>
mov    -0x18(%rbp),%eax
mov    0x2d29(%rip),%rcx
cmp    (%rcx),%eax
jne    12f7 <main+0x167>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <print_sequence@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    13b1 <main+0x221>
cmpl   $0xa,-0x18(%rbp)
jne    1336 <main+0x1a6>
cmpl   $0x1,-0x24(%rbp)
jne    1336 <main+0x1a6>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <print_clean_header@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
jmp    13ac <main+0x21c>
cmpl   $0x3e,-0x18(%rbp)
jne    137f <main+0x1ef>
cmpl   $0x0,-0x24(%rbp)
jne    137f <main+0x1ef>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <print_sequence@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x3e,(%rax)
movl   $0x1,-0x1c(%rbp)
jmp    13a7 <main+0x217>
cmpl   $0xa,-0x18(%rbp)
je     13a2 <main+0x212>
mov    -0x18(%rbp),%eax
mov    %al,%dl
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    13a7 <main+0x217>
jmp    13ac <main+0x21c>
jmp    11fd <main+0x6d>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x8(%rsi),%rdi
call   10b0 <atoi@plt>
xor    %edi,%edi
mov    %eax,0x10(%rsp)
test   %eax,%eax
setg   %dil
call   1080 <assert@plt>
mov    $0x2710,%r14d
mov    $0x2710,%edi
call   1090 <malloc@plt>
mov    %rax,%r12
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <getchar@plt>
test   %eax,%eax
je     133a <main+0x1aa>
mov    %eax,%ebx
mov    $0x1,%bpl
movl   $0x0,0xc(%rsp)
mov    0x2df8(%rip),%r13
xor    %r15d,%r15d
jmp    1231 <main+0xa1>
cs nopw 0x0(%rax,%rax,1)
nop
movslq %r15d,%rax
movb   $0x0,(%r12,%rax,1)
mov    %r12,%rdi
mov    %r15d,%esi
call   1060 <print_clean_header@plt>
xor    %r15d,%r15d
movl   $0x0,0xc(%rsp)
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %eax,%ebx
test   %eax,%eax
je     133a <main+0x1aa>
cmp    %r14d,%r15d
jl     1277 <main+0xe7>
add    %r14d,%r14d
mov    %r12,%rdi
mov    %r14d,%esi
call   10a0 <realloc@plt>
mov    %rax,%r12
mov    %r15d,0x14(%rsp)
mov    %r13,%r15
mov    %r14d,%r13d
xor    %r14d,%r14d
test   %rax,%rax
setne  %r14b
mov    %r14d,%edi
call   1080 <assert@plt>
mov    %r14d,%edi
mov    %r13d,%r14d
mov    %r15,%r13
mov    0x14(%rsp),%r15d
call   1080 <assert@plt>
test   $0x1,%bpl
mov    0xc(%rsp),%eax
je     128f <main+0xff>
mov    $0x1,%eax
cmp    $0x3e,%ebx
jne    1320 <main+0x190>
cmp    0x0(%r13),%ebx
je     12fd <main+0x16d>
cmp    $0xa,%ebx
jne    12a3 <main+0x113>
cmp    $0x1,%eax
je     1200 <main+0x70>
cmp    $0x3e,%ebx
jne    12e0 <main+0x150>
test   %eax,%eax
jne    12e0 <main+0x150>
movslq %r15d,%rax
movb   $0x0,(%r12,%rax,1)
mov    %r12,%rdi
mov    %r15d,%esi
mov    0x10(%rsp),%edx
call   1050 <print_sequence@plt>
movb   $0x3e,(%r12)
mov    $0x1,%r15d
movl   $0x1,0xc(%rsp)
jmp    121e <main+0x8e>
nopl   0x0(%rax,%rax,1)
cmp    $0xa,%ebx
mov    %eax,0xc(%rsp)
je     121e <main+0x8e>
movslq %r15d,%rax
mov    %bl,(%r12,%rax,1)
add    $0x1,%r15d
jmp    121e <main+0x8e>
movslq %r15d,%rax
movb   $0x0,(%r12,%rax,1)
mov    %r12,%rdi
mov    %r15d,%esi
mov    0x10(%rsp),%edx
call   1050 <print_sequence@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
jmp    133a <main+0x1aa>
mov    0x2cb1(%rip),%rax
mov    (%rax),%esi
lea    0xcd0(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"ERROR: data doesn't look like a fasta file!\0A\00"
@stderr = global i32 0
@EOF = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp sgt i32 %18, 0
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
store i32 0, i32* %7
store i32 0, i32* %8
store i32 1, i32* %9
store i32 0, i32* %10
store i32 10000, i32* %11
%22 = load i32, i32* %11
%23 = sext i32 %22 to i64
%24 = mul i64 1, %23
%25 = trunc i64 %24 to i32
%26 = call i8* @malloc(i32 %25)
store i8* %26, i8** %12
br label %27
27: ; preds = %123, %2
%28 = call i32 (...) @getchar()
store i32 %28, i32* %7
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %124
30: ; preds = %27
%31 = load i32, i32* %8
%32 = load i32, i32* %11
%33 = icmp sge i32 %31, %32
br i1 %33, label %34, label %52
34: ; preds = %30
%35 = load i32, i32* %11
%36 = mul nsw i32 %35, 2
store i32 %36, i32* %11
%37 = load i8*, i8** %12
%38 = load i32, i32* %11
%39 = sext i32 %38 to i64
%40 = mul i64 1, %39
%41 = trunc i64 %40 to i32
%42 = call i8* @realloc(i8* %37, i32 %41)
store i8* %42, i8** %13
%43 = load i8*, i8** %13
%44 = icmp ne i8* %43, null
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = load i8*, i8** %13
store i8* %47, i8** %12
%48 = load i8*, i8** %12
%49 = icmp ne i8* %48, null
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
br label %52
52: ; preds = %34, %30
%53 = load i32, i32* %9
%54 = icmp eq i32 %53, 1
br i1 %54, label %55, label %63
55: ; preds = %52
%56 = load i32, i32* %7
%57 = icmp eq i32 %56, 62
br i1 %57, label %58, label %59
58: ; preds = %55
store i32 0, i32* %9
store i32 1, i32* %10
br label %62
59: ; preds = %55
%60 = load i32, i32* @stderr
%61 = call i32 @fputs(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %60)
store i32 1, i32* %3
br label %124
62: ; preds = %58
br label %63
63: ; preds = %62, %52
%64 = load i32, i32* %7
%65 = load i32, i32* @EOF
%66 = icmp eq i32 %64, %65
br i1 %66, label %67, label %78
67: ; preds = %63
%68 = load i8*, i8** %12
%69 = load i32, i32* %8
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
store i8 0, i8* %71
%72 = load i8*, i8** %12
%73 = load i32, i32* %8
%74 = load i32, i32* %6
%75 = call i32 @print_sequence(i8* %72, i32 %73, i32 %74)
%76 = load i8*, i8** %12
%77 = call i32 @free(i8* %76)
store i32 0, i32* %3
br label %124
78: ; preds = %63
%79 = load i32, i32* %7
%80 = icmp eq i32 %79, 10
br i1 %80, label %81, label %92
81: ; preds = %78
%82 = load i32, i32* %10
%83 = icmp eq i32 %82, 1
br i1 %83, label %84, label %92
84: ; preds = %81
%85 = load i8*, i8** %12
%86 = load i32, i32* %8
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8, i8* %85, i64 %87
store i8 0, i8* %88
%89 = load i8*, i8** %12
%90 = load i32, i32* %8
%91 = call i32 @print_clean_header(i8* %89, i32 %90)
store i32 0, i32* %10
store i32 0, i32* %8
br label %123
92: ; preds = %81, %78
%93 = load i32, i32* %7
%94 = icmp eq i32 %93, 62
br i1 %94, label %95, label %109
95: ; preds = %92
%96 = load i32, i32* %10
%97 = icmp eq i32 %96, 0
br i1 %97, label %98, label %109
98: ; preds = %95
%99 = load i8*, i8** %12
%100 = load i32, i32* %8
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i8, i8* %99, i64 %101
store i8 0, i8* %102
%103 = load i8*, i8** %12
%104 = load i32, i32* %8
%105 = load i32, i32* %6
%106 = call i32 @print_sequence(i8* %103, i32 %104, i32 %105)
store i32 1, i32* %10
%107 = load i8*, i8** %12
%108 = getelementptr inbounds i8, i8* %107, i64 0
store i8 62, i8* %108
store i32 1, i32* %8
br label %122
109: ; preds = %95, %92
%110 = load i32, i32* %7
%111 = icmp ne i32 %110, 10
br i1 %111, label %112, label %121
112: ; preds = %109
%113 = load i32, i32* %7
%114 = trunc i32 %113 to i8
%115 = load i8*, i8** %12
%116 = load i32, i32* %8
%117 = sext i32 %116 to i64
%118 = getelementptr inbounds i8, i8* %115, i64 %117
store i8 %114, i8* %118
%119 = load i32, i32* %8
%120 = add nsw i32 %119, 1
store i32 %120, i32* %8
br label %121
121: ; preds = %112, %109
br label %122
122: ; preds = %121, %98
br label %123
123: ; preds = %122, %84
br label %27
124: ; preds = %59, %67, %27
%125 = load i32, i32* %3
ret i32 %125
}

LLVM IR (-O2):
@.str = [45 x i8] c"ERROR: data doesn't look like a fasta file!\0A\00"
@stderr = global i32 0
@EOF = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @atoi(i8* %4)
%6 = icmp sgt i32 %5, 0
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call dereferenceable_or_null(10000) i8* @malloc(i32 10000)
%10 = tail call i32 (...) @getchar()
%11 = icmp eq i32 %10, 0
br i1 %11, label %71, label %12
12: ; preds = %2, %66
%13 = phi i32 [ %69, %66 ], [ %10, %2 ]
%14 = phi i8* [ %29, %66 ], [ %9, %2 ]
%15 = phi i32 [ %28, %66 ], [ 10000, %2 ]
%16 = phi i32 [ %68, %66 ], [ 0, %2 ]
%17 = phi i1 [ false, %66 ], [ true, %2 ]
%18 = phi i32 [ %67, %66 ], [ 0, %2 ]
%19 = icmp slt i32 %18, %15
br i1 %19, label %27, label %20
20: ; preds = %12
%21 = shl nsw i32 %15, 1
%22 = tail call i8* @realloc(i8* %14, i32 %21)
%23 = icmp ne i8* %22, null
%24 = zext i1 %23 to i32
%25 = tail call i32 @assert(i32 %24)
%26 = tail call i32 @assert(i32 %24)
br label %27
27: ; preds = %20, %12
%28 = phi i32 [ %21, %20 ], [ %15, %12 ]
%29 = phi i8* [ %22, %20 ], [ %14, %12 ]
br i1 %17, label %30, label %35
30: ; preds = %27
%31 = icmp eq i32 %13, 62
br i1 %31, label %35, label %32
32: ; preds = %30
%33 = load i32, i32* @stderr
%34 = tail call i32 @fputs(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %33)
br label %71
35: ; preds = %30, %27
%36 = phi i32 [ %16, %27 ], [ 1, %30 ]
%37 = load i32, i32* @EOF
%38 = icmp eq i32 %13, %37
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = sext i32 %18 to i64
%41 = getelementptr inbounds i8, i8* %29, i64 %40
store i8 0, i8* %41
%42 = tail call i32 @print_sequence(i8* %29, i32 %18, i32 %5)
%43 = tail call i32 @free(i8* %29)
br label %71
44: ; preds = %35
%45 = icmp eq i32 %13, 10
%46 = icmp eq i32 %36, 1
%47 = select i1 %45, i1 %46, i1 false
br i1 %47, label %48, label %52
48: ; preds = %44
%49 = sext i32 %18 to i64
%50 = getelementptr inbounds i8, i8* %29, i64 %49
store i8 0, i8* %50
%51 = tail call i32 @print_clean_header(i8* %29, i32 %18)
br label %66
52: ; preds = %44
%53 = icmp eq i32 %13, 62
%54 = icmp eq i32 %36, 0
%55 = select i1 %53, i1 %54, i1 false
br i1 %55, label %56, label %60
56: ; preds = %52
%57 = sext i32 %18 to i64
%58 = getelementptr inbounds i8, i8* %29, i64 %57
store i8 0, i8* %58
%59 = tail call i32 @print_sequence(i8* %29, i32 %18, i32 %5)
store i8 62, i8* %29
br label %66
60: ; preds = %52
br i1 %45, label %66, label %61
61: ; preds = %60
%62 = trunc i32 %13 to i8
%63 = sext i32 %18 to i64
%64 = getelementptr inbounds i8, i8* %29, i64 %63
store i8 %62, i8* %64
%65 = add nsw i32 %18, 1
br label %66
66: ; preds = %56, %61, %60, %48
%67 = phi i32 [ 0, %48 ], [ 1, %56 ], [ %65, %61 ], [ %18, %60 ]
%68 = phi i32 [ 0, %48 ], [ 1, %56 ], [ %36, %61 ], [ %36, %60 ]
%69 = tail call i32 (...) @getchar()
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %12
71: ; preds = %66, %2, %39, %32
%72 = phi i32 [ 0, %39 ], [ 1, %32 ], [ 0, %2 ], [ 0, %66 ]
ret i32 %72
}