#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__ sqrt(float);
int prime_numbers() {
  int nprimes = 2;
  for (int n = 3; n < 1000; n += 2) {
    volatile int limit, factor = 3;
    limit = (long)(sqrt((float)n) + 0.5f);
    while ((factor <= limit) && (n % factor))
      factor++;
    if (factor > limit)
      nprimes++;
  }
  return nprimes;
}


x86 assembly (clang, -O0):
<prime_numbers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x2,-0x4(%rbp)
movl   $0x3,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    11ca <prime_numbers+0xba>
movl   $0x3,-0x10(%rbp)
cvtsi2ssl -0x8(%rbp),%xmm0
call   1030 <sqrt@plt>
cvtsi2ss %rax,%xmm0
movss  0xeaf(%rip),%xmm1
addss  %xmm1,%xmm0
cvttss2si %xmm0,%rax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x11(%rbp)
jg     1182 <prime_numbers+0x72>
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1192 <prime_numbers+0x82>
jmp    11a0 <prime_numbers+0x90>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115d <prime_numbers+0x4d>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
cmp    %ecx,%eax
jle    11b7 <prime_numbers+0xa7>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11bc <prime_numbers+0xac>
mov    -0x8(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x8(%rbp)
jmp    1126 <prime_numbers+0x16>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prime_numbers>:
push   %rbp
push   %rbx
push   %rax
mov    $0x2,%ebp
mov    $0x3,%ebx
jmp    113b <prime_numbers+0x2b>
nop
mov    (%rsp),%eax
xor    %ecx,%ecx
cmp    0x4(%rsp),%eax
setg   %cl
add    %ecx,%ebp
lea    0x2(%rbx),%eax
cmp    $0x3e6,%ebx
mov    %eax,%ebx
jae    1189 <prime_numbers+0x79>
movl   $0x3,(%rsp)
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
call   1030 <sqrt@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  0xea2(%rip),%xmm0
cvttss2si %xmm0,%rax
mov    %eax,0x4(%rsp)
nopw   0x0(%rax,%rax,1)
mov    (%rsp),%eax
cmp    0x4(%rsp),%eax
jg     1120 <prime_numbers+0x10>
mov    %ebx,%eax
cltd
idivl  (%rsp)
test   %edx,%edx
je     1120 <prime_numbers+0x10>
addl   $0x1,(%rsp)
jmp    1170 <prime_numbers+0x60>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @prime_numbers() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 2, i32* %1
store i32 3, i32* %2
br label %5
5: ; preds = %38, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 1000
br i1 %7, label %8, label %41
8: ; preds = %5
store volatile i32 3, i32* %4
%9 = load i32, i32* %2
%10 = sitofp i32 %9 to float
%11 = call i64 @sqrt(float %10)
%12 = sitofp i64 %11 to float
%13 = fadd float %12, 5.000000e-01
%14 = fptosi float %13 to i64
%15 = trunc i64 %14 to i32
store volatile i32 %15, i32* %3
br label %16
16: ; preds = %27, %8
%17 = load volatile i32, i32* %4
%18 = load volatile i32, i32* %3
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i32, i32* %2
%22 = load volatile i32, i32* %4
%23 = srem i32 %21, %22
%24 = icmp ne i32 %23, 0
br label %25
25: ; preds = %20, %16
%26 = phi i1 [ false, %16 ], [ %24, %20 ]
br i1 %26, label %27, label %30
27: ; preds = %25
%28 = load volatile i32, i32* %4
%29 = add nsw i32 %28, 1
store volatile i32 %29, i32* %4
br label %16
30: ; preds = %25
%31 = load volatile i32, i32* %4
%32 = load volatile i32, i32* %3
%33 = icmp sgt i32 %31, %32
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32, i32* %1
%36 = add nsw i32 %35, 1
store i32 %36, i32* %1
br label %37
37: ; preds = %34, %30
br label %38
38: ; preds = %37
%39 = load i32, i32* %2
%40 = add nsw i32 %39, 2
store i32 %40, i32* %2
br label %5
41: ; preds = %5
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
define i32 @prime_numbers() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
br label %6
5: ; preds = %28
ret i32 %33
6: ; preds = %0, %28
%7 = phi i32 [ 3, %0 ], [ %34, %28 ]
%8 = phi i32 [ 2, %0 ], [ %33, %28 ]
store volatile i32 3, i32* %2
%9 = sitofp i32 %7 to float
%10 = tail call i64 @sqrt(float %9)
%11 = sitofp i64 %10 to float
%12 = fadd float %11, 5.000000e-01
%13 = fptosi float %12 to i64
%14 = trunc i64 %13 to i32
store volatile i32 %14, i32* %1
%15 = load volatile i32, i32* %2
%16 = load volatile i32, i32* %1
%17 = icmp sgt i32 %15, %16
br i1 %17, label %28, label %18
18: ; preds = %6, %22
%19 = load volatile i32, i32* %2
%20 = srem i32 %7, %19
%21 = icmp eq i32 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %18
%23 = load volatile i32, i32* %2
%24 = add nsw i32 %23, 1
store volatile i32 %24, i32* %2
%25 = load volatile i32, i32* %2
%26 = load volatile i32, i32* %1
%27 = icmp sgt i32 %25, %26
br i1 %27, label %28, label %18
28: ; preds = %18, %22, %6
%29 = load volatile i32, i32* %2
%30 = load volatile i32, i32* %1
%31 = icmp sgt i32 %29, %30
%32 = zext i1 %31 to i32
%33 = add nuw nsw i32 %8, %32
%34 = add nuw nsw i32 %7, 2
%35 = icmp ult i32 %7, 998
br i1 %35, label %6, label %5
}