#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 */
struct llu_list {
  int dummy;
};

/* Variables and functions */
unsigned char *calloc(unsigned long long, int);
int /*<<< orphan*/ llu_list_append(struct llu_list *, unsigned long long);
int /*<<< orphan*/ llu_list_free(struct llu_list *);
struct llu_list *llu_list_make(unsigned long long);
struct llu_list *llu_primes_less_than(unsigned long long N) {
  unsigned char *S;
  struct llu_list *L;
  unsigned long long i, j;
  L = llu_list_make(N / 2);
  if (L == NULL)
    return NULL;
  if (N >= 2)
    llu_list_append(L, 2);
  S = calloc(N, 1);
  if (S == NULL) {
    llu_list_free(L);
    return NULL;
  }
  for (i = 3; i < N; i += 2) {
    if (!S[i]) {
      llu_list_append(L, i);
      for (j = 0; j < N; j += i) {
        S[j] = 1;
      }
    }
  }
  return L;
}


x86 assembly (clang, -O0):
<llu_primes_less_than>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
shr    $0x1,%rdi
call   1040 <llu_list_make@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1175 <llu_primes_less_than+0x35>
movq   $0x0,-0x8(%rbp)
jmp    124c <llu_primes_less_than+0x10c>
cmpq   $0x2,-0x10(%rbp)
jb     118e <llu_primes_less_than+0x4e>
mov    -0x20(%rbp),%rdi
mov    $0x2,%esi
call   1050 <llu_list_append@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c1 <llu_primes_less_than+0x81>
mov    -0x20(%rbp),%rdi
call   1030 <llu_list_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    124c <llu_primes_less_than+0x10c>
movq   $0x3,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1244 <llu_primes_less_than+0x104>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
jne    122e <llu_primes_less_than+0xee>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <llu_list_append@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1229 <llu_primes_less_than+0xe9>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x1,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11fe <llu_primes_less_than+0xbe>
jmp    122e <llu_primes_less_than+0xee>
jmp    1233 <llu_primes_less_than+0xf3>
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
jmp    11c9 <llu_primes_less_than+0x89>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<llu_primes_less_than>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
shr    %rdi
call   1040 <llu_list_make@plt>
test   %rax,%rax
je     11c7 <llu_primes_less_than+0x87>
mov    %rax,%r14
cmp    $0x2,%r15
jb     116e <llu_primes_less_than+0x2e>
mov    $0x2,%esi
mov    %r14,%rdi
call   1050 <llu_list_append@plt>
mov    %r15,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
test   %rax,%rax
je     11bf <llu_primes_less_than+0x7f>
cmp    $0x4,%r15
jb     11ca <llu_primes_less_than+0x8a>
mov    %rax,%r12
mov    $0x3,%ebx
jmp    1199 <llu_primes_less_than+0x59>
add    $0x2,%rbx
cmp    %r15,%rbx
jae    11ca <llu_primes_less_than+0x8a>
cmpb   $0x0,(%r12,%rbx,1)
jne    1190 <llu_primes_less_than+0x50>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <llu_list_append@plt>
xor    %eax,%eax
nopl   (%rax)
movb   $0x1,(%r12,%rax,1)
add    %rbx,%rax
cmp    %r15,%rax
jb     11b0 <llu_primes_less_than+0x70>
jmp    1190 <llu_primes_less_than+0x50>
mov    %r14,%rdi
call   1030 <llu_list_free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.llu_list = type { i32 }
define %struct.llu_list* @llu_primes_less_than(i64 %0) {
%2 = alloca %struct.llu_list*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca %struct.llu_list*
%6 = alloca i64
%7 = alloca i64
store i64 %0, i64* %3
%8 = load i64, i64* %3
%9 = udiv i64 %8, 2
%10 = call %struct.llu_list* @llu_list_make(i64 %9)
store %struct.llu_list* %10, %struct.llu_list** %5
%11 = load %struct.llu_list*, %struct.llu_list** %5
%12 = icmp eq %struct.llu_list* %11, null
br i1 %12, label %13, label %14
13: ; preds = %1
store %struct.llu_list* null, %struct.llu_list** %2
br label %62
14: ; preds = %1
%15 = load i64, i64* %3
%16 = icmp uge i64 %15, 2
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load %struct.llu_list*, %struct.llu_list** %5
%19 = call i32 @llu_list_append(%struct.llu_list* %18, i64 2)
br label %20
20: ; preds = %17, %14
%21 = load i64, i64* %3
%22 = call i8* @calloc(i64 %21, i32 1)
store i8* %22, i8** %4
%23 = load i8*, i8** %4
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load %struct.llu_list*, %struct.llu_list** %5
%27 = call i32 @llu_list_free(%struct.llu_list* %26)
store %struct.llu_list* null, %struct.llu_list** %2
br label %62
28: ; preds = %20
store i64 3, i64* %6
br label %29
29: ; preds = %57, %28
%30 = load i64, i64* %6
%31 = load i64, i64* %3
%32 = icmp ult i64 %30, %31
br i1 %32, label %33, label %60
33: ; preds = %29
%34 = load i8*, i8** %4
%35 = load i64, i64* %6
%36 = getelementptr inbounds i8, i8* %34, i64 %35
%37 = load i8, i8* %36
%38 = icmp ne i8 %37, 0
br i1 %38, label %56, label %39
39: ; preds = %33
%40 = load %struct.llu_list*, %struct.llu_list** %5
%41 = load i64, i64* %6
%42 = call i32 @llu_list_append(%struct.llu_list* %40, i64 %41)
store i64 0, i64* %7
br label %43
43: ; preds = %51, %39
%44 = load i64, i64* %7
%45 = load i64, i64* %3
%46 = icmp ult i64 %44, %45
br i1 %46, label %47, label %55
47: ; preds = %43
%48 = load i8*, i8** %4
%49 = load i64, i64* %7
%50 = getelementptr inbounds i8, i8* %48, i64 %49
store i8 1, i8* %50
br label %51
51: ; preds = %47
%52 = load i64, i64* %6
%53 = load i64, i64* %7
%54 = add i64 %53, %52
store i64 %54, i64* %7
br label %43
55: ; preds = %43
br label %56
56: ; preds = %55, %33
br label %57
57: ; preds = %56
%58 = load i64, i64* %6
%59 = add i64 %58, 2
store i64 %59, i64* %6
br label %29
60: ; preds = %29
%61 = load %struct.llu_list*, %struct.llu_list** %5
store %struct.llu_list* %61, %struct.llu_list** %2
br label %62
62: ; preds = %60, %25, %13
%63 = load %struct.llu_list*, %struct.llu_list** %2
ret %struct.llu_list* %63
}

