#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
void read_and_store_kmers(char *filename, unsigned int *counts) {
  FILE *fp = fopen(filename, "r");
  char line[1024];
  char id[1024];
  int reading = 0;
  if (!fp) {
    printf("Error: can't open %s\n", filename);
    exit(1);
  }
  while (!feof(fp)) {
    if (fgets(line, 1024, fp)) {
      if (line[0] == '>') {
        int i = 1;
        while ((i < strlen(line)) && (line[i] > ' ')) {
          id[i - 1] = line[i];
          i++;
        }
        id[i - 1] = 0;
        printf("Got ID %s\n", id);
      }
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<read_and_store_kmers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x824(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c6 <read_and_store_kmers+0x56>
mov    -0x8(%rbp),%rsi
lea    0xe4b(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11cb <read_and_store_kmers+0x5b>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e9 <read_and_store_kmers+0x79>
jmp    12e4 <read_and_store_kmers+0x174>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12df <read_and_store_kmers+0x16f>
movsbl -0x420(%rbp),%eax
cmp    $0x3e,%eax
jne    12da <read_and_store_kmers+0x16a>
movl   $0x1,-0x828(%rbp)
mov    -0x828(%rbp),%eax
mov    %eax,-0x830(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x830(%rbp),%ecx
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x829(%rbp)
jge    126d <read_and_store_kmers+0xfd>
movslq -0x828(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
setg   %al
mov    %al,-0x829(%rbp)
mov    -0x829(%rbp),%al
test   $0x1,%al
jne    1280 <read_and_store_kmers+0x110>
jmp    12b4 <read_and_store_kmers+0x144>
movslq -0x828(%rbp),%rax
mov    -0x420(%rbp,%rax,1),%cl
mov    -0x828(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %cl,-0x820(%rbp,%rax,1)
mov    -0x828(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x828(%rbp)
jmp    1222 <read_and_store_kmers+0xb2>
mov    -0x828(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x820(%rbp,%rax,1)
lea    -0x820(%rbp),%rsi
lea    0xd43(%rip),%rdi
call   1050 <printf@plt>
jmp    12df <read_and_store_kmers+0x16f>
jmp    11cb <read_and_store_kmers+0x5b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_and_store_kmers>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    %rdi,%rbx
lea    0xe76(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1268 <read_and_store_kmers+0xf8>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11c0 <read_and_store_kmers+0x50>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0x400(%rsp),%r13
lea    0xe49(%rip),%r15
mov    %rsp,%r12
jmp    1201 <read_and_store_kmers+0x91>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffff,%ebx
movslq %ebx,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11a7 <read_and_store_kmers+0x37>
mov    %r13,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11f5 <read_and_store_kmers+0x85>
cmpb   $0x3e,0x400(%rsp)
3e
jne    11f5 <read_and_store_kmers+0x85>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    $0x1,%ebx
cmp    $0x2,%eax
jl     11e0 <read_and_store_kmers+0x70>
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
movzbl 0x400(%rsp,%rbx,1),%eax
cmp    $0x21,%al
jl     11e0 <read_and_store_kmers+0x70>
mov    %al,-0x1(%rsp,%rbx,1)
add    $0x1,%rbx
mov    %r13,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1240 <read_and_store_kmers+0xd0>
jmp    11e0 <read_and_store_kmers+0x70>
lea    0xd93(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"Error: can't open %s\0A\00"
@.str.2 = [11 x i8] c"Got ID %s\0A\00"
define void @read_and_store_kmers(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %5
store i32 0, i32* %8
%12 = load i32*, i32** %5
%13 = icmp ne i32* %12, null
br i1 %13, label %18, label %14
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
br label %19
19: ; preds = %68, %18
%20 = load i32*, i32** %5
%21 = call i32 @feof(i32* %20)
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br i1 %23, label %24, label %69
24: ; preds = %19
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = load i32*, i32** %5
%27 = call i64 @fgets(i8* %25, i32 1024, i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %68
29: ; preds = %24
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 62
br i1 %33, label %34, label %67
34: ; preds = %29
store i32 1, i32* %9
br label %35
35: ; preds = %49, %34
%36 = load i32, i32* %9
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%38 = call i32 @strlen(i8* %37)
%39 = icmp slt i32 %36, %38
br i1 %39, label %40, label %47
40: ; preds = %35
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp sgt i32 %45, 32
br label %47
47: ; preds = %40, %35
%48 = phi i1 [ false, %35 ], [ %46, %40 ]
br i1 %48, label %49, label %60
49: ; preds = %47
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = load i32, i32* %9
%55 = sub nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %56
store i8 %53, i8* %57
%58 = load i32, i32* %9
%59 = add nsw i32 %58, 1
store i32 %59, i32* %9
br label %35
60: ; preds = %47
%61 = load i32, i32* %9
%62 = sub nsw i32 %61, 1
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %63
store i8 0, i8* %64
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%66 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %65)
br label %67
67: ; preds = %60, %29
br label %68
68: ; preds = %67, %24
br label %19
69: ; preds = %19
%70 = load i32*, i32** %5
%71 = call i32 @fclose(i32* %70)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"Error: can't open %s\0A\00"
@.str.2 = [11 x i8] c"Got ID %s\0A\00"
define void @read_and_store_kmers(i8* %0, i32* nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = icmp eq i32* %5, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = call i32 @feof(i32* %5)
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %46
12: ; preds = %2
%13 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %9, %43
%16 = call i64 @fgets(i8* %6, i32 1024, i32* %5)
%17 = icmp ne i64 %16, 0
%18 = load i8, i8* %6
%19 = icmp eq i8 %18, 62
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %21, label %43
21: ; preds = %15
%22 = call i32 @strlen(i8* %6)
%23 = icmp sgt i32 %22, 1
br i1 %23, label %24, label %36
24: ; preds = %21, %29
%25 = phi i64 [ %32, %29 ], [ 1, %21 ]
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = icmp sgt i8 %27, 32
br i1 %28, label %29, label %36
29: ; preds = %24
%30 = add nsw i64 %25, -1
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %30
store i8 %27, i8* %31
%32 = add nuw nsw i64 %25, 1
%33 = call i32 @strlen(i8* %6)
%34 = sext i32 %33 to i64
%35 = icmp slt i64 %32, %34
br i1 %35, label %24, label %36
36: ; preds = %24, %29, %21
%37 = phi i64 [ 1, %21 ], [ %32, %29 ], [ %25, %24 ]
%38 = shl i64 %37, 32
%39 = add i64 %38, -4294967296
%40 = ashr exact i64 %39, 32
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %40
store i8 0, i8* %41
%42 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %7)
br label %43
43: ; preds = %36, %15
%44 = call i32 @feof(i32* %5)
%45 = icmp eq i32 %44, 0
br i1 %45, label %15, label %46
46: ; preds = %43, %9
%47 = call i32 @fclose(i32* %5)
ret void
}