#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 diags();
scalar_t__ isprime(int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int nprimes = 0;
  int ndiags = 1;
  while (1) {
    for (int i = 0; i < 4; i++) {
      int n = diags();
      ndiags++;
      if (isprime(n)) {
        nprimes++;
      }
    }
    float ratio = nprimes * 1.0 / ndiags;
    if (ratio < 0.1) {
      break;
    }
  }
  printf("%d\n", (ndiags + 1) / 2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    119f <main+0x6f>
mov    $0x0,%al
call   1040 <diags@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <isprime@plt>
cmp    $0x0,%rax
je     118c <main+0x5c>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1191 <main+0x61>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1154 <main+0x24>
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xe5c(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe2d(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11e2 <main+0xb2>
jmp    11e7 <main+0xb7>
jmp    114d <main+0x1d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe12(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x2,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <diags@plt>
mov    %eax,%edi
call   1050 <isprime@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
xor    %eax,%eax
call   1040 <diags@plt>
mov    %eax,%edi
call   1050 <isprime@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
xor    %eax,%eax
call   1040 <diags@plt>
mov    %eax,%edi
call   1050 <isprime@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
xor    %eax,%eax
call   1040 <diags@plt>
mov    %eax,%edi
call   1050 <isprime@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
lea    0x3(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
cvtss2sd %xmm0,%xmm0
add    $0x4,%ebx
movsd  0xe44(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1140 <main+0x10>
mov    %ebx,%esi
shr    $0x1f,%esi
add    %ebx,%esi
sar    %esi
lea    0xe32(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca float
store i32 0, i32* %1
store i32 0, i32* %2
store i32 1, i32* %3
br label %7
7: ; preds = %0, %37
store i32 0, i32* %4
br label %8
8: ; preds = %22, %7
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 4
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = call i32 (...) @diags()
store i32 %12, i32* %5
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
%15 = load i32, i32* %5
%16 = call i64 @isprime(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %21
21: ; preds = %18, %11
br label %22
22: ; preds = %21
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %8
25: ; preds = %8
%26 = load i32, i32* %2
%27 = sitofp i32 %26 to double
%28 = fmul double %27, 1.000000e+00
%29 = load i32, i32* %3
%30 = sitofp i32 %29 to double
%31 = fdiv double %28, %30
%32 = fptrunc double %31 to float
store float %32, float* %6
%33 = load float, float* %6
%34 = fpext float %33 to double
%35 = fcmp olt double %34, 1.000000e-01
br i1 %35, label %36, label %37
36: ; preds = %25
br label %38
37: ; preds = %25
br label %7
38: ; preds = %36
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
%41 = sdiv i32 %40, 2
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
br label %1
1: ; preds = %1, %0
%2 = phi i32 [ 1, %0 ], [ %24, %1 ]
%3 = phi i32 [ 0, %0 ], [ %23, %1 ]
%4 = tail call i32 (...) @diags()
%5 = tail call i64 @isprime(i32 %4)
%6 = icmp ne i64 %5, 0
%7 = zext i1 %6 to i32
%8 = add nsw i32 %3, %7
%9 = tail call i32 (...) @diags()
%10 = tail call i64 @isprime(i32 %9)
%11 = icmp ne i64 %10, 0
%12 = zext i1 %11 to i32
%13 = add nsw i32 %8, %12
%14 = tail call i32 (...) @diags()
%15 = tail call i64 @isprime(i32 %14)
%16 = icmp ne i64 %15, 0
%17 = zext i1 %16 to i32
%18 = add nsw i32 %13, %17
%19 = tail call i32 (...) @diags()
%20 = tail call i64 @isprime(i32 %19)
%21 = icmp ne i64 %20, 0
%22 = zext i1 %21 to i32
%23 = add nsw i32 %18, %22
%24 = add i32 %2, 4
%25 = sitofp i32 %23 to double
%26 = sitofp i32 %24 to double
%27 = fdiv double %25, %26
%28 = fptrunc double %27 to float
%29 = fpext float %28 to double
%30 = fcmp olt double %29, 1.000000e-01
br i1 %30, label %31, label %1
31: ; preds = %1
%32 = add i32 %2, 5
%33 = sdiv i32 %32, 2
%34 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %33)
ret i32 0
}