#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*/ print(int);
int /*<<< orphan*/ printf(char *, int);
void printprimes() {
  int i, count;
  i = 2;
  count = 0;
  while (i < 100) {
    if (isprime(i)) {
      print(i);
      count = count + 1;
    }
    i = i + 1;
  }
  printf("we found %d primes\n", count);
}


x86 assembly (clang, -O0):
<printprimes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x2,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x64,-0x4(%rbp)
jge    1181 <printprimes+0x51>
mov    -0x4(%rbp),%edi
call   1050 <isprime@plt>
cmp    $0x0,%rax
je     1173 <printprimes+0x43>
mov    -0x4(%rbp),%edi
call   1040 <print@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1146 <printprimes+0x16>
mov    -0x8(%rbp),%esi
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printprimes>:
push   %rbp
push   %rbx
push   %rax
mov    $0x2,%ebp
xor    %ebx,%ebx
jmp    1148 <printprimes+0x18>
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    $0x64,%ebp
je     1160 <printprimes+0x30>
mov    %ebp,%edi
call   1050 <isprime@plt>
test   %rax,%rax
je     1140 <printprimes+0x10>
mov    %ebp,%edi
call   1040 <print@plt>
add    $0x1,%ebx
jmp    1140 <printprimes+0x10>
lea    0xe99(%rip),%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"we found %d primes\0A\00"
define void @printprimes() {
%1 = alloca i32
%2 = alloca i32
store i32 2, i32* %1
store i32 0, i32* %2
br label %3
3: ; preds = %15, %0
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 100
br i1 %5, label %6, label %18
6: ; preds = %3
%7 = load i32, i32* %1
%8 = call i64 @isprime(i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = load i32, i32* %1
%12 = call i32 @print(i32 %11)
%13 = load i32, i32* %2
%14 = add nsw i32 %13, 1
store i32 %14, i32* %2
br label %15
15: ; preds = %10, %6
%16 = load i32, i32* %1
%17 = add nsw i32 %16, 1
store i32 %17, i32* %1
br label %3
18: ; preds = %3
%19 = load i32, i32* %2
%20 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %19)
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"we found %d primes\0A\00"
define void @printprimes() {
br label %1
1: ; preds = %0, %9
%2 = phi i32 [ 0, %0 ], [ %10, %9 ]
%3 = phi i32 [ 2, %0 ], [ %11, %9 ]
%4 = tail call i64 @isprime(i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = tail call i32 @print(i32 %3)
%8 = add nsw i32 %2, 1
br label %9
9: ; preds = %6, %1
%10 = phi i32 [ %8, %6 ], [ %2, %1 ]
%11 = add nuw nsw i32 %3, 1
%12 = icmp eq i32 %11, 100
br i1 %12, label %13, label %1
13: ; preds = %9
%14 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %10)
ret void
}