#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*/ printf(char *, int);
int sieve_of_eratosthenes(int **, int);
int main() {
  int n = 100, i;
  int *primes = NULL;
  int size = sieve_of_eratosthenes(&primes, n);
  printf("Primes up to %d are:\n", n);
  for (i = 0; i < size; ++i) {
    printf("%d\n", primes[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%esi
lea    -0x18(%rbp),%rdi
call   1040 <sieve_of_eratosthenes@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%esi
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1194 <main+0x74>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1163 <main+0x43>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x64,%esi
call   1040 <sieve_of_eratosthenes@plt>
mov    %eax,%ebx
lea    0xeb6(%rip),%rdi
mov    $0x64,%esi
call   1030 <printf@plt>
test   %ebx,%ebx
jle    1189 <main+0x69>
mov    %ebx,%r15d
xor    %ebx,%ebx
lea    0xeb2(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,4),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1170 <main+0x50>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Primes up to %d are:\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32 0, i32* %1
store i32 100, i32* %2
store i32* null, i32** %4
%6 = load i32, i32* %2
%7 = call i32 @sieve_of_eratosthenes(i32** %4, i32 %6)
store i32 %7, i32* %5
%8 = load i32, i32* %2
%9 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 0, i32* %3
br label %10
10: ; preds = %21, %0
%11 = load i32, i32* %3
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = load i32*, i32** %4
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %14
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %10
24: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"Primes up to %d are:\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32*
%2 = bitcast i32** %1 to i8*
store i32* null, i32** %1
%3 = call i32 @sieve_of_eratosthenes(i32** %1, i32 100)
%4 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 100)
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %16
6: ; preds = %0
%7 = zext i32 %3 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %14, %8 ]
%10 = load i32*, i32** %1
%11 = getelementptr inbounds i32, i32* %10, i64 %9
%12 = load i32, i32* %11
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = add nuw nsw i64 %9, 1
%15 = icmp eq i64 %14, %7
br i1 %15, label %16, label %8
16: ; preds = %8, %0
ret i32 0
}