#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__ floor(int /*<<< orphan*/);
scalar_t__ pow(int, int);
int /*<<< orphan*/ sqrt(int);
void sieve(int *numbers) {
  int limit = (int)floor(sqrt(1000000));
  int i;
  for (i = 2; i <= limit; i++) {
    int j, k;
    j = k = 0;
    while (1) {
      j = ((int)pow(i, 2)) + (k++ * i);
      if (j <= 1000000) {
        numbers[j] = 0;
      } else {
        break;
      }
    }
  }
}


x86 assembly (clang, -O0):
<sieve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0xf4240,%edi
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1050 <floor@plt>
mov    %eax,-0xc(%rbp)
movl   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11d0 <sieve+0xa0>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%edi
mov    $0x2,%esi
call   1030 <pow@plt>
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
imul   -0x10(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xf4240,-0x14(%rbp)
jg     11b3 <sieve+0x83>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    11b8 <sieve+0x88>
jmp    11bd <sieve+0x8d>
jmp    1171 <sieve+0x41>
jmp    11c2 <sieve+0x92>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1157 <sieve+0x27>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sieve>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
mov    $0xf4240,%edi
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1050 <floor@plt>
mov    %rax,%r14
cmp    $0x2,%r14d
jge    115e <sieve+0x2e>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x2,%r12d
jmp    117d <sieve+0x4d>
cs nopw 0x0(%rax,%rax,1)
lea    0x1(%r12),%eax
cmp    %r14d,%r12d
mov    %eax,%r12d
je     1155 <sieve+0x25>
mov    %r12d,%edi
mov    $0x2,%esi
call   1030 <pow@plt>
cmp    $0xf4240,%eax
jg     1170 <sieve+0x40>
xor    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebx
cltq
movl   $0x0,(%r15,%rax,4)
mov    %r12d,%edi
mov    $0x2,%esi
call   1030 <pow@plt>
mov    %rax,%rcx
mov    %ebx,%eax
imul   %r12d,%eax
add    %ecx,%eax
add    %r12d,%ebp
add    %ebp,%ecx
cmp    $0xf4241,%ecx
jl     11a0 <sieve+0x70>
jmp    1170 <sieve+0x40>

LLVM IR (-O0):
define void @sieve(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %2
%7 = call i32 @sqrt(i32 1000000)
%8 = call i64 @floor(i32 %7)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %3
store i32 2, i32* %4
br label %10
10: ; preds = %34, %1
%11 = load i32, i32* %4
%12 = load i32, i32* %3
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %37
14: ; preds = %10
store i32 0, i32* %6
store i32 0, i32* %5
br label %15
15: ; preds = %14, %32
%16 = load i32, i32* %4
%17 = call i64 @pow(i32 %16, i32 2)
%18 = trunc i64 %17 to i32
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
%21 = load i32, i32* %4
%22 = mul nsw i32 %19, %21
%23 = add nsw i32 %18, %22
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = icmp sle i32 %24, 1000000
br i1 %25, label %26, label %31
26: ; preds = %15
%27 = load i32*, i32** %2
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
store i32 0, i32* %30
br label %32
31: ; preds = %15
br label %33
32: ; preds = %26
br label %15
33: ; preds = %31
br label %34
34: ; preds = %33
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %10
37: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @sieve(i32* nocapture writeonly %0) {
%2 = tail call i32 @sqrt(i32 1000000)
%3 = tail call i64 @floor(i32 %2)
%4 = trunc i64 %3 to i32
%5 = icmp slt i32 %4, 2
br i1 %5, label %25, label %6
6: ; preds = %1, %22
%7 = phi i32 [ %23, %22 ], [ 2, %1 ]
%8 = tail call i64 @pow(i32 %7, i32 2)
%9 = trunc i64 %8 to i32
%10 = icmp slt i32 %9, 1000001
br i1 %10, label %11, label %22
11: ; preds = %6, %11
%12 = phi i32 [ %20, %11 ], [ %9, %6 ]
%13 = phi i32 [ %14, %11 ], [ 0, %6 ]
%14 = add nuw nsw i32 %13, 1
%15 = sext i32 %12 to i64
%16 = getelementptr inbounds i32, i32* %0, i64 %15
store i32 0, i32* %16
%17 = tail call i64 @pow(i32 %7, i32 2)
%18 = trunc i64 %17 to i32
%19 = mul nsw i32 %14, %7
%20 = add nsw i32 %19, %18
%21 = icmp slt i32 %20, 1000001
br i1 %21, label %11, label %22
22: ; preds = %11, %6
%23 = add nuw i32 %7, 1
%24 = icmp eq i32 %7, %4
br i1 %24, label %25, label %6
25: ; preds = %22, %1
ret void
}