#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 clock_t;

/* Variables and functions */
int CLOCKS_PER_SEC;
int atoi(char *);
int clock();
int countSeqs(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int sample(int, int, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strdup(char *);
int main(int argc, char **argv) {
  int count, total, kept;
  char *infn, *outfn;
  clock_t start, middle, end;
  (void)argc;
  count = atoi(argv[1]);
  infn = strdup(argv[2]);
  outfn = strdup(argv[3]);
  start = clock();
  total = countSeqs(infn);
  middle = clock();
  fprintf(stderr, "count reads: %ld secs\n", (middle - start) / CLOCKS_PER_SEC);
  kept = sample(count, total, infn, outfn);
  end = clock();
  fprintf(stderr, "sample reads: %ld secs\n", (end - middle) / CLOCKS_PER_SEC);
  fprintf(stderr, "kept %d reads\n", kept);
  fprintf(stdout, "%d\t%d\n", total, kept);
  return 0;
}


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   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <countSeqs@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %eax,-0x38(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%eax
sub    -0x34(%rbp),%eax
mov    0x2e0a(%rip),%rcx
cltd
idivl  (%rcx)
mov    %eax,%edx
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1050 <sample@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %eax,-0x3c(%rbp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
mov    -0x3c(%rbp),%eax
sub    -0x38(%rbp),%eax
mov    0x2dc1(%rip),%rcx
cltd
idivl  (%rcx)
mov    %eax,%edx
lea    0xde4(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xdd4(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,0x4(%rsp)
mov    0x10(%rbx),%rdi
call   1080 <strdup@plt>
mov    %rax,%r13
mov    0x18(%rbx),%rdi
call   1080 <strdup@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1030 <clock@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1060 <countSeqs@plt>
mov    %eax,%r12d
xor    %eax,%eax
call   1030 <clock@plt>
mov    %eax,%ebx
mov    0x2e21(%rip),%r14
mov    (%r14),%edi
sub    %ebp,%eax
mov    0x2e25(%rip),%rcx
cltd
idivl  (%rcx)
lea    0xe33(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x4(%rsp),%edi
mov    %r12d,%esi
mov    %r13,%rdx
mov    %r15,%rcx
call   1050 <sample@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <clock@plt>
mov    (%r14),%edi
sub    %ebx,%eax
cltd
mov    0x2dea(%rip),%rcx
idivl  (%rcx)
lea    0xe10(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
lea    0xe15(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
mov    %r12d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"count reads: %ld secs\0A\00"
@CLOCKS_PER_SEC = global i32 0
@.str.1 = [24 x i8] c"sample reads: %ld secs\0A\00"
@.str.2 = [15 x i8] c"kept %d reads\0A\00"
@stdout = global i32 0
@.str.3 = [7 x i8] c"%d\09%d\0A\00"
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 i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i8* @strdup(i8* %21)
store i8* %22, i8** %9
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 3
%25 = load i8*, i8** %24
%26 = call i8* @strdup(i8* %25)
store i8* %26, i8** %10
%27 = call i32 (...) @clock()
store i32 %27, i32* %11
%28 = load i8*, i8** %9
%29 = call i32 @countSeqs(i8* %28)
store i32 %29, i32* %7
%30 = call i32 (...) @clock()
store i32 %30, i32* %12
%31 = load i32, i32* @stderr
%32 = load i32, i32* %12
%33 = load i32, i32* %11
%34 = sub nsw i32 %32, %33
%35 = load i32, i32* @CLOCKS_PER_SEC
%36 = sdiv i32 %34, %35
%37 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %6
%39 = load i32, i32* %7
%40 = load i8*, i8** %9
%41 = load i8*, i8** %10
%42 = call i32 @sample(i32 %38, i32 %39, i8* %40, i8* %41)
store i32 %42, i32* %8
%43 = call i32 (...) @clock()
store i32 %43, i32* %13
%44 = load i32, i32* @stderr
%45 = load i32, i32* %13
%46 = load i32, i32* %12
%47 = sub nsw i32 %45, %46
%48 = load i32, i32* @CLOCKS_PER_SEC
%49 = sdiv i32 %47, %48
%50 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %49)
%51 = load i32, i32* @stderr
%52 = load i32, i32* %8
%53 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %52)
%54 = load i32, i32* @stdout
%55 = load i32, i32* %7
%56 = load i32, i32* %8
%57 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %55, i32 %56)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"count reads: %ld secs\0A\00"
@CLOCKS_PER_SEC = global i32 0
@.str.1 = [24 x i8] c"sample reads: %ld secs\0A\00"
@.str.2 = [15 x i8] c"kept %d reads\0A\00"
@stdout = global i32 0
@.str.3 = [7 x i8] c"%d\09%d\0A\00"
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 = getelementptr inbounds i8*, i8** %1, i64 2
%7 = load i8*, i8** %6
%8 = tail call i8* @strdup(i8* %7)
%9 = getelementptr inbounds i8*, i8** %1, i64 3
%10 = load i8*, i8** %9
%11 = tail call i8* @strdup(i8* %10)
%12 = tail call i32 (...) @clock()
%13 = tail call i32 @countSeqs(i8* %8)
%14 = tail call i32 (...) @clock()
%15 = load i32, i32* @stderr
%16 = sub nsw i32 %14, %12
%17 = load i32, i32* @CLOCKS_PER_SEC
%18 = sdiv i32 %16, %17
%19 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = tail call i32 @sample(i32 %5, i32 %13, i8* %8, i8* %11)
%21 = tail call i32 (...) @clock()
%22 = load i32, i32* @stderr
%23 = sub nsw i32 %21, %14
%24 = load i32, i32* @CLOCKS_PER_SEC
%25 = sdiv i32 %23, %24
%26 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%29 = load i32, i32* @stdout
%30 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 %20)
ret i32 0
}