#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ memset(int *, int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
void print_primes(int min, int max) {
  int *composite_numbers = malloc(sizeof(int) * (max + 1));
  if (composite_numbers == NULL) {
    fprintf(stderr, "Insufficient memory\n");
    exit(EXIT_FAILURE);
  }
  int i;
  enum { PRIME, NON_PRIME };
  memset(composite_numbers, PRIME, (max + 1) * sizeof(int));
  for (i = 2; i <= max; i++) {
    if (composite_numbers[i] == NON_PRIME)
      continue;
    if (i >= min)
      printf("%d\n", i);
    int j;
    for (j = 2 * i; j <= max; j += i)
      composite_numbers[j] = NON_PRIME;
  }
  free(composite_numbers);
}


x86 assembly (clang, -O0):
<print_primes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b3 <print_primes+0x53>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1256 <print_primes+0xf6>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    11f6 <print_primes+0x96>
jmp    1248 <print_primes+0xe8>
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jl     1211 <print_primes+0xb1>
mov    -0x14(%rbp),%esi
lea    0xe09(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1243 <print_primes+0xe3>
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    121a <print_primes+0xba>
jmp    1248 <print_primes+0xe8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d3 <print_primes+0x73>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_primes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r15d
mov    %edi,%ebx
lea    0x4(,%r15,4),%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1242 <print_primes+0xe2>
mov    %rax,%r12
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1050 <memset@plt>
cmp    $0x2,%r15d
jge    11b6 <print_primes+0x56>
mov    %r12,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
movslq %ebx,%rdx
lea    0x1(%r15),%esi
mov    %r12,%r14
add    $0x10,%r14
mov    $0x2,%ebx
mov    $0x8,%r13d
mov    $0x4,%ebp
mov    %r12,0x10(%rsp)
mov    %rsi,0x8(%rsp)
jmp    11f4 <print_primes+0x94>
add    $0x1,%rbx
add    $0x8,%r14
add    $0x4,%r13
add    $0x2,%ebp
cmp    %rsi,%rbx
je     11a0 <print_primes+0x40>
cmpl   $0x1,(%r12,%rbx,4)
je     11e0 <print_primes+0x80>
cmp    %rdx,%rbx
jl     121e <print_primes+0xbe>
lea    0xe0e(%rip),%rdi
mov    %ebx,%esi
mov    %rdx,%r12
call   1040 <printf@plt>
mov    0x8(%rsp),%rsi
mov    %r12,%rdx
mov    0x10(%rsp),%r12
lea    (%rbx,%rbx,1),%eax
cmp    %r15d,%eax
jg     11e0 <print_primes+0x80>
mov    %ebp,%eax
mov    %r14,%rcx
nopl   0x0(%rax,%rax,1)
movl   $0x1,(%rcx)
add    %r13,%rcx
add    %ebx,%eax
cmp    %r15d,%eax
jle    1230 <print_primes+0xd0>
jmp    11e0 <print_primes+0x80>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
lea    0xdae(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"Insufficient memory\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
define void @print_primes(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = add nsw i32 %8, 1
%10 = sext i32 %9 to i64
%11 = mul i64 4, %10
%12 = trunc i64 %11 to i32
%13 = call i32* @malloc(i32 %12)
store i32* %13, i32** %5
%14 = load i32*, i32** %5
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i32*, i32** %5
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = mul i64 %25, 4
%27 = trunc i64 %26 to i32
%28 = call i32 @memset(i32* %22, i32 0, i32 %27)
store i32 2, i32* %6
br label %29
29: ; preds = %65, %21
%30 = load i32, i32* %6
%31 = load i32, i32* %4
%32 = icmp sle i32 %30, %31
br i1 %32, label %33, label %68
33: ; preds = %29
%34 = load i32*, i32** %5
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %37
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %41
40: ; preds = %33
br label %65
41: ; preds = %33
%42 = load i32, i32* %6
%43 = load i32, i32* %3
%44 = icmp sge i32 %42, %43
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32, i32* %6
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %45, %41
%49 = load i32, i32* %6
%50 = mul nsw i32 2, %49
store i32 %50, i32* %7
br label %51
51: ; preds = %60, %48
%52 = load i32, i32* %7
%53 = load i32, i32* %4
%54 = icmp sle i32 %52, %53
br i1 %54, label %55, label %64
55: ; preds = %51
%56 = load i32*, i32** %5
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %56, i64 %58
store i32 1, i32* %59
br label %60
60: ; preds = %55
%61 = load i32, i32* %6
%62 = load i32, i32* %7
%63 = add nsw i32 %62, %61
store i32 %63, i32* %7
br label %51
64: ; preds = %51
br label %65
65: ; preds = %64, %40
%66 = load i32, i32* %6
%67 = add nsw i32 %66, 1
store i32 %67, i32* %6
br label %29
68: ; preds = %29
%69 = load i32*, i32** %5
%70 = call i32 @free(i32* %69)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"Insufficient memory\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
define void @print_primes(i32 %0, i32 %1) {
%3 = shl i32 %1, 2
%4 = add i32 %3, 4
%5 = tail call i32* @malloc(i32 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = tail call i32 @memset(i32* %5, i32 0, i32 %4)
%14 = icmp slt i32 %1, 2
br i1 %14, label %44, label %15
15: ; preds = %12
%16 = sext i32 %0 to i64
%17 = add nuw nsw i32 %1, 1
%18 = zext i32 %17 to i64
br label %19
19: ; preds = %15, %40
%20 = phi i64 [ 2, %15 ], [ %41, %40 ]
%21 = phi i64 [ 4, %15 ], [ %42, %40 ]
%22 = getelementptr inbounds i32, i32* %5, i64 %20
%23 = load i32, i32* %22
%24 = icmp eq i32 %23, 1
br i1 %24, label %40, label %25
25: ; preds = %19
%26 = icmp slt i64 %20, %16
br i1 %26, label %30, label %27
27: ; preds = %25
%28 = trunc i64 %20 to i32
%29 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %27, %25
%31 = trunc i64 %20 to i32
%32 = shl i32 %31, 1
%33 = icmp sgt i32 %32, %1
br i1 %33, label %40, label %34
34: ; preds = %30, %34
%35 = phi i64 [ %37, %34 ], [ %21, %30 ]
%36 = getelementptr inbounds i32, i32* %5, i64 %35
store i32 1, i32* %36
%37 = add nuw nsw i64 %35, %20
%38 = trunc i64 %37 to i32
%39 = icmp sgt i32 %38, %1
br i1 %39, label %40, label %34
40: ; preds = %34, %30, %19
%41 = add nuw nsw i64 %20, 1
%42 = add nuw nsw i64 %21, 2
%43 = icmp eq i64 %41, %18
br i1 %43, label %44, label %19
44: ; preds = %40, %12
%45 = tail call i32 @free(i32* %5)
ret void
}