#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*/ Erastothenes(int, int *, int *);
int atoi(char *);
int binary(int);
int /*<<< orphan*/ free(int *);
int isPrime(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int, ...);
int main(int argc, char *argv[]) {
  int N = 999, l;
  int i;
  if (argc > 1) {
    N = atoi(argv[1]);
  }
  if (l = isPrime(N)) {
    printf("%d is NOT a prime number(%d)\n", N, l);
  } else {
    printf("%d IS a prime number\n", N);
  }
  printf("%d=>binary(%d)\n", N, binary(N));
  int *primes = (int *)malloc(sizeof(int) * N);
  int len = 0;
  memset(primes, 0, N * sizeof(int));
  Erastothenes(N, primes, &len);
  for (i = 0; i < len; ++i) {
    printf("%d\n", *(primes + i));
  }
  free(primes);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x3e7,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11b7 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <isPrime@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     11e4 <main+0x64>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    11f5 <main+0x75>
mov    -0x14(%rbp),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <binary@plt>
mov    -0x30(%rbp),%esi
mov    %eax,%edx
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1040 <Erastothenes@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    128f <main+0x10f>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    125c <main+0xdc>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x3e7,%r14d
cmp    $0x2,%edi
jl     119f <main+0x1f>
mov    0x8(%rsi),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r14d
mov    %r14d,%edi
call   1080 <isPrime@plt>
test   %eax,%eax
je     11c0 <main+0x40>
lea    0xe4e(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11d1 <main+0x51>
lea    0xe57(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%edi
call   1050 <binary@plt>
lea    0xe54(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x0(,%r14,4),%ebp
mov    %ebp,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
movl   $0x0,0xc(%rsp)
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1070 <memset@plt>
lea    0xc(%rsp),%rdx
mov    %r14d,%edi
mov    %rbx,%rsi
call   1040 <Erastothenes@plt>
cmpl   $0x0,0xc(%rsp)
jle    125b <main+0xdb>
lea    0xe14(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rbx,%rbp,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
cmp    %rax,%rbp
jl     1240 <main+0xc0>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"%d is NOT a prime number(%d)\0A\00"
@.str.1 = [22 x i8] c"%d IS a prime number\0A\00"
@.str.2 = [16 x i8] c"%d=>binary(%d)\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 999, i32* %6
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %6
br label %18
18: ; preds = %13, %2
%19 = load i32, i32* %6
%20 = call i32 @isPrime(i32 %19)
store i32 %20, i32* %7
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i32, i32* %6
%24 = load i32, i32* %7
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %24)
br label %29
26: ; preds = %18
%27 = load i32, i32* %6
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %26, %22
%30 = load i32, i32* %6
%31 = load i32, i32* %6
%32 = call i32 @binary(i32 %31)
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %32)
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = mul i64 4, %35
%37 = trunc i64 %36 to i32
%38 = call i64 @malloc(i32 %37)
%39 = inttoptr i64 %38 to i32*
store i32* %39, i32** %9
store i32 0, i32* %10
%40 = load i32*, i32** %9
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = mul i64 %42, 4
%44 = trunc i64 %43 to i32
%45 = call i32 @memset(i32* %40, i32 0, i32 %44)
%46 = load i32, i32* %6
%47 = load i32*, i32** %9
%48 = call i32 @Erastothenes(i32 %46, i32* %47, i32* %10)
store i32 0, i32* %8
br label %49
49: ; preds = %60, %29
%50 = load i32, i32* %8
%51 = load i32, i32* %10
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %63
53: ; preds = %49
%54 = load i32*, i32** %9
%55 = load i32, i32* %8
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %54, i64 %56
%58 = load i32, i32* %57
%59 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %53
%61 = load i32, i32* %8
%62 = add nsw i32 %61, 1
store i32 %62, i32* %8
br label %49
63: ; preds = %49
%64 = load i32*, i32** %9
%65 = call i32 @free(i32* %64)
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"%d is NOT a prime number(%d)\0A\00"
@.str.1 = [22 x i8] c"%d IS a prime number\0A\00"
@.str.2 = [16 x i8] c"%d=>binary(%d)\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
br label %9
9: ; preds = %5, %2
%10 = phi i32 [ %8, %5 ], [ 999, %2 ]
%11 = tail call i32 @isPrime(i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %11)
br label %17
15: ; preds = %9
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %17
17: ; preds = %15, %13
%18 = tail call i32 @binary(i32 %10)
%19 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %10, i32 %18)
%20 = shl i32 %10, 2
%21 = tail call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i32*
%23 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%24 = tail call i32 @memset(i32* %22, i32 0, i32 %20)
%25 = call i32 @Erastothenes(i32 %10, i32* %22, i32* %3)
%26 = load i32, i32* %3
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %17, %28
%29 = phi i64 [ %33, %28 ], [ 0, %17 ]
%30 = getelementptr inbounds i32, i32* %22, i64 %29
%31 = load i32, i32* %30
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = add nuw nsw i64 %29, 1
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = icmp slt i64 %33, %35
br i1 %36, label %28, label %37
37: ; preds = %28, %17
%38 = call i32 @free(i32* %22)
ret i32 0
}