#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 get_gap_qual(int *);
int init_gap_qual_window(int *, char *, int);
int *malloc(int);
int /*<<< orphan*/ print_window(int *, int);
int /*<<< orphan*/ printf(char *, int, char);
int push_qual(int *, int, char *, int);
int strlen(char *);
void get_gap_quals(char *quals) {
  int seq_len = strlen(quals);
  int *window = malloc(sizeof(int) * 4 * 2);
  int win_edge = init_gap_qual_window(window, quals, seq_len);
  print_window(window, win_edge);
  int i;
  char gap_qual;
  for (i = 0; i < seq_len; i++) {
    if (quals[i] == ' ') {
      gap_qual = get_gap_qual(window);
      printf("gap %2d: %2d\n", i, gap_qual);
    } else {
      win_edge = push_qual(window, win_edge, quals, seq_len);
      print_window(window, win_edge);
    }
  }
}


x86 assembly (clang, -O0):
<get_gap_quals>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    $0x20,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <init_gap_qual_window@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <print_window@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1236 <get_gap_quals+0xc6>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    1201 <get_gap_quals+0x91>
mov    -0x18(%rbp),%rdi
call   1090 <get_gap_qual@plt>
mov    %al,-0x21(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe0d(%rip),%rdi
movsbl -0x21(%rbp),%edx
call   1050 <printf@plt>
jmp    1223 <get_gap_quals+0xb3>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
call   1080 <push_qual@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <print_window@plt>
jmp    1228 <get_gap_quals+0xb8>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11bc <get_gap_quals+0x4c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_gap_quals>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    $0x20,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <init_gap_qual_window@plt>
mov    %eax,%r12d
mov    %r15,%rdi
mov    %eax,%esi
call   1060 <print_window@plt>
test   %ebx,%ebx
jle    1204 <get_gap_quals+0x94>
mov    %ebx,%ebx
xor    %ebp,%ebp
lea    0xe45(%rip),%r13
jmp    11e6 <get_gap_quals+0x76>
nopl   (%rax)
mov    %r15,%rdi
mov    %r12d,%esi
mov    %r14,%rdx
mov    %ebx,%ecx
call   1080 <push_qual@plt>
mov    %eax,%r12d
mov    %r15,%rdi
mov    %eax,%esi
call   1060 <print_window@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
je     1204 <get_gap_quals+0x94>
cmpb   $0x20,(%r14,%rbp,1)
jne    11c0 <get_gap_quals+0x50>
mov    %r15,%rdi
call   1090 <get_gap_qual@plt>
movsbl %al,%edx
mov    %r13,%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
jmp    11dd <get_gap_quals+0x6d>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"gap %2d: %2d\0A\00"
define void @get_gap_quals(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %3
%10 = call i32* @malloc(i32 32)
store i32* %10, i32** %4
%11 = load i32*, i32** %4
%12 = load i8*, i8** %2
%13 = load i32, i32* %3
%14 = call i32 @init_gap_qual_window(i32* %11, i8* %12, i32 %13)
store i32 %14, i32* %5
%15 = load i32*, i32** %4
%16 = load i32, i32* %5
%17 = call i32 @print_window(i32* %15, i32 %16)
store i32 0, i32* %6
br label %18
18: ; preds = %46, %1
%19 = load i32, i32* %6
%20 = load i32, i32* %3
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %49
22: ; preds = %18
%23 = load i8*, i8** %2
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 32
br i1 %29, label %30, label %36
30: ; preds = %22
%31 = load i32*, i32** %4
%32 = call signext i8 @get_gap_qual(i32* %31)
store i8 %32, i8* %7
%33 = load i32, i32* %6
%34 = load i8, i8* %7
%35 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %33, i8 signext %34)
br label %45
36: ; preds = %22
%37 = load i32*, i32** %4
%38 = load i32, i32* %5
%39 = load i8*, i8** %2
%40 = load i32, i32* %3
%41 = call i32 @push_qual(i32* %37, i32 %38, i8* %39, i32 %40)
store i32 %41, i32* %5
%42 = load i32*, i32** %4
%43 = load i32, i32* %5
%44 = call i32 @print_window(i32* %42, i32 %43)
br label %45
45: ; preds = %36, %30
br label %46
46: ; preds = %45
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %18
49: ; preds = %18
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"gap %2d: %2d\0A\00"
define void @get_gap_quals(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32* @malloc(i32 32)
%4 = tail call i32 @init_gap_qual_window(i32* %3, i8* %0, i32 %2)
%5 = tail call i32 @print_window(i32* %3, i32 %4)
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %26
7: ; preds = %1
%8 = zext i32 %2 to i64
br label %9
9: ; preds = %7, %22
%10 = phi i64 [ 0, %7 ], [ %24, %22 ]
%11 = phi i32 [ %4, %7 ], [ %23, %22 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %10
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 32
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = tail call signext i8 @get_gap_qual(i32* %3)
%17 = trunc i64 %10 to i32
%18 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %17, i8 signext %16)
br label %22
19: ; preds = %9
%20 = tail call i32 @push_qual(i32* %3, i32 %11, i8* %0, i32 %2)
%21 = tail call i32 @print_window(i32* %3, i32 %20)
br label %22
22: ; preds = %15, %19
%23 = phi i32 [ %11, %15 ], [ %20, %19 ]
%24 = add nuw nsw i64 %10, 1
%25 = icmp eq i64 %24, %8
br i1 %25, label %26, label %9
26: ; preds = %22, %1
ret void
}