#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*/ grow(int *, int, int);
int isPrime(int);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, int *);
int main(int argc, char **argv) {
  int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
  int n;
  int rc;
  int case_num = 1;
  int i;
  while ((rc = scanf("%d", &n) == 1)) {
    if (case_num != 1) {
      printf("\n");
    }
    printf("Case %d:\n", case_num);
    int ring[n];
    for (i = 0; i < n; i++) {
      ring[i] = 0;
    }
    if (n == 1) {
      printf("1\n");
    }
    ring[0] = 1;
    for (i = 2; i < n + 1; i = i + 1) {
      if ((rc = isPrime(1 + i)) == 1) {
        grow(ring, i, n);
      }
    }
    case_num = case_num + 1;
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe8f(%rip),%rsi
mov    $0x2c,%edx
call   1060 <memcpy@plt>
movl   $0x1,-0x4c(%rbp)
lea    0xea3(%rip),%rdi
lea    -0x44(%rbp),%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
sete   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x48(%rbp)
test   $0x1,%al
jne    11b0 <main+0x60>
jmp    12b8 <main+0x168>
cmpl   $0x1,-0x4c(%rbp)
je     11c8 <main+0x78>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4c(%rbp),%esi
lea    0xe5d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x44(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x58(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x60(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1230 <main+0xe0>
mov    -0x68(%rbp),%rax
movslq -0x50(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1207 <main+0xb7>
cmpl   $0x1,-0x44(%rbp)
jne    1248 <main+0xf8>
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x68(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x2,-0x50(%rbp)
mov    -0x50(%rbp),%eax
mov    -0x44(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    12a3 <main+0x153>
mov    -0x50(%rbp),%edi
add    $0x1,%edi
call   1050 <isPrime@plt>
mov    %eax,-0x48(%rbp)
cmp    $0x1,%eax
jne    1290 <main+0x140>
mov    -0x68(%rbp),%rdi
mov    -0x50(%rbp),%esi
mov    -0x44(%rbp),%edx
call   1030 <grow@plt>
jmp    1295 <main+0x145>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1259 <main+0x109>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,%rsp
jmp    1182 <main+0x32>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe7b(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1090 <scanf@plt>
cmp    $0x1,%eax
jne    128e <main+0x11e>
mov    $0x1,%r13d
jmp    11c7 <main+0x57>
nop
movl   $0x1,(%r15)
mov    %r12,%rsp
add    $0x1,%r13d
lea    0xe4b(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1090 <scanf@plt>
cmp    $0x1,%eax
jne    128e <main+0x11e>
cmp    $0x1,%r13d
je     11d7 <main+0x67>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe25(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%r12
mov    -0x2c(%rbp),%eax
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    -0x2c(%rbp),%ebx
test   %ebx,%ebx
jle    11a0 <main+0x30>
mov    %rbx,%rdx
shl    $0x2,%rdx
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
cmp    $0x1,%ebx
jne    1250 <main+0xe0>
lea    0xde6(%rip),%rdi
call   1040 <puts@plt>
mov    -0x2c(%rbp),%eax
movl   $0x1,(%r15)
cmp    $0x2,%eax
jl     11a7 <main+0x37>
jmp    1257 <main+0xe7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movl   $0x1,(%r15)
mov    $0x1,%r14d
jmp    126a <main+0xfa>
nop
cmp    -0x2c(%rbp),%r14d
jge    11a7 <main+0x37>
mov    %r14d,%edi
lea    0x1(%rdi),%r14d
add    $0x2,%edi
call   1080 <isPrime@plt>
cmp    $0x1,%eax
jne    1260 <main+0xf0>
mov    -0x2c(%rbp),%edx
mov    %r15,%rdi
mov    %r14d,%esi
call   1050 <grow@plt>
jmp    1260 <main+0xf0>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.primes = [11 x i32] [i32 2, i32 3, i32 5, i32 7, i32 11, i32 13, i32 17, i32 19, i32 23, i32 29, i32 31]
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [10 x i8] c"Case %d:\0A\00"
@.str.3 = [3 x i8] c"1\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [11 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast [11 x i32]* %6 to i8*
store i32 1, i32* %9
br label %14
14: ; preds = %66, %2
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%16 = icmp eq i32 %15, 1
%17 = zext i1 %16 to i32
store i32 %17, i32* %8
br i1 %16, label %18, label %70
18: ; preds = %14
%19 = load i32, i32* %9
%20 = icmp ne i32 %19, 1
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = load i32, i32* %9
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %7
%27 = zext i32 %26 to i64
%28 = call i8* @llvm.stacksave()
store i8* %28, i8** %11
%29 = alloca i32, i64 %27
store i64 %27, i64* %12
store i32 0, i32* %10
br label %30
30: ; preds = %38, %23
%31 = load i32, i32* %10
%32 = load i32, i32* %7
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %41
34: ; preds = %30
%35 = load i32, i32* %10
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %29, i64 %36
store i32 0, i32* %37
br label %38
38: ; preds = %34
%39 = load i32, i32* %10
%40 = add nsw i32 %39, 1
store i32 %40, i32* %10
br label %30
41: ; preds = %30
%42 = load i32, i32* %7
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %46
46: ; preds = %44, %41
%47 = getelementptr inbounds i32, i32* %29, i64 0
store i32 1, i32* %47
store i32 2, i32* %10
br label %48
48: ; preds = %63, %46
%49 = load i32, i32* %10
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
%52 = icmp slt i32 %49, %51
br i1 %52, label %53, label %66
53: ; preds = %48
%54 = load i32, i32* %10
%55 = add nsw i32 1, %54
%56 = call i32 @isPrime(i32 %55)
store i32 %56, i32* %8
%57 = icmp eq i32 %56, 1
br i1 %57, label %58, label %62
58: ; preds = %53
%59 = load i32, i32* %10
%60 = load i32, i32* %7
%61 = call i32 @grow(i32* %29, i32 %59, i32 %60)
br label %62
62: ; preds = %58, %53
br label %63
63: ; preds = %62
%64 = load i32, i32* %10
%65 = add nsw i32 %64, 1
store i32 %65, i32* %10
br label %48
66: ; preds = %48
%67 = load i32, i32* %9
%68 = add nsw i32 %67, 1
store i32 %68, i32* %9
%69 = load i8*, i8** %11
br label %14
70: ; preds = %14
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.2 = [10 x i8] c"Case %d:\0A\00"
@str = [2 x i8] c"1\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %47
7: ; preds = %2, %43
%8 = phi i32 [ %44, %43 ], [ 1, %2 ]
%9 = icmp eq i32 %8, 1
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 @putchar(i32 10)
br label %12
12: ; preds = %10, %7
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%14 = load i32, i32* %3
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
%17 = alloca i32, i64 %15
%18 = load i32, i32* %3
%19 = icmp sgt i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %12
store i32 1, i32* %17
br label %43
21: ; preds = %12
%22 = bitcast i32* %17 to i8*
%23 = zext i32 %18 to i64
%24 = shl nuw nsw i64 %23, 2
%25 = icmp eq i32 %18, 1
br i1 %25, label %27, label %26
26: ; preds = %21
store i32 1, i32* %17
br label %31
27: ; preds = %21
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%29 = load i32, i32* %3
store i32 1, i32* %17
%30 = icmp slt i32 %29, 2
br i1 %30, label %43, label %31
31: ; preds = %26, %27
br label %32
32: ; preds = %31, %40
%33 = phi i32 [ %34, %40 ], [ 2, %31 ]
%34 = add nuw nsw i32 %33, 1
%35 = call i32 @isPrime(i32 %34)
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i32, i32* %3
%39 = call i32 @grow(i32* %17, i32 %33, i32 %38)
br label %40
40: ; preds = %32, %37
%41 = load i32, i32* %3
%42 = icmp slt i32 %33, %41
br i1 %42, label %32, label %43
43: ; preds = %40, %20, %27
%44 = add nuw nsw i32 %8, 1
%45 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%46 = icmp eq i32 %45, 1
br i1 %46, label %7, label %47
47: ; preds = %43, %2
ret i32 0
}