#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 /*<<< orphan*/ memset(unsigned char *, int, unsigned int);
unsigned int sieveSearch(unsigned char *, int, unsigned int);
int /*<<< orphan*/ sieveSingle(unsigned char *, unsigned int, unsigned int,
                               unsigned int);
void sieveSmall(unsigned char *array, unsigned size) {
  unsigned i;
  unsigned p;
  memset(array, 0xFF, size);
  array[0] = 0xfe;
  i = 1;
  do {
    p = 2 * i + 1;
    if (p > 256)
      break;
    sieveSingle(array, size, (p * p - 1) / 2, p);
    i = sieveSearch(array, 16, i);
  } while (i);
}


x86 assembly (clang, -O0):
<sieveSmall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    $0xff,%esi
call   1040 <memset@plt>
mov    -0x8(%rbp),%rax
movb   $0xfe,(%rax)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x100,-0x14(%rbp)
jbe    117c <sieveSmall+0x4c>
jmp    11b6 <sieveSmall+0x86>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
imul   -0x14(%rbp),%edx
sub    $0x1,%edx
shr    $0x1,%edx
mov    -0x14(%rbp),%ecx
call   1050 <sieveSingle@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%edx
mov    $0x10,%esi
call   1030 <sieveSearch@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    115e <sieveSmall+0x2e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sieveSmall>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
mov    $0xff,%esi
mov    %r14d,%edx
call   1040 <memset@plt>
movb   $0xfe,(%rbx)
mov    $0x1,%ebp
nop
lea    0x1(%rbp,%rbp,1),%ecx
cmp    $0x100,%ecx
ja     1186 <sieveSmall+0x56>
mov    %ecx,%edx
imul   %ecx,%edx
add    $0xffffffff,%edx
shr    %edx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <sieveSingle@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
mov    %ebp,%edx
call   1030 <sieveSearch@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1150 <sieveSmall+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @sieveSmall(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = load i32, i32* %4
%9 = call i32 @memset(i8* %7, i32 255, i32 %8)
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 0
store i8 -2, i8* %11
store i32 1, i32* %5
br label %12
12: ; preds = %32, %2
%13 = load i32, i32* %5
%14 = mul i32 2, %13
%15 = add i32 %14, 1
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp ugt i32 %16, 256
br i1 %17, label %18, label %19
18: ; preds = %12
br label %35
19: ; preds = %12
%20 = load i8*, i8** %3
%21 = load i32, i32* %4
%22 = load i32, i32* %6
%23 = load i32, i32* %6
%24 = mul i32 %22, %23
%25 = sub i32 %24, 1
%26 = udiv i32 %25, 2
%27 = load i32, i32* %6
%28 = call i32 @sieveSingle(i8* %20, i32 %21, i32 %26, i32 %27)
%29 = load i8*, i8** %3
%30 = load i32, i32* %5
%31 = call i32 @sieveSearch(i8* %29, i32 16, i32 %30)
store i32 %31, i32* %5
br label %32
32: ; preds = %19
%33 = load i32, i32* %5
%34 = icmp ne i32 %33, 0
br i1 %34, label %12, label %35
35: ; preds = %32, %18
ret void
}

LLVM IR (-O2):
define void @sieveSmall(i8* %0, i32 %1) {
%3 = tail call i32 @memset(i8* %0, i32 255, i32 %1)
store i8 -2, i8* %0
br label %4
4: ; preds = %9, %2
%5 = phi i32 [ 1, %2 ], [ %14, %9 ]
%6 = shl i32 %5, 1
%7 = or i32 %6, 1
%8 = icmp ugt i32 %7, 256
br i1 %8, label %16, label %9
9: ; preds = %4
%10 = mul nuw nsw i32 %7, %7
%11 = add nsw i32 %10, -1
%12 = lshr exact i32 %11, 1
%13 = tail call i32 @sieveSingle(i8* %0, i32 %1, i32 %12, i32 %7)
%14 = tail call i32 @sieveSearch(i8* %0, i32 16, i32 %5)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %4
16: ; preds = %4, %9
ret void
}