LLVM IR (-O2):
%struct.llu_list = type { i32 }
define %struct.llu_list* @llu_primes_less_than(i64 %0) {
%2 = lshr i64 %0, 1
%3 = tail call %struct.llu_list* @llu_list_make(i64 %2)
%4 = icmp eq %struct.llu_list* %3, null
br i1 %4, label %31, label %5
5: ; preds = %1
%6 = icmp ugt i64 %0, 1
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = tail call i32 @llu_list_append(%struct.llu_list* %3, i64 2)
br label %9
9: ; preds = %7, %5
%10 = tail call i8* @calloc(i64 %0, i32 1)
%11 = icmp eq i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = icmp ugt i64 %0, 3
br i1 %13, label %16, label %31
14: ; preds = %9
%15 = tail call i32 @llu_list_free(%struct.llu_list* %3)
br label %31
16: ; preds = %12, %28
%17 = phi i64 [ %29, %28 ], [ 3, %12 ]
%18 = getelementptr inbounds i8, i8* %10, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %16
%22 = tail call i32 @llu_list_append(%struct.llu_list* %3, i64 %17)
br label %23
23: ; preds = %21, %23
%24 = phi i64 [ 0, %21 ], [ %26, %23 ]
%25 = getelementptr inbounds i8, i8* %10, i64 %24
store i8 1, i8* %25
%26 = add i64 %24, %17
%27 = icmp ult i64 %26, %0
br i1 %27, label %23, label %28
28: ; preds = %23, %16
%29 = add i64 %17, 2
%30 = icmp ult i64 %29, %0
br i1 %30, label %16, label %31
31: ; preds = %28, %12, %1, %14
%32 = phi %struct.llu_list* [ null, %14 ], [ null, %1 ], [ %3, %12 ], [ %3, %28 ]
ret %struct.llu_list* %32
}