#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 sqrt(int);
void sieve_eratosthene(int prime[], int length) {
  int i, j;
  for (i = 2; i < sqrt(length); i++) {
    for (j = i * i; j < length; j += i) {
      prime[j] = 0;
    }
  }
}


x86 assembly (clang, -O0):
<sieve_eratosthene>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <sqrt@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    1187 <sieve_eratosthene+0x77>
mov    -0x10(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1174 <sieve_eratosthene+0x64>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    114b <sieve_eratosthene+0x3b>
jmp    1179 <sieve_eratosthene+0x69>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <sieve_eratosthene+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sieve_eratosthene>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r12d
mov    %rdi,%r14
mov    %esi,%edi
call   1030 <sqrt@plt>
cmp    $0x3,%eax
jl     1192 <sieve_eratosthene+0x82>
mov    $0x2,%ebx
mov    $0x5,%r13d
mov    $0x4,%r15d
mov    $0x8,%ebp
jmp    116b <sieve_eratosthene+0x5b>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
mov    %r12d,%edi
call   1030 <sqrt@plt>
add    %r13d,%r15d
add    $0x2,%r13
add    $0x4,%rbp
cmp    %ebx,%eax
jle    1192 <sieve_eratosthene+0x82>
mov    %ebx,%eax
imul   %ebx,%eax
cmp    %r12d,%eax
jge    1150 <sieve_eratosthene+0x40>
mov    %r15d,%eax
lea    (%r14,%rax,4),%rax
mov    %r15d,%ecx
nop
movl   $0x0,(%rax)
add    %rbp,%rax
add    %ebx,%ecx
cmp    %r12d,%ecx
jl     1180 <sieve_eratosthene+0x70>
jmp    1150 <sieve_eratosthene+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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