#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 main() {
  int i, j;
  int count;
  count = 0;
  for (i = 2; i <= 1000; i++) {
    if (is_prime(i)) {
      count++;
      printf("%4d", i);
      if (count % 10 == 0) {
        printf("\n");
      }
    }
  }
  printf("\nThere are %d prime numbers!\n", count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x2,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jg     11b0 <main+0x90>
mov    -0x8(%rbp),%edi
call   1040 <is_prime@plt>
cmp    $0x0,%rax
je     119d <main+0x7d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1198 <main+0x78>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119d <main+0x7d>
jmp    11a2 <main+0x82>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    113d <main+0x1d>
mov    -0x10(%rbp),%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x2,%ebp
lea    0xec0(%rip),%r14
xor    %ebx,%ebx
jmp    115b <main+0x2b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebp
cmp    $0x3e9,%ebp
je     1196 <main+0x66>
mov    %ebp,%edi
call   1050 <is_prime@plt>
test   %rax,%rax
je     1150 <main+0x20>
add    $0x1,%ebx
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
imul   $0xcccccccd,%ebx,%eax
add    $0x19999998,%eax
ror    %eax
cmp    $0x19999998,%eax
ja     1150 <main+0x20>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1150 <main+0x20>
lea    0xe67(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%4d\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [30 x i8] c"\0AThere are %d prime numbers!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
store i32 2, i32* %2
br label %5
5: ; preds = %24, %0
%6 = load i32, i32* %2
%7 = icmp sle i32 %6, 1000
br i1 %7, label %8, label %27
8: ; preds = %5
%9 = load i32, i32* %2
%10 = call i64 @is_prime(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %8
%13 = load i32, i32* %4
%14 = add nsw i32 %13, 1
store i32 %14, i32* %4
%15 = load i32, i32* %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %4
%18 = srem i32 %17, 10
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %12
br label %23
23: ; preds = %22, %8
br label %24
24: ; preds = %23
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %5
27: ; preds = %5
%28 = load i32, i32* %4
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%4d\00"
@.str.2 = [30 x i8] c"\0AThere are %d prime numbers!\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %13
%2 = phi i32 [ 0, %0 ], [ %14, %13 ]
%3 = phi i32 [ 2, %0 ], [ %15, %13 ]
%4 = tail call i64 @is_prime(i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %1
%7 = add nsw i32 %2, 1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %3)
%9 = srem i32 %7, 10
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @putchar(i32 10)
br label %13
13: ; preds = %1, %11, %6
%14 = phi i32 [ %7, %11 ], [ %7, %6 ], [ %2, %1 ]
%15 = add nuw nsw i32 %3, 1
%16 = icmp eq i32 %15, 1001
br i1 %16, label %17, label %1
17: ; preds = %13
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %14)
ret i32 0
}