#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ memoryCheck();
unsigned char *prime(int n) {
  int i, j, remainder;
  unsigned char *primeNumber;
  if ((primeNumber = (unsigned char *)calloc(n, sizeof(unsigned char))) == NULL)
    memoryCheck();
  primeNumber[0] = 0;
  primeNumber[1] = 1;
  for (j = 2; j <= n; j++) {
    primeNumber[j] = 1;
    for (i = 2; i < j; i++) {
      remainder = j % i;
      if ((remainder == 0)) {
        primeNumber[j] = 0;
        break;
      }
    }
  }
  return primeNumber;
}


x86 assembly (clang, -O0):
<prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    114d <prime+0x2d>
mov    $0x0,%al
call   1040 <memoryCheck@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x1,0x1(%rax)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11d9 <prime+0xb9>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x1,(%rax,%rcx,1)
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c6 <prime+0xa6>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11b3 <prime+0x93>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11c6 <prime+0xa6>
jmp    11b8 <prime+0x98>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1182 <prime+0x62>
jmp    11cb <prime+0xab>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1163 <prime+0x43>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prime>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%r14d
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1141 <prime+0x21>
xor    %eax,%eax
call   1040 <memoryCheck@plt>
movw   $0x100,(%r15)
cmp    $0x2,%r14d
jge    1156 <prime+0x36>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
add    $0x1,%r14d
mov    $0x2,%ecx
xor    %esi,%esi
jmp    1182 <prime+0x62>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x0,(%r15,%rcx,1)
add    $0x1,%rcx
add    $0x1,%rsi
cmp    %r14,%rcx
je     114d <prime+0x2d>
movb   $0x1,(%r15,%rcx,1)
cmp    $0x3,%rcx
jb     1175 <prime+0x55>
xor    %edi,%edi
nop
lea    0x2(%rdi),%ebx
mov    %ecx,%eax
xor    %edx,%edx
div    %ebx
test   %edx,%edx
je     1170 <prime+0x50>
add    $0x1,%rdi
cmp    %rdi,%rsi
jne    1190 <prime+0x70>
jmp    1175 <prime+0x55>

LLVM IR (-O0):
define i8* @prime(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = call i64 @calloc(i32 %7, i32 1)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %6
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 (...) @memoryCheck()
br label %13
13: ; preds = %11, %1
%14 = load i8*, i8** %6
%15 = getelementptr inbounds i8, i8* %14, i64 0
store i8 0, i8* %15
%16 = load i8*, i8** %6
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8 1, i8* %17
store i32 2, i32* %4
br label %18
18: ; preds = %47, %13
%19 = load i32, i32* %4
%20 = load i32, i32* %2
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %50
22: ; preds = %18
%23 = load i8*, i8** %6
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 1, i8* %26
store i32 2, i32* %3
br label %27
27: ; preds = %43, %22
%28 = load i32, i32* %3
%29 = load i32, i32* %4
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %46
31: ; preds = %27
%32 = load i32, i32* %4
%33 = load i32, i32* %3
%34 = srem i32 %32, %33
store i32 %34, i32* %5
%35 = load i32, i32* %5
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %31
%38 = load i8*, i8** %6
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 0, i8* %41
br label %46
42: ; preds = %31
br label %43
43: ; preds = %42
%44 = load i32, i32* %3
%45 = add nsw i32 %44, 1
store i32 %45, i32* %3
br label %27
46: ; preds = %37, %27
br label %47
47: ; preds = %46
%48 = load i32, i32* %4
%49 = add nsw i32 %48, 1
store i32 %49, i32* %4
br label %18
50: ; preds = %18
%51 = load i8*, i8** %6
ret i8* %51
}

LLVM IR (-O2):
define i8* @prime(i32 %0) {
%2 = tail call i64 @calloc(i32 %0, i32 1)
%3 = inttoptr i64 %2 to i8*
%4 = icmp eq i64 %2, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 (...) @memoryCheck()
br label %7
7: ; preds = %5, %1
store i8 0, i8* %3
%8 = getelementptr inbounds i8, i8* %3, i64 1
store i8 1, i8* %8
%9 = icmp slt i32 %0, 2
br i1 %9, label %31, label %10
10: ; preds = %7
%11 = add nuw i32 %0, 1
%12 = zext i32 %11 to i64
br label %13
13: ; preds = %10, %28
%14 = phi i64 [ 2, %10 ], [ %29, %28 ]
%15 = getelementptr inbounds i8, i8* %3, i64 %14
store i8 1, i8* %15
%16 = icmp ugt i64 %14, 2
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = trunc i64 %14 to i32
br label %22
19: ; preds = %22
%20 = zext i32 %26 to i64
%21 = icmp eq i64 %14, %20
br i1 %21, label %28, label %22
22: ; preds = %17, %19
%23 = phi i32 [ %26, %19 ], [ 2, %17 ]
%24 = urem i32 %18, %23
%25 = icmp eq i32 %24, 0
%26 = add nuw nsw i32 %23, 1
br i1 %25, label %27, label %19
27: ; preds = %22
store i8 0, i8* %15
br label %28
28: ; preds = %19, %13, %27
%29 = add nuw nsw i64 %14, 1
%30 = icmp eq i64 %29, %12
br i1 %30, label %31, label %13
31: ; preds = %28, %7
ret i8* %3
}