#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 */
typedef int /*<<< orphan*/ mpz_t;

/* Variables and functions */
int /*<<< orphan*/ mpz_add_ui(int /*<<< orphan*/, int /*<<< orphan*/,
                              unsigned long);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
scalar_t__ mpz_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
scalar_t__ mpz_probab_prime_p(int /*<<< orphan*/, int);
int /*<<< orphan*/ report(int /*<<< orphan*/);
void find_primes(unsigned char *s, mpz_t fr, unsigned long ssize,
                 mpz_t siev_sqr_lim) {
  unsigned long j, ij;
  mpz_t tmp;
  mpz_init(tmp);
  for (j = 0; j < (ssize + sizeof(long) - 1) / sizeof(long); j++) {
    if (((long *)s)[j] != 0) {
      for (ij = 0; ij < sizeof(long); ij++) {
        if (s[j * sizeof(long) + ij] != 0) {
          if (j * sizeof(long) + ij >= ssize)
            goto out;
          mpz_add_ui(tmp, fr, (j * sizeof(long) + ij) * 2);
          if (mpz_cmp(tmp, siev_sqr_lim) < 0 || mpz_probab_prime_p(tmp, 3))
            report(tmp);
        }
      }
    }
  }
out:
  mpz_clear(tmp);
}


x86 assembly (clang, -O0):
<find_primes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x34(%rbp),%edi
call   1050 <mpz_init@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
add    $0x8,%rcx
sub    $0x1,%rcx
shr    $0x3,%rcx
cmp    %rcx,%rax
jae    1286 <find_primes+0x126>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1270 <find_primes+0x110>
movq   $0x0,-0x30(%rbp)
cmpq   $0x8,-0x30(%rbp)
jae    126b <find_primes+0x10b>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
shl    $0x3,%rcx
add    -0x30(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1255 <find_primes+0xf5>
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
add    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     1201 <find_primes+0xa1>
jmp    128b <find_primes+0x12b>
mov    -0x34(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x28(%rbp),%rdx
shl    $0x3,%rdx
add    -0x30(%rbp),%rdx
shl    $0x1,%rdx
call   1040 <mpz_add_ui@plt>
mov    -0x34(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1060 <mpz_cmp@plt>
cmp    $0x0,%rax
jl     1248 <find_primes+0xe8>
mov    -0x34(%rbp),%edi
mov    $0x3,%esi
call   1030 <mpz_probab_prime_p@plt>
cmp    $0x0,%rax
je     1250 <find_primes+0xf0>
mov    -0x34(%rbp),%edi
call   1080 <report@plt>
jmp    1255 <find_primes+0xf5>
jmp    125a <find_primes+0xfa>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11be <find_primes+0x5e>
jmp    1270 <find_primes+0x110>
jmp    1275 <find_primes+0x115>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1186 <find_primes+0x26>
jmp    128b <find_primes+0x12b>
mov    -0x34(%rbp),%edi
call   1070 <mpz_clear@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_primes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,0x14(%rsp)
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %rdi,%rbp
call   1050 <mpz_init@plt>
lea    0x7(%rbx),%rax
mov    %rax,0x18(%rsp)
cmp    $0x8,%rax
jae    11a2 <find_primes+0x42>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <mpz_clear@plt>
shrq   $0x3,0x18(%rsp)
xor    %eax,%eax
mov    %rax,0x20(%rsp)
xor    %r12d,%r12d
xor    %eax,%eax
mov    %rax,0x8(%rsp)
jmp    11e2 <find_primes+0x82>
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rcx
add    $0x1,%rcx
add    $0x10,%r12
addq   $0x8,0x20(%rsp)
mov    %rcx,%rax
mov    %rcx,0x8(%rsp)
cmp    0x18(%rsp),%rcx
je     118f <find_primes+0x2f>
mov    0x8(%rsp),%rax
cmpq   $0x0,0x0(%rbp,%rax,8)
je     11c0 <find_primes+0x60>
mov    0x20(%rsp),%r13
xor    %r14d,%r14d
jmp    1213 <find_primes+0xb3>
nopl   0x0(%rax)
call   1080 <report@plt>
add    $0x2,%r14
add    $0x1,%r13
cmp    $0x10,%r14
je     11c0 <find_primes+0x60>
cmpb   $0x0,0x0(%rbp,%r13,1)
je     1205 <find_primes+0xa5>
cmp    %rbx,%r13
jae    118f <find_primes+0x2f>
lea    (%r12,%r14,1),%rdx
mov    %r15d,%esi
call   1040 <mpz_add_ui@plt>
mov    0x14(%rsp),%esi
call   1060 <mpz_cmp@plt>
test   %rax,%rax
js     1200 <find_primes+0xa0>
mov    $0x3,%esi
call   1030 <mpz_probab_prime_p@plt>
test   %rax,%rax
jne    1200 <find_primes+0xa0>
jmp    1205 <find_primes+0xa5>

LLVM IR (-O0):
define void @find_primes(i8* %0, i32 %1, i64 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i64 %2, i64* %7
store i32 %3, i32* %8
%12 = load i32, i32* %11
%13 = call i32 @mpz_init(i32 %12)
store i64 0, i64* %9
br label %14
14: ; preds = %77, %4
%15 = load i64, i64* %9
%16 = load i64, i64* %7
%17 = add i64 %16, 8
%18 = sub i64 %17, 1
%19 = udiv i64 %18, 8
%20 = icmp ult i64 %15, %19
br i1 %20, label %21, label %80
21: ; preds = %14
%22 = load i8*, i8** %5
%23 = bitcast i8* %22 to i64*
%24 = load i64, i64* %9
%25 = getelementptr inbounds i64, i64* %23, i64 %24
%26 = load i64, i64* %25
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %76
28: ; preds = %21
store i64 0, i64* %10
br label %29
29: ; preds = %72, %28
%30 = load i64, i64* %10
%31 = icmp ult i64 %30, 8
br i1 %31, label %32, label %75
32: ; preds = %29
%33 = load i8*, i8** %5
%34 = load i64, i64* %9
%35 = mul i64 %34, 8
%36 = load i64, i64* %10
%37 = add i64 %35, %36
%38 = getelementptr inbounds i8, i8* %33, i64 %37
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %71
42: ; preds = %32
%43 = load i64, i64* %9
%44 = mul i64 %43, 8
%45 = load i64, i64* %10
%46 = add i64 %44, %45
%47 = load i64, i64* %7
%48 = icmp uge i64 %46, %47
br i1 %48, label %49, label %50
49: ; preds = %42
br label %81
50: ; preds = %42
%51 = load i32, i32* %11
%52 = load i32, i32* %6
%53 = load i64, i64* %9
%54 = mul i64 %53, 8
%55 = load i64, i64* %10
%56 = add i64 %54, %55
%57 = mul i64 %56, 2
%58 = call i32 @mpz_add_ui(i32 %51, i32 %52, i64 %57)
%59 = load i32, i32* %11
%60 = load i32, i32* %8
%61 = call i64 @mpz_cmp(i32 %59, i32 %60)
%62 = icmp slt i64 %61, 0
br i1 %62, label %67, label %63
63: ; preds = %50
%64 = load i32, i32* %11
%65 = call i64 @mpz_probab_prime_p(i32 %64, i32 3)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %63, %50
%68 = load i32, i32* %11
%69 = call i32 @report(i32 %68)
br label %70
70: ; preds = %67, %63
br label %71
71: ; preds = %70, %32
br label %72
72: ; preds = %71
%73 = load i64, i64* %10
%74 = add i64 %73, 1
store i64 %74, i64* %10
br label %29
75: ; preds = %29
br label %76
76: ; preds = %75, %21
br label %77
77: ; preds = %76
%78 = load i64, i64* %9
%79 = add i64 %78, 1
store i64 %79, i64* %9
br label %14
80: ; preds = %14
br label %81
81: ; preds = %80, %49
%82 = load i32, i32* %11
%83 = call i32 @mpz_clear(i32 %82)
ret void
}

LLVM IR (-O2):
define void @find_primes(i8* nocapture %0, i32 %1, i64 %2, i32 %3) {
%5 = tail call i32 @mpz_init(i32 undef)
%6 = add i64 %2, 7
%7 = icmp ult i64 %6, 8
br i1 %7, label %42, label %8
8: ; preds = %4
%9 = lshr i64 %6, 3
%10 = bitcast i8* %0 to i64*
br label %11
11: ; preds = %8, %39
%12 = phi i64 [ 0, %8 ], [ %40, %39 ]
%13 = getelementptr inbounds i64, i64* %10, i64 %12
%14 = load i64, i64* %13
%15 = icmp eq i64 %14, 0
br i1 %15, label %39, label %16
16: ; preds = %11
%17 = shl i64 %12, 3
br label %18
18: ; preds = %16, %36
%19 = phi i64 [ 0, %16 ], [ %37, %36 ]
%20 = add nuw nsw i64 %19, %17
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %36, label %24
24: ; preds = %18
%25 = icmp ult i64 %20, %2
br i1 %25, label %26, label %42
26: ; preds = %24
%27 = shl i64 %20, 1
%28 = tail call i32 @mpz_add_ui(i32 undef, i32 %1, i64 %27)
%29 = tail call i64 @mpz_cmp(i32 undef, i32 %3)
%30 = icmp slt i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %26
%32 = tail call i64 @mpz_probab_prime_p(i32 undef, i32 3)
%33 = icmp eq i64 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %31, %26
%35 = tail call i32 @report(i32 undef)
br label %36
36: ; preds = %18, %34, %31
%37 = add nuw nsw i64 %19, 1
%38 = icmp eq i64 %37, 8
br i1 %38, label %39, label %18
39: ; preds = %36, %11
%40 = add nuw nsw i64 %12, 1
%41 = icmp eq i64 %40, %9
br i1 %41, label %42, label %11
42: ; preds = %39, %24, %4
%43 = tail call i32 @mpz_clear(i32 undef)
ret void
}