#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 *malloc(int);
int pow(int, int);
int sqrt(int);
int *GenerateEratosthenesSieve(int *ptr_amount_primes) {
  int i = 0, j = 0, k = 0;
  int *ptr_sieve = malloc((20 - 2) * sizeof *ptr_sieve);
  for (i = 0; i < (20 - 2); i++) {
    ptr_sieve[i] = 1;
  }
  for (i = 2; i < sqrt(20); i++) {
    if (ptr_sieve[i - 2] == 1) {
      k = 0;
      j = (pow(i, 2) + k * i);
      while (j < 20) {
        if (ptr_sieve[j - 2] == 1) {
          ptr_sieve[j - 2] = 0;
          *ptr_amount_primes -= 1;
        }
        j = (pow(i, 2) + k++ * i);
      }
    }
  }
  return ptr_sieve;
}


x86 assembly (clang, -O0):
<GenerateEratosthenesSieve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x48,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x12,-0xc(%rbp)
jge    118d <GenerateEratosthenesSieve+0x5d>
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1166 <GenerateEratosthenesSieve+0x36>
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x14,%edi
call   1050 <sqrt@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    1266 <GenerateEratosthenesSieve+0x136>
mov    -0x20(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    1253 <GenerateEratosthenesSieve+0x123>
movl   $0x0,-0x14(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x2,%esi
call   1040 <pow@plt>
mov    -0x14(%rbp),%ecx
imul   -0xc(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x14,-0x10(%rbp)
jge    124e <GenerateEratosthenesSieve+0x11e>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    1228 <GenerateEratosthenesSieve+0xf8>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
sub    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0xc(%rbp),%edi
mov    $0x2,%esi
call   1040 <pow@plt>
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
imul   -0xc(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
jmp    11e8 <GenerateEratosthenesSieve+0xb8>
jmp    1253 <GenerateEratosthenesSieve+0x123>
jmp    1258 <GenerateEratosthenesSieve+0x128>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1194 <GenerateEratosthenesSieve+0x64>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GenerateEratosthenesSieve>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
mov    $0x48,%edi
call   1030 <malloc@plt>
mov    %rax,%r15
movaps 0xeb1(%rip),%xmm0
movups %xmm0,(%rax)
movups %xmm0,0x10(%rax)
movups %xmm0,0x20(%rax)
movups %xmm0,0x30(%rax)
movabs $0x100000001,%rax
mov    %rax,0x40(%r15)
mov    $0x14,%edi
call   1050 <sqrt@plt>
cmp    $0x3,%eax
jl     1209 <GenerateEratosthenesSieve+0xd9>
mov    $0x2,%ebx
mov    $0xfffffffe,%r12d
jmp    11a9 <GenerateEratosthenesSieve+0x79>
nopl   0x0(%rax)
add    $0x1,%rbx
mov    $0x14,%edi
call   1050 <sqrt@plt>
cltq
add    $0xffffffff,%r12d
cmp    %rax,%rbx
jge    1209 <GenerateEratosthenesSieve+0xd9>
cmpl   $0x1,-0x8(%r15,%rbx,4)
jne    1190 <GenerateEratosthenesSieve+0x60>
mov    %ebx,%edi
mov    $0x2,%esi
call   1040 <pow@plt>
cmp    $0x13,%eax
jg     1190 <GenerateEratosthenesSieve+0x60>
xor    %ebp,%ebp
jmp    11ed <GenerateEratosthenesSieve+0xbd>
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    $0x2,%esi
call   1040 <pow@plt>
mov    %eax,%ecx
lea    (%rcx,%rbp,1),%eax
add    %ebx,%ebp
add    %r12d,%ecx
add    %ebp,%ecx
cmp    $0x14,%ecx
jge    1190 <GenerateEratosthenesSieve+0x60>
cltq
cmpl   $0x1,-0x8(%r15,%rax,4)
jne    11d0 <GenerateEratosthenesSieve+0xa0>
add    $0xfffffffffffffffe,%rax
movl   $0x0,(%r15,%rax,4)
addl   $0xffffffff,(%r14)
jmp    11d0 <GenerateEratosthenesSieve+0xa0>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @GenerateEratosthenesSieve(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i32* %0, i32** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%7 = call i32* @malloc(i32 72)
store i32* %7, i32** %6
store i32 0, i32* %3
br label %8
8: ; preds = %16, %1
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 18
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load i32*, i32** %6
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
store i32 1, i32* %15
br label %16
16: ; preds = %11
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %8
19: ; preds = %8
store i32 2, i32* %3
br label %20
20: ; preds = %69, %19
%21 = load i32, i32* %3
%22 = call i32 @sqrt(i32 20)
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %72
24: ; preds = %20
%25 = load i32*, i32** %6
%26 = load i32, i32* %3
%27 = sub nsw i32 %26, 2
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %25, i64 %28
%30 = load i32, i32* %29
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %68
32: ; preds = %24
store i32 0, i32* %5
%33 = load i32, i32* %3
%34 = call i32 @pow(i32 %33, i32 2)
%35 = load i32, i32* %5
%36 = load i32, i32* %3
%37 = mul nsw i32 %35, %36
%38 = add nsw i32 %34, %37
store i32 %38, i32* %4
br label %39
39: ; preds = %59, %32
%40 = load i32, i32* %4
%41 = icmp slt i32 %40, 20
br i1 %41, label %42, label %67
42: ; preds = %39
%43 = load i32*, i32** %6
%44 = load i32, i32* %4
%45 = sub nsw i32 %44, 2
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %43, i64 %46
%48 = load i32, i32* %47
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %59
50: ; preds = %42
%51 = load i32*, i32** %6
%52 = load i32, i32* %4
%53 = sub nsw i32 %52, 2
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %51, i64 %54
store i32 0, i32* %55
%56 = load i32*, i32** %2
%57 = load i32, i32* %56
%58 = sub nsw i32 %57, 1
store i32 %58, i32* %56
br label %59
59: ; preds = %50, %42
%60 = load i32, i32* %3
%61 = call i32 @pow(i32 %60, i32 2)
%62 = load i32, i32* %5
%63 = add nsw i32 %62, 1
store i32 %63, i32* %5
%64 = load i32, i32* %3
%65 = mul nsw i32 %62, %64
%66 = add nsw i32 %61, %65
store i32 %66, i32* %4
br label %39
67: ; preds = %39
br label %68
68: ; preds = %67, %24
br label %69
69: ; preds = %68
%70 = load i32, i32* %3
%71 = add nsw i32 %70, 1
store i32 %71, i32* %3
br label %20
72: ; preds = %20
%73 = load i32*, i32** %6
ret i32* %73
}

LLVM IR (-O2):
define noalias i32* @GenerateEratosthenesSieve(i32* nocapture %0) {
%2 = tail call i32* @malloc(i32 72)
%3 = bitcast i32* %2 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %3
%4 = getelementptr inbounds i32, i32* %2, i64 4
%5 = bitcast i32* %4 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %5
%6 = getelementptr inbounds i32, i32* %2, i64 8
%7 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %7
%8 = getelementptr inbounds i32, i32* %2, i64 12
%9 = bitcast i32* %8 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %9
%10 = getelementptr inbounds i32, i32* %2, i64 16
store i32 1, i32* %10
%11 = getelementptr inbounds i32, i32* %2, i64 17
store i32 1, i32* %11
%12 = tail call i32 @sqrt(i32 20)
%13 = icmp sgt i32 %12, 2
br i1 %13, label %14, label %46
14: ; preds = %1, %41
%15 = phi i64 [ %42, %41 ], [ 2, %1 ]
%16 = add nsw i64 %15, -2
%17 = getelementptr inbounds i32, i32* %2, i64 %16
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %41
20: ; preds = %14
%21 = trunc i64 %15 to i32
%22 = tail call i32 @pow(i32 %21, i32 2)
%23 = icmp slt i32 %22, 20
br i1 %23, label %24, label %41
24: ; preds = %20, %35
%25 = phi i32 [ %37, %35 ], [ 0, %20 ]
%26 = phi i32 [ %39, %35 ], [ %22, %20 ]
%27 = add nsw i32 %26, -2
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %2, i64 %28
%30 = load i32, i32* %29
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %35
32: ; preds = %24
store i32 0, i32* %29
%33 = load i32, i32* %0
%34 = add nsw i32 %33, -1
store i32 %34, i32* %0
br label %35
35: ; preds = %32, %24
%36 = tail call i32 @pow(i32 %21, i32 2)
%37 = add nuw nsw i32 %25, 1
%38 = mul nsw i32 %25, %21
%39 = add nsw i32 %36, %38
%40 = icmp slt i32 %39, 20
br i1 %40, label %24, label %41
41: ; preds = %35, %20, %14
%42 = add nuw nsw i64 %15, 1
%43 = tail call i32 @sqrt(i32 20)
%44 = sext i32 %43 to i64
%45 = icmp slt i64 %42, %44
br i1 %45, label %14, label %46
46: ; preds = %41, %1
ret i32* %2
}