#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 */
scalar_t__ is_prime(int);
int /*<<< orphan*/ printf(char *, int, int);
void check_primes(int count) {
  int i, primes = 0;
  for (i = 1; i <= count; i++) {
    if (is_prime(i)) {
      primes++;
      printf("#%3i: %3i is prime.\n", primes, i);
    }
  }
}


x86 assembly (clang, -O0):
<check_primes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1185 <check_primes+0x65>
mov    -0x8(%rbp),%edi
call   1040 <is_prime@plt>
cmp    $0x0,%rax
je     1172 <check_primes+0x52>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
jmp    1177 <check_primes+0x57>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1139 <check_primes+0x19>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_primes>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
jle    1180 <check_primes+0x60>
mov    %edi,%r14d
neg    %r14d
mov    $0x1,%ebx
xor    %ebp,%ebp
lea    0xec1(%rip),%r15
jmp    1163 <check_primes+0x43>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r14,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
je     1180 <check_primes+0x60>
mov    %ebx,%edi
call   1040 <is_prime@plt>
test   %rax,%rax
je     1150 <check_primes+0x30>
add    $0x1,%ebp
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
jmp    1150 <check_primes+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"#%3i: %3i is prime.\0A\00"
define void @check_primes(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
store i32 1, i32* %3
br label %5
5: ; preds = %20, %1
%6 = load i32, i32* %3
%7 = load i32, i32* %2
%8 = icmp sle i32 %6, %7
br i1 %8, label %9, label %23
9: ; preds = %5
%10 = load i32, i32* %3
%11 = call i64 @is_prime(i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = load i32, i32* %3
%18 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %17)
br label %19
19: ; preds = %13, %9
br label %20
20: ; preds = %19
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
br label %5
23: ; preds = %5
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"#%3i: %3i is prime.\0A\00"
define void @check_primes(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %15, label %3
3: ; preds = %1, %11
%4 = phi i32 [ %12, %11 ], [ 0, %1 ]
%5 = phi i32 [ %13, %11 ], [ 1, %1 ]
%6 = tail call i64 @is_prime(i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = add nsw i32 %4, 1
%10 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %5)
br label %11
11: ; preds = %3, %8
%12 = phi i32 [ %9, %8 ], [ %4, %3 ]
%13 = add nuw i32 %5, 1
%14 = icmp eq i32 %5, %0
br i1 %14, label %15, label %3
15: ; preds = %11, %1
ret void
}