#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 sqrt(int);
int frequency_of_primes(int n) {
  int i, j;
  int freq = n - 1;
  for (i = 2; i <= n; ++i)
    for (j = sqrt(i); j > 1; --j)
      if (i % j == 0) {
        --freq;
        break;
      }
  return freq;
}


x86 assembly (clang, -O0):
<frequency_of_primes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1190 <frequency_of_primes+0x80>
mov    -0x8(%rbp),%edi
call   1030 <sqrt@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jle    117d <frequency_of_primes+0x6d>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    116a <frequency_of_primes+0x5a>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    117d <frequency_of_primes+0x6d>
jmp    116f <frequency_of_primes+0x5f>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1142 <frequency_of_primes+0x32>
jmp    1182 <frequency_of_primes+0x72>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    112b <frequency_of_primes+0x1b>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<frequency_of_primes>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
lea    -0x1(%rbx),%r14d
cmp    $0x2,%edi
jge    1127 <frequency_of_primes+0x17>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0x2,%ebp
jmp    113d <frequency_of_primes+0x2d>
xchg   %ax,%ax
add    $0xffffffff,%r14d
lea    0x1(%rbp),%eax
cmp    %ebx,%ebp
mov    %eax,%ebp
je     111f <frequency_of_primes+0xf>
mov    %ebp,%edi
call   1030 <sqrt@plt>
mov    %eax,%ecx
cmp    $0x2,%eax
jl     1134 <frequency_of_primes+0x24>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%eax
cltd
idiv   %ecx
test   %edx,%edx
je     1130 <frequency_of_primes+0x20>
lea    -0x1(%rcx),%eax
cmp    $0x3,%ecx
mov    %eax,%ecx
jge    1150 <frequency_of_primes+0x40>
jmp    1134 <frequency_of_primes+0x24>

LLVM IR (-O0):
define i32 @frequency_of_primes(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = sub nsw i32 %6, 1
store i32 %7, i32* %5
store i32 2, i32* %3
br label %8
8: ; preds = %31, %1
%9 = load i32, i32* %3
%10 = load i32, i32* %2
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %34
12: ; preds = %8
%13 = load i32, i32* %3
%14 = call i32 @sqrt(i32 %13)
store i32 %14, i32* %4
br label %15
15: ; preds = %27, %12
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 1
br i1 %17, label %18, label %30
18: ; preds = %15
%19 = load i32, i32* %3
%20 = load i32, i32* %4
%21 = srem i32 %19, %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32, i32* %5
%25 = add nsw i32 %24, -1
store i32 %25, i32* %5
br label %30
26: ; preds = %18
br label %27
27: ; preds = %26
%28 = load i32, i32* %4
%29 = add nsw i32 %28, -1
store i32 %29, i32* %4
br label %15
30: ; preds = %23, %15
br label %31
31: ; preds = %30
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %8
34: ; preds = %8
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
define i32 @frequency_of_primes(i32 %0) {
%2 = add nsw i32 %0, -1
%3 = icmp slt i32 %0, 2
br i1 %3, label %22, label %4
4: ; preds = %1, %18
%5 = phi i32 [ %19, %18 ], [ %2, %1 ]
%6 = phi i32 [ %20, %18 ], [ 2, %1 ]
%7 = tail call i32 @sqrt(i32 %6)
%8 = icmp sgt i32 %7, 1
br i1 %8, label %12, label %18
9: ; preds = %12
%10 = add nsw i32 %13, -1
%11 = icmp sgt i32 %13, 2
br i1 %11, label %12, label %18
12: ; preds = %4, %9
%13 = phi i32 [ %10, %9 ], [ %7, %4 ]
%14 = srem i32 %6, %13
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %9
16: ; preds = %12
%17 = add nsw i32 %5, -1
br label %18
18: ; preds = %9, %4, %16
%19 = phi i32 [ %17, %16 ], [ %5, %4 ], [ %5, %9 ]
%20 = add nuw i32 %6, 1
%21 = icmp eq i32 %6, %0
br i1 %21, label %22, label %4
22: ; preds = %18, %1
%23 = phi i32 [ %2, %1 ], [ %19, %18 ]
ret i32 %23
}