#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*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
void siebdesaratosthenes(int n) {
  int *array = (int *)malloc(sizeof(int) * n);
  memset(array, 0, n * sizeof(int));
  printf("Primzahlen:  => ");
  for (int i = 2; i < n; i++) {
    if (array[i] == 0) {
      printf("%d ", i);
      for (int j = i * i; j < n; j += i) {
        array[j] = 1;
      }
    }
  }
  free(array);
}


x86 assembly (clang, -O0):
<siebdesaratosthenes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1202 <siebdesaratosthenes+0xc2>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    11ef <siebdesaratosthenes+0xaf>
mov    -0x14(%rbp),%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ea <siebdesaratosthenes+0xaa>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11c1 <siebdesaratosthenes+0x81>
jmp    11ef <siebdesaratosthenes+0xaf>
jmp    11f4 <siebdesaratosthenes+0xb4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1188 <siebdesaratosthenes+0x48>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<siebdesaratosthenes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
lea    0x0(,%r15,4),%ebx
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1050 <memset@plt>
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x3,%r15d
jl     1212 <siebdesaratosthenes+0xd2>
mov    %r15d,%edx
mov    $0x2,%ebx
mov    $0x5,%r13d
mov    $0x4,%ebp
mov    $0x8,%r12d
mov    %r14,(%rsp)
jmp    11c4 <siebdesaratosthenes+0x84>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
add    %r13d,%ebp
add    $0x2,%r13
add    $0x4,%r12
cmp    %rdx,%rbx
je     1212 <siebdesaratosthenes+0xd2>
cmpl   $0x0,(%r14,%rbx,4)
jne    11b0 <siebdesaratosthenes+0x70>
lea    0xe3f(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
mov    %rdx,%r14
call   1040 <printf@plt>
mov    %r14,%rdx
mov    (%rsp),%r14
mov    %ebx,%eax
imul   %ebx,%eax
cmp    %r15d,%eax
jge    11b0 <siebdesaratosthenes+0x70>
mov    %ebp,%eax
lea    (%r14,%rax,4),%rax
mov    %ebp,%ecx
nopw   0x0(%rax,%rax,1)
movl   $0x1,(%rax)
add    %r12,%rax
add    %ebx,%ecx
cmp    %r15d,%ecx
jl     1200 <siebdesaratosthenes+0xc0>
jmp    11b0 <siebdesaratosthenes+0x70>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"Primzahlen: => \00"
@.str.1 = [4 x i8] c"%d \00"
define void @siebdesaratosthenes(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = sext i32 %6 to i64
%8 = mul i64 4, %7
%9 = trunc i64 %8 to i32
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 4
%16 = trunc i64 %15 to i32
%17 = call i32 @memset(i32* %12, i32 0, i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %4
br label %19
19: ; preds = %51, %1
%20 = load i32, i32* %4
%21 = load i32, i32* %2
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %54
23: ; preds = %19
%24 = load i32*, i32** %3
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %50
30: ; preds = %23
%31 = load i32, i32* %4
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %4
%34 = load i32, i32* %4
%35 = mul nsw i32 %33, %34
store i32 %35, i32* %5
br label %36
36: ; preds = %45, %30
%37 = load i32, i32* %5
%38 = load i32, i32* %2
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %49
40: ; preds = %36
%41 = load i32*, i32** %3
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
store i32 1, i32* %44
br label %45
45: ; preds = %40
%46 = load i32, i32* %4
%47 = load i32, i32* %5
%48 = add nsw i32 %47, %46
store i32 %48, i32* %5
br label %36
49: ; preds = %36
br label %50
50: ; preds = %49, %23
br label %51
51: ; preds = %50
%52 = load i32, i32* %4
%53 = add nsw i32 %52, 1
store i32 %53, i32* %4
br label %19
54: ; preds = %19
%55 = load i32*, i32** %3
%56 = call i32 @free(i32* %55)
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"Primzahlen: => \00"
@.str.1 = [4 x i8] c"%d \00"
define void @siebdesaratosthenes(i32 %0) {
%2 = shl i32 %0, 2
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i32*
%5 = tail call i32 @memset(i32* %4, i32 0, i32 %2)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%7 = icmp sgt i32 %0, 2
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = zext i32 %0 to i64
br label %12
10: ; preds = %32, %1
%11 = tail call i32 @free(i32* %4)
ret void
12: ; preds = %8, %32
%13 = phi i64 [ 5, %8 ], [ %34, %32 ]
%14 = phi i64 [ 2, %8 ], [ %33, %32 ]
%15 = phi i32 [ 4, %8 ], [ %36, %32 ]
%16 = getelementptr inbounds i32, i32* %4, i64 %14
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %32
19: ; preds = %12
%20 = trunc i64 %14 to i32
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = mul nsw i32 %20, %20
%23 = icmp slt i32 %22, %0
br i1 %23, label %24, label %32
24: ; preds = %19
%25 = zext i32 %15 to i64
br label %26
26: ; preds = %24, %26
%27 = phi i64 [ %29, %26 ], [ %25, %24 ]
%28 = getelementptr inbounds i32, i32* %4, i64 %27
store i32 1, i32* %28
%29 = add nuw nsw i64 %27, %14
%30 = trunc i64 %29 to i32
%31 = icmp slt i32 %30, %0
br i1 %31, label %26, label %32
32: ; preds = %26, %19, %12
%33 = add nuw nsw i64 %14, 1
%34 = add nuw nsw i64 %13, 2
%35 = trunc i64 %13 to i32
%36 = add i32 %15, %35
%37 = icmp eq i64 %33, %9
br i1 %37, label %10, label %12
}