#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__ isPrime(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int main() {
  int i = 0;
  char str[80];
  for (int a = 1; a <= 30000000; a++) {
    if (isPrime(a)) {
      i++;
      continue;
    }
  }
  sprintf(str, "Found %d primes.\n", i);
  printf("%s", str);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0x64(%rbp)
cmpl   $0x1c9c380,-0x64(%rbp)
jg     118d <main+0x5d>
mov    -0x64(%rbp),%edi
call   1040 <isPrime@plt>
cmp    $0x0,%rax
je     117a <main+0x4a>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117f <main+0x4f>
jmp    117f <main+0x4f>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    114d <main+0x1d>
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe65(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x60(%rbp),%rsi
lea    0xe67(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
xor    %ebx,%ebx
mov    $0x1,%ebp
nopl   (%rax)
mov    %ebp,%edi
call   1040 <isPrime@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebx
add    $0x1,%ebp
cmp    $0x1c9c381,%ebp
jne    1140 <main+0x10>
lea    0xea0(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %ebx,%edx
call   1050 <sprintf@plt>
lea    0xe9e(%rip),%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Found %d primes.\0A\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [80 x i8]
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 1, i32* %4
br label %5
5: ; preds = %16, %0
%6 = load i32, i32* %4
%7 = icmp sle i32 %6, 30000000
br i1 %7, label %8, label %19
8: ; preds = %5
%9 = load i32, i32* %4
%10 = call i64 @isPrime(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* %2
%14 = add nsw i32 %13, 1
store i32 %14, i32* %2
br label %16
15: ; preds = %8
br label %16
16: ; preds = %15, %12
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %5
19: ; preds = %5
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%21 = load i32, i32* %2
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%24 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [18 x i8] c"Found %d primes.\0A\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
br label %6
3: ; preds = %6
%4 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %12)
%5 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
ret i32 0
6: ; preds = %0, %6
%7 = phi i32 [ 1, %0 ], [ %13, %6 ]
%8 = phi i32 [ 0, %0 ], [ %12, %6 ]
%9 = tail call i64 @isPrime(i32 %7)
%10 = icmp ne i64 %9, 0
%11 = zext i1 %10 to i32
%12 = add nuw nsw i32 %8, %11
%13 = add nuw nsw i32 %7, 1
%14 = icmp eq i32 %13, 30000001
br i1 %14, label %3, label %6
}