#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 *, ...);
void sieve(unsigned int max_number, bool *primes) {
  int i = 0, j = 0;
  printf("\nmax_number is %d", max_number);
  if (max_number < 2)
    return;
  for (i = 2; i <= max_number; i++) {
    if (primes[i]) {
      for (j = i * i; j <= max_number; j += i) {
        primes[j] = false;
      }
    }
  }
  printf("\nPrime numbers from 1 to %d are: ", max_number);
  for (i = 2; i <= max_number; i++) {
    if (primes[i] == true)
      printf("%d, ", i);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<sieve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%esi
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x2,-0x4(%rbp)
jae    114d <sieve+0x3d>
jmp    1225 <sieve+0x115>
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
ja     11bd <sieve+0xad>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     11aa <sieve+0x9a>
mov    -0x14(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
ja     11a5 <sieve+0x95>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    117c <sieve+0x6c>
jmp    11aa <sieve+0x9a>
jmp    11af <sieve+0x9f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1154 <sieve+0x44>
mov    -0x4(%rbp),%esi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
ja     1217 <sieve+0x107>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    1204 <sieve+0xf4>
mov    -0x14(%rbp),%esi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1209 <sieve+0xf9>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d5 <sieve+0xc5>
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sieve>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
lea    0xecb(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x2,%r14d
jae    1151 <sieve+0x31>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r14d,%eax
lea    0x1(%r14),%r12d
mov    $0x5,%ecx
mov    $0x2,%edx
mov    $0x4,%r8d
mov    $0x8,%edi
jmp    1183 <sieve+0x63>
nop
add    $0x1,%rdx
add    %ecx,%r8d
add    $0x2,%ecx
add    $0x4,%rdi
cmp    %r12,%rdx
je     11b3 <sieve+0x93>
cmpl   $0x0,(%r15,%rdx,4)
je     1170 <sieve+0x50>
mov    %edx,%esi
imul   %edx,%esi
cmp    %r14d,%esi
ja     1170 <sieve+0x50>
mov    %r8d,%ebx
lea    (%r15,%rbx,4),%rsi
nopl   0x0(%rax,%rax,1)
movl   $0x0,(%rsi)
add    %rdx,%rbx
add    %rdi,%rsi
cmp    %rax,%rbx
jbe    11a0 <sieve+0x80>
jmp    1170 <sieve+0x50>
lea    0xe58(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2,%ebx
lea    0xe64(%rip),%r14
jmp    11e9 <sieve+0xc9>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%r12
je     11fe <sieve+0xde>
cmpl   $0x1,(%r15,%rbx,4)
jne    11e0 <sieve+0xc0>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e0 <sieve+0xc0>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"\0Amax_number is %d\00"
@.str.1 = [34 x i8] c"\0APrime numbers from 1 to %d are: \00"
@.str.2 = [5 x i8] c"%d, \00"
@.str.3 = [2 x i8] c"\0A\00"
define void @sieve(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 0, i32* %5
store i32 0, i32* %6
%7 = load i32, i32* %3
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %3
%10 = icmp ult i32 %9, 2
br i1 %10, label %11, label %12
11: ; preds = %2
br label %69
12: ; preds = %2
store i32 2, i32* %5
br label %13
13: ; preds = %43, %12
%14 = load i32, i32* %5
%15 = load i32, i32* %3
%16 = icmp ule i32 %14, %15
br i1 %16, label %17, label %46
17: ; preds = %13
%18 = load i32*, i32** %4
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
%22 = load i32, i32* %21
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %42
24: ; preds = %17
%25 = load i32, i32* %5
%26 = load i32, i32* %5
%27 = mul nsw i32 %25, %26
store i32 %27, i32* %6
br label %28
28: ; preds = %37, %24
%29 = load i32, i32* %6
%30 = load i32, i32* %3
%31 = icmp ule i32 %29, %30
br i1 %31, label %32, label %41
32: ; preds = %28
%33 = load i32*, i32** %4
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
store i32 0, i32* %36
br label %37
37: ; preds = %32
%38 = load i32, i32* %5
%39 = load i32, i32* %6
%40 = add nsw i32 %39, %38
store i32 %40, i32* %6
br label %28
41: ; preds = %28
br label %42
42: ; preds = %41, %17
br label %43
43: ; preds = %42
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %13
46: ; preds = %13
%47 = load i32, i32* %3
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %47)
store i32 2, i32* %5
br label %49
49: ; preds = %64, %46
%50 = load i32, i32* %5
%51 = load i32, i32* %3
%52 = icmp ule i32 %50, %51
br i1 %52, label %53, label %67
53: ; preds = %49
%54 = load i32*, i32** %4
%55 = load i32, i32* %5
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %54, i64 %56
%58 = load i32, i32* %57
%59 = icmp eq i32 %58, 1
br i1 %59, label %60, label %63
60: ; preds = %53
%61 = load i32, i32* %5
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %60, %53
br label %64
64: ; preds = %63
%65 = load i32, i32* %5
%66 = add nsw i32 %65, 1
store i32 %66, i32* %5
br label %49
67: ; preds = %49
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %69
69: ; preds = %67, %11
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"\0Amax_number is %d\00"
@.str.1 = [34 x i8] c"\0APrime numbers from 1 to %d are: \00"
@.str.2 = [5 x i8] c"%d, \00"
define void @sieve(i32 %0, i32* nocapture %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %0)
%4 = icmp ult i32 %0, 2
br i1 %4, label %47, label %5
5: ; preds = %2
%6 = zext i32 %0 to i64
%7 = add i32 %0, 1
%8 = zext i32 %7 to i64
br label %9
9: ; preds = %5, %27
%10 = phi i64 [ 2, %5 ], [ %28, %27 ]
%11 = phi i32 [ 4, %5 ], [ %30, %27 ]
%12 = phi i32 [ 5, %5 ], [ %29, %27 ]
%13 = trunc i64 %10 to i32
%14 = getelementptr inbounds i32, i32* %1, i64 %10
%15 = load i32, i32* %14
%16 = icmp eq i32 %15, 0
%17 = mul nsw i32 %13, %13
%18 = icmp ugt i32 %17, %0
%19 = select i1 %16, i1 true, i1 %18
br i1 %19, label %27, label %20
20: ; preds = %9
%21 = zext i32 %11 to i64
br label %22
22: ; preds = %20, %22
%23 = phi i64 [ %21, %20 ], [ %25, %22 ]
%24 = getelementptr inbounds i32, i32* %1, i64 %23
store i32 0, i32* %24
%25 = add nuw i64 %23, %10
%26 = icmp ugt i64 %25, %6
br i1 %26, label %27, label %22
27: ; preds = %22, %9
%28 = add nuw nsw i64 %10, 1
%29 = add i32 %12, 2
%30 = add i32 %11, %12
%31 = icmp eq i64 %28, %8
br i1 %31, label %32, label %9
32: ; preds = %27
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %34
34: ; preds = %32, %42
%35 = phi i64 [ 2, %32 ], [ %43, %42 ]
%36 = getelementptr inbounds i32, i32* %1, i64 %35
%37 = load i32, i32* %36
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = trunc i64 %35 to i32
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %34, %39
%43 = add nuw nsw i64 %35, 1
%44 = icmp eq i64 %43, %8
br i1 %44, label %45, label %34
45: ; preds = %42
%46 = tail call i32 @putchar(i32 10)
br label %47
47: ; preds = %2, %45
ret void
}