#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 */
struct node {
  int dummy;
};

/* Variables and functions */
int EXIT_SUCCESS;
struct node **gen_factors(int const, struct node *);
struct node *gen_primes(int const);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ relative_prime(int, int, struct node **);
int main(int argc, char **argv) {
  const int max = 12000;
  struct node *primes = gen_primes(max);
  struct node **factors = gen_factors(max + 1, primes);
  int count = 0;
  for (int d = 2; d <= max; ++d) {
    for (int n = d / 3 + 1; n < (d - 1) / 2 + 1; ++n) {
      double result = 1.0 * n / d;
      if (result > 1.0 / 3.0 && result < 1.0 / 2.0 &&
          relative_prime(n, d, factors)) {
        count++;
      }
    }
  }
  printf("%d\n", count);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2ee0,-0x14(%rbp)
mov    $0x2ee0,%edi
call   1050 <gen_primes@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
mov    $0x2ee1,%edi
call   1060 <gen_factors@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x2,-0x30(%rbp)
cmpl   $0x2ee0,-0x30(%rbp)
jg     125e <main+0x11e>
mov    -0x30(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jge    124b <main+0x10b>
cvtsi2sdl -0x34(%rbp),%xmm1
movsd  0xe2e(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x30(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xe07(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1238 <main+0xf8>
movsd  0xe05(%rip),%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    1238 <main+0xf8>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1030 <relative_prime@plt>
cmp    $0x0,%rax
je     1238 <main+0xf8>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    123d <main+0xfd>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a9 <main+0x69>
jmp    1250 <main+0x110>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    118b <main+0x4b>
mov    -0x2c(%rbp),%esi
lea    0xdb0(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0x2ee0,%edi
call   1050 <gen_primes@plt>
mov    $0x2ee1,%edi
mov    %rax,%rsi
call   1060 <gen_factors@plt>
mov    %rax,%r14
xor    %r15d,%r15d
mov    $0x2,%r12d
movsd  0xe89(%rip),%xmm1
movsd  0xe89(%rip),%xmm2
jmp    11a5 <main+0x65>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
addsd  0xe80(%rip),%xmm1
add    $0x1,%r12d
cmp    $0x2ee1,%r12d
je     121b <main+0xdb>
movzwl %r12w,%eax
imul   $0xaaab,%eax,%ebp
shr    $0x11,%ebp
lea    -0x1(%r12),%ebx
shr    %ebx
cmp    %ebp,%ebx
movsd  %xmm1,0x8(%rsp)
ja     11d4 <main+0x94>
jmp    1190 <main+0x50>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    %ebx,%ebp
jae    1190 <main+0x50>
add    $0x1,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
divsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jbe    11d0 <main+0x90>
movsd  0xe20(%rip),%xmm3
ucomisd %xmm0,%xmm3
jbe    11d0 <main+0x90>
mov    %ebp,%edi
mov    %r12d,%esi
mov    %r14,%rdx
call   1030 <relative_prime@plt>
movsd  0xdfd(%rip),%xmm2
movsd  0x8(%rsp),%xmm1
cmp    $0x1,%rax
sbb    $0xffffffff,%r15d
jmp    11d0 <main+0x90>
lea    0xdfe(%rip),%rdi
mov    %r15d,%esi
call   1040 <printf@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.node = type { i32 }
@.str = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.node*
%8 = alloca %struct.node**
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 12000, i32* %6
%13 = call %struct.node* @gen_primes(i32 12000)
store %struct.node* %13, %struct.node** %7
%14 = load %struct.node*, %struct.node** %7
%15 = call %struct.node** @gen_factors(i32 12001, %struct.node* %14)
store %struct.node** %15, %struct.node*** %8
store i32 0, i32* %9
store i32 2, i32* %10
br label %16
16: ; preds = %56, %2
%17 = load i32, i32* %10
%18 = icmp sle i32 %17, 12000
br i1 %18, label %19, label %59
19: ; preds = %16
%20 = load i32, i32* %10
%21 = sdiv i32 %20, 3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %11
br label %23
23: ; preds = %52, %19
%24 = load i32, i32* %11
%25 = load i32, i32* %10
%26 = sub nsw i32 %25, 1
%27 = sdiv i32 %26, 2
%28 = add nsw i32 %27, 1
%29 = icmp slt i32 %24, %28
br i1 %29, label %30, label %55
30: ; preds = %23
%31 = load i32, i32* %11
%32 = sitofp i32 %31 to double
%33 = fmul double 1.000000e+00, %32
%34 = load i32, i32* %10
%35 = sitofp i32 %34 to double
%36 = fdiv double %33, %35
store double %36, double* %12
%37 = load double, double* %12
%38 = fcmp ogt double %37, 0x3FD5555555555555
br i1 %38, label %39, label %51
39: ; preds = %30
%40 = load double, double* %12
%41 = fcmp olt double %40, 5.000000e-01
br i1 %41, label %42, label %51
42: ; preds = %39
%43 = load i32, i32* %11
%44 = load i32, i32* %10
%45 = load %struct.node**, %struct.node*** %8
%46 = call i64 @relative_prime(i32 %43, i32 %44, %struct.node** %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %42
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
store i32 %50, i32* %9
br label %51
51: ; preds = %48, %42, %39, %30
br label %52
52: ; preds = %51
%53 = load i32, i32* %11
%54 = add nsw i32 %53, 1
store i32 %54, i32* %11
br label %23
55: ; preds = %23
br label %56
56: ; preds = %55
%57 = load i32, i32* %10
%58 = add nsw i32 %57, 1
store i32 %58, i32* %10
br label %16
59: ; preds = %16
%60 = load i32, i32* %9
%61 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %60)
%62 = load i32, i32* @EXIT_SUCCESS
ret i32 %62
}

LLVM IR (-O2):
%struct.node = type { i32 }
@.str = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call %struct.node* @gen_primes(i32 12000)
%4 = tail call %struct.node** @gen_factors(i32 12001, %struct.node* %3)
br label %8
5: ; preds = %19
%6 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %20)
%7 = load i32, i32* @EXIT_SUCCESS
ret i32 %7
8: ; preds = %2, %19
%9 = phi i32 [ 2, %2 ], [ %21, %19 ]
%10 = phi i32 [ 0, %2 ], [ %20, %19 ]
%11 = trunc i32 %9 to i16
%12 = udiv i16 %11, 3
%13 = zext i16 %12 to i32
%14 = add nsw i32 %9, -1
%15 = lshr i32 %14, 1
%16 = icmp ugt i32 %15, %13
br i1 %16, label %17, label %19
17: ; preds = %8
%18 = sitofp i32 %9 to double
br label %23
19: ; preds = %37, %8
%20 = phi i32 [ %10, %8 ], [ %38, %37 ]
%21 = add nuw nsw i32 %9, 1
%22 = icmp eq i32 %21, 12001
br i1 %22, label %5, label %8
23: ; preds = %17, %37
%24 = phi i32 [ %13, %17 ], [ %26, %37 ]
%25 = phi i32 [ %10, %17 ], [ %38, %37 ]
%26 = add nuw nsw i32 %24, 1
%27 = sitofp i32 %26 to double
%28 = fdiv double %27, %18
%29 = fcmp ogt double %28, 0x3FD5555555555555
%30 = fcmp olt double %28, 5.000000e-01
%31 = and i1 %29, %30
br i1 %31, label %32, label %37
32: ; preds = %23
%33 = tail call i64 @relative_prime(i32 %26, i32 %9, %struct.node** %4)
%34 = icmp ne i64 %33, 0
%35 = zext i1 %34 to i32
%36 = add nsw i32 %25, %35
br label %37
37: ; preds = %32, %23
%38 = phi i32 [ %25, %23 ], [ %36, %32 ]
%39 = icmp ult i32 %26, %15
br i1 %39, label %23, label %19
}