#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 *, int);
int /*<<< orphan*/ printf(char *, ...);
int test_prime(void) {
  const int m = 20;
  int prime[m];
  int count = 1;
  int i = 3;
  for (i = 0; i < m; i++)
    prime[i] = 2;
  i = 3;
  while (count < m) {
    if (isPrime(i, prime, count)) {
      prime[count++] = i;
    }
    i++;
  }
  for (i = 0; i < m; i++) {
    printf("%d\t", prime[i]);
    if ((i + 1) % 5 == 0)
      printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x14,-0x4(%rbp)
mov    %rsp,%rax
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x3,-0x18(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x14,-0x18(%rbp)
jge    116f <test_prime+0x4f>
movslq -0x18(%rbp),%rax
movl   $0x2,-0x70(%rbp,%rax,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114b <test_prime+0x2b>
movl   $0x3,-0x18(%rbp)
cmpl   $0x14,-0x14(%rbp)
jge    11bb <test_prime+0x9b>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%edx
lea    -0x70(%rbp),%rsi
call   1040 <isPrime@plt>
cmp    $0x0,%rax
je     11ad <test_prime+0x8d>
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
cltq
mov    %ecx,-0x70(%rbp,%rax,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1176 <test_prime+0x56>
movl   $0x0,-0x18(%rbp)
cmpl   $0x14,-0x18(%rbp)
jge    121a <test_prime+0xfa>
movslq -0x18(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%esi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1207 <test_prime+0xe7>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120c <test_prime+0xec>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c2 <test_prime+0xa2>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_prime>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
movaps 0xebd(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x40(%rsp)
mov    $0x1,%ebx
mov    $0x3,%ebp
mov    %rsp,%r14
jmp    1178 <test_prime+0x48>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0x14,%ebx
jge    1194 <test_prime+0x64>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <isPrime@plt>
test   %rax,%rax
je     1170 <test_prime+0x40>
movslq %ebx,%rax
add    $0x1,%ebx
mov    %ebp,(%rsp,%rax,4)
jmp    1170 <test_prime+0x40>
mov    $0x1,%bl
lea    0xe73(%rip),%r14
xor    %r15d,%r15d
jmp    11b9 <test_prime+0x89>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%bl
cmp    $0x14,%r15
je     11f2 <test_prime+0xc2>
mov    %r15,%r12
movzbl %bl,%eax
imul   $0xcd,%eax,%eax
shr    $0xa,%eax
lea    (%rax,%rax,4),%ebp
add    $0xff,%bpl
mov    (%rsp,%r15,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15
cmp    %r12b,%bpl
jne    11b0 <test_prime+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11b0 <test_prime+0x80>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\09\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @test_prime() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 20, i32* %1
%5 = call i8* @llvm.stacksave()
store i8* %5, i8** %2
%6 = alloca i32, i64 20
store i32 1, i32* %3
store i32 3, i32* %4
store i32 0, i32* %4
br label %7
7: ; preds = %14, %0
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 20
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %6, i64 %12
store i32 2, i32* %13
br label %14
14: ; preds = %10
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %7
17: ; preds = %7
store i32 3, i32* %4
br label %18
18: ; preds = %32, %17
%19 = load i32, i32* %3
%20 = icmp slt i32 %19, 20
br i1 %20, label %21, label %35
21: ; preds = %18
%22 = load i32, i32* %4
%23 = load i32, i32* %3
%24 = call i64 @isPrime(i32 %22, i32* %6, i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load i32, i32* %4
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i32, i32* %6, i64 %30
store i32 %27, i32* %31
br label %32
32: ; preds = %26, %21
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %18
35: ; preds = %18
store i32 0, i32* %4
br label %36
36: ; preds = %52, %35
%37 = load i32, i32* %4
%38 = icmp slt i32 %37, 20
br i1 %38, label %39, label %55
39: ; preds = %36
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %6, i64 %41
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %43)
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 1
%47 = srem i32 %46, 5
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %39
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %51
51: ; preds = %49, %39
br label %52
52: ; preds = %51
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
br label %36
55: ; preds = %36
%56 = load i8*, i8** %2
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\09\00"
define i32 @test_prime() {
%1 = alloca [20 x i32]
%2 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%3 = bitcast [20 x i32]* %1 to <4 x i32>*
store <4 x i32> <i32 2, i32 2, i32 2, i32 2>, <4 x i32>* %3
%4 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 4
%5 = bitcast i32* %4 to <4 x i32>*
store <4 x i32> <i32 2, i32 2, i32 2, i32 2>, <4 x i32>* %5
%6 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 8
%7 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> <i32 2, i32 2, i32 2, i32 2>, <4 x i32>* %7
%8 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 12
%9 = bitcast i32* %8 to <4 x i32>*
store <4 x i32> <i32 2, i32 2, i32 2, i32 2>, <4 x i32>* %9
%10 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 16
%11 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> <i32 2, i32 2, i32 2, i32 2>, <4 x i32>* %11
br label %12
12: ; preds = %0, %21
%13 = phi i32 [ %23, %21 ], [ 3, %0 ]
%14 = phi i32 [ %22, %21 ], [ 1, %0 ]
%15 = call i64 @isPrime(i32 %13, i32* %2, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %12
%18 = add nsw i32 %14, 1
%19 = sext i32 %14 to i64
%20 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %19
store i32 %13, i32* %20
br label %21
21: ; preds = %17, %12
%22 = phi i32 [ %18, %17 ], [ %14, %12 ]
%23 = add nuw nsw i32 %13, 1
%24 = icmp slt i32 %22, 20
br i1 %24, label %12, label %25
25: ; preds = %21, %36
%26 = phi i64 [ %30, %36 ], [ 0, %21 ]
%27 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = add nuw nsw i64 %26, 1
%31 = trunc i64 %30 to i8
%32 = urem i8 %31, 5
%33 = icmp eq i8 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %25
%35 = call i32 @putchar(i32 10)
br label %36
36: ; preds = %25, %34
%37 = icmp eq i64 %30, 20
br i1 %37, label %38, label %25
38: ; preds = %36
ret i32 0
}