why do you need this check? Iteration should only stop when bam_read1 returns 0.