#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__ isprime1(int);
int /*<<< orphan*/ printf(char *, int, int, int);
int main(int argc, char *argv[]) {
  int i = 0, max = 500;
  int i6 = 0;
  int i7;
  while (1) {
    if (isprime1(i)) {
      i7 = i;
      i6++;
    }
    i++;
    if (i == max) {
      break;
    }
  }
  printf("N primes calculated to %d is %d\nlast is: %d\n", max, i6, i7);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1f4,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <isprime1@plt>
cmp    $0x0,%rax
je     116c <main+0x4c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    1186 <main+0x66>
jmp    118b <main+0x6b>
jmp    114b <main+0x2b>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1040 <isprime1@plt>
xor    %ecx,%ecx
test   %rax,%rax
cmovne %ebp,%r14d
setne  %cl
add    %ecx,%ebx
add    $0x1,%ebp
cmp    $0x1f4,%ebp
jne    1130 <main+0x10>
lea    0xea9(%rip),%rdi
mov    $0x1f4,%esi
mov    %ebx,%edx
mov    %r14d,%ecx
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [45 x i8] c"N primes calculated to %d is %d\0Alast is: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i32 [ 0, %2 ], [ %13, %3 ]
%5 = phi i32 [ 0, %2 ], [ %11, %3 ]
%6 = phi i32 [ undef, %2 ], [ %12, %3 ]
%7 = tail call i64 @isprime1(i32 %4)
%8 = icmp eq i64 %7, 0
%9 = xor i1 %8, true
%10 = zext i1 %9 to i32
%11 = add nuw nsw i32 %5, %10
%12 = select i1 %8, i32 %6, i32 %4
%13 = add nuw nsw i32 %4, 1
%14 = icmp eq i32 %13, 500
br i1 %14, label %15, label %3
15: ; preds = %3
%16 = tail call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 500, i32 %11, i32 %12)
ret i32 0
}