#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*/ mark_multiples(unsigned int **, unsigned int *,
                                  unsigned int *);
double sqrt(unsigned int);
void sieve(unsigned int **list, unsigned int *N) {
  unsigned int k = 2;
  double sqrtN = sqrt(*N);
  while (k < sqrtN) {
    if ((*list)[k] == 0)
      mark_multiples(list, N, &k);
    ++k;
  }
}


x86 assembly (clang, -O0):
<sieve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1040 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
cvtsi2sd %rax,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1191 <sieve+0x71>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x14(%rbp),%ecx
cmpl   $0x0,(%rax,%rcx,4)
jne    1183 <sieve+0x63>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1030 <mark_multiples@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1147 <sieve+0x27>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sieve>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x2,0x4(%rsp)
mov    (%rsi),%edi
call   1040 <sqrt@plt>
ucomisd 0xeba(%rip),%xmm0
jbe    119a <sieve+0x7a>
mov    $0x2,%eax
lea    0x4(%rsp),%r15
movsd  %xmm0,0x8(%rsp)
jmp    1175 <sieve+0x55>
nopw   0x0(%rax,%rax,1)
add    $0x1,%eax
mov    %eax,0x4(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
ucomisd %xmm1,%xmm0
jbe    119a <sieve+0x7a>
mov    (%rbx),%rcx
mov    %eax,%edx
cmpl   $0x0,(%rcx,%rdx,4)
jne    1160 <sieve+0x40>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <mark_multiples@plt>
movsd  0x8(%rsp),%xmm0
mov    0x4(%rsp),%eax
jmp    1160 <sieve+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @sieve(i32** %0, i32* %1) {
%3 = alloca i32**
%4 = alloca i32*
%5 = alloca i32
%6 = alloca double
store i32** %0, i32*** %3
store i32* %1, i32** %4
store i32 2, i32* %5
%7 = load i32*, i32** %4
%8 = load i32, i32* %7
%9 = call double @sqrt(i32 %8)
store double %9, double* %6
br label %10
10: ; preds = %27, %2
%11 = load i32, i32* %5
%12 = uitofp i32 %11 to double
%13 = load double, double* %6
%14 = fcmp olt double %12, %13
br i1 %14, label %15, label %30
15: ; preds = %10
%16 = load i32**, i32*** %3
%17 = load i32*, i32** %16
%18 = load i32, i32* %5
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %15
%24 = load i32**, i32*** %3
%25 = load i32*, i32** %4
%26 = call i32 @mark_multiples(i32** %24, i32* %25, i32* %5)
br label %27
27: ; preds = %23, %15
%28 = load i32, i32* %5
%29 = add i32 %28, 1
store i32 %29, i32* %5
br label %10
30: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @sieve(i32** %0, i32* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 2, i32* %3
%5 = load i32, i32* %1
%6 = tail call double @sqrt(i32 %5)
%7 = fcmp ogt double %6, 2.000000e+00
br i1 %7, label %8, label %23
8: ; preds = %2, %18
%9 = phi i32 [ %20, %18 ], [ 2, %2 ]
%10 = load i32*, i32** %0
%11 = zext i32 %9 to i64
%12 = getelementptr inbounds i32, i32* %10, i64 %11
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %8
%16 = call i32 @mark_multiples(i32** %0, i32* %1, i32* %3)
%17 = load i32, i32* %3
br label %18
18: ; preds = %15, %8
%19 = phi i32 [ %17, %15 ], [ %9, %8 ]
%20 = add i32 %19, 1
store i32 %20, i32* %3
%21 = uitofp i32 %20 to double
%22 = fcmp ogt double %6, %21
br i1 %22, label %8, label %23
23: ; preds = %18, %2
ret void
}