#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 */
int /*<<< orphan*/ printf(char *);
int sqrt(int);
void isprime(int n) {
  static int d = 2;
  if (d <= sqrt(n)) {
    if (n % d == 0) {
      printf("Not a prime\n");
      return;
    } else {
      d++;
      isprime(n);
    }
  } else
    printf("Prime\n");
}


x86 assembly (clang, -O0):
<isprime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2ef7(%rip),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <sqrt@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%eax
cmp    %ecx,%eax
jg     1199 <isprime+0x69>
mov    -0x4(%rbp),%eax
cltd
idivl  0x2ed5(%rip)
cmp    $0x0,%edx
jne    117d <isprime+0x4d>
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
jmp    11a5 <isprime+0x75>
mov    0x2eb5(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2eac(%rip)
mov    -0x4(%rbp),%edi
call   1040 <isprime@plt>
jmp    11a5 <isprime+0x75>
lea    0xe6d(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isprime>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2f01(%rip),%ebx
call   1040 <sqrt@plt>
lea    0xec5(%rip),%r15
cmp    %eax,%ebx
jg     1178 <isprime+0x58>
lea    0xec0(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    0x2eda(%rip),%ebx
mov    %ebp,%eax
cltd
idiv   %ebx
test   %edx,%edx
je     1175 <isprime+0x55>
lea    0x1(%rbx),%eax
mov    %eax,0x2ec8(%rip)
mov    %ebp,%edi
call   1040 <sqrt@plt>
cmp    %eax,%ebx
jl     1150 <isprime+0x30>
jmp    1178 <isprime+0x58>
mov    %r14,%r15
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@isprime.d = internal global i32 2
@.str = [13 x i8] c"Not a prime\0A\00"
@.str.1 = [7 x i8] c"Prime\0A\00"
define void @isprime(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* @isprime.d
%4 = load i32, i32* %2
%5 = call i32 @sqrt(i32 %4)
%6 = icmp sle i32 %3, %5
br i1 %6, label %7, label %19
7: ; preds = %1
%8 = load i32, i32* %2
%9 = load i32, i32* @isprime.d
%10 = srem i32 %8, %9
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %21
14: ; preds = %7
%15 = load i32, i32* @isprime.d
%16 = add nsw i32 %15, 1
store i32 %16, i32* @isprime.d
%17 = load i32, i32* %2
br label %18
18: ; preds = %14
br label %21
19: ; preds = %1
%20 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %12, %19, %18
ret void
}

LLVM IR (-O2):
@isprime.d = internal unnamed_addr global i32 2
@str = [6 x i8] c"Prime\00"
@str.2 = [12 x i8] c"Not a prime\00"
define void @isprime(i32 %0) {
%2 = load i32, i32* @isprime.d
%3 = tail call i32 @sqrt(i32 %0)
%4 = icmp sgt i32 %2, %3
br i1 %4, label %13, label %5
5: ; preds = %1, %9
%6 = load i32, i32* @isprime.d
%7 = srem i32 %0, %6
%8 = icmp eq i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = add nsw i32 %6, 1
store i32 %10, i32* @isprime.d
%11 = tail call i32 @sqrt(i32 %0)
%12 = icmp slt i32 %6, %11
br i1 %12, label %5, label %13
13: ; preds = %9, %5, %1
%14 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @str.2, i64 0, i64 0), %5 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0), %9 ]
%15 = tail call i32 @puts(i8* dereferenceable(1) %14)
ret void
}