#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 prime(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int limit;
  int column;
  int primeNum;
  int i;
  int row;
  printf("Table of Primes\n");
  printf("===============\n");
  printf("Upper limit  :	");
  scanf("%d", &limit);
  printf("# of columns :	");
  scanf("%d", &column);
  for (i = 2; i <= limit; i++) {
    primeNum = prime(i);
    if (primeNum == 1) {
      printf("%d\t", i);
      row = row + 1;
    }
    if (row == column) {
      printf("\n");
      row = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec2(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea4(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     120d <main+0xdd>
mov    -0x14(%rbp),%edi
call   1050 <prime@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    11d9 <main+0xa9>
mov    -0x14(%rbp),%esi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    11fa <main+0xca>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
jmp    11ff <main+0xcf>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119e <main+0x6e>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec8(%rip),%rdi
call   1040 <puts@plt>
lea    0xecc(%rip),%rdi
call   1040 <puts@plt>
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe8b(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xe7a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
cmpl   $0x2,0x8(%rsp)
jge    11bf <main+0x6f>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0x1,%ebx
lea    0xe58(%rip),%r14
jmp    11d6 <main+0x86>
nopl   (%rax)
cmp    0x8(%rsp),%ebx
jge    11b4 <main+0x64>
add    $0x1,%ebx
mov    %ebx,%edi
call   1070 <prime@plt>
cmp    $0x1,%eax
je     11f0 <main+0xa0>
cmp    0xc(%rsp),%ebp
jne    11d0 <main+0x80>
jmp    1205 <main+0xb5>
nopl   (%rax)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebp
cmp    0xc(%rsp),%ebp
jne    11d0 <main+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebp,%ebp
jmp    11d0 <main+0x80>

LLVM IR (-O0):
@.str = [17 x i8] c"Table of Primes\0A\00"
@.str.1 = [17 x i8] c"===============\0A\00"
@.str.2 = [16 x i8] c"Upper limit :\09\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [16 x i8] c"# of columns :\09\00"
@.str.5 = [4 x i8] c"%d\09\00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
store i32 2, i32* %5
br label %13
13: ; preds = %34, %0
%14 = load i32, i32* %5
%15 = load i32, i32* %2
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %37
17: ; preds = %13
%18 = load i32, i32* %5
%19 = call i32 @prime(i32 %18)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i32, i32* %5
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %27
27: ; preds = %22, %17
%28 = load i32, i32* %6
%29 = load i32, i32* %3
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %6
br label %33
33: ; preds = %31, %27
br label %34
34: ; preds = %33
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %13
37: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [16 x i8] c"Upper limit :\09\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [16 x i8] c"# of columns :\09\00"
@.str.5 = [4 x i8] c"%d\09\00"
@str = [16 x i8] c"Table of Primes\00"
@str.7 = [16 x i8] c"===============\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %1
%12 = icmp slt i32 %11, 2
br i1 %12, label %32, label %13
13: ; preds = %0, %27
%14 = phi i32 [ %28, %27 ], [ undef, %0 ]
%15 = phi i32 [ %29, %27 ], [ 2, %0 ]
%16 = call i32 @prime(i32 %15)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %15)
%20 = add nsw i32 %14, 1
br label %21
21: ; preds = %18, %13
%22 = phi i32 [ %20, %18 ], [ %14, %13 ]
%23 = load i32, i32* %2
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @putchar(i32 10)
br label %27
27: ; preds = %21, %25
%28 = phi i32 [ 0, %25 ], [ %22, %21 ]
%29 = add nuw nsw i32 %15, 1
%30 = load i32, i32* %1
%31 = icmp slt i32 %15, %30
br i1 %31, label %13, label %32
32: ; preds = %27, %0
ret i32 0
}