#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 *);
void main() {
  int n, i, j = 0;
  printf("n:");
  scanf("%d", &n);
  printf("Ð¡ÓÚµÈÓÚ%dµÄËØÊý:\n", n);
  if (n >= 2) {
    printf("%4d", 2);
    j++;
  }
  for (i = 3; i <= n; i += 1)
    if (prime(i) == 1) {
      printf("%4d", i);
      if (j != 0 && ++j % 10 == 0)
        printf("\n");
    }
  printf("\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeaf(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x4(%rbp),%esi
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x2,-0x4(%rbp)
jl     1194 <main+0x64>
lea    0xea8(%rip),%rdi
mov    $0x2,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movl   $0x3,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1213 <main+0xe3>
mov    -0x8(%rbp),%edi
call   1050 <prime@plt>
cmp    $0x1,%eax
jne    1200 <main+0xd0>
mov    -0x8(%rbp),%esi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
je     11fb <main+0xcb>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11fb <main+0xcb>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1200 <main+0xd0>
jmp    1205 <main+0xd5>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    119b <main+0x6b>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeb2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea7(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%esi
lea    0xe95(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x2,0x4(%rsp)
jl     119f <main+0x5f>
lea    0xea1(%rip),%rdi
mov    $0x2,%r15d
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x3,0x4(%rsp)
jge    11b4 <main+0x74>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebp
lea    0xe67(%rip),%r14
jmp    11db <main+0x9b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%ebx
mov    %ebx,%ebp
cmp    0x4(%rsp),%r15d
jge    119f <main+0x5f>
add    $0x1,%r15d
mov    %r15d,%edi
call   1060 <prime@plt>
cmp    $0x1,%eax
jne    11d0 <main+0x90>
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
je     11d2 <main+0x92>
add    $0x1,%ebp
imul   $0xcccccccd,%ebp,%eax
add    $0x19999998,%eax
ror    %eax
cmp    $0x19999998,%eax
ja     11d0 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11d0 <main+0x90>

LLVM IR (-O0):
@.str = [3 x i8] c"n:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"\C3\90\C2\A1\C3\93\C3\9A\C2\B5\C3\88\C3\93\C3\9A%d\C2\B5\C3\84\C3\8B\C3\98\C3\8A\C3\BD:\0A\00"
@.str.3 = [4 x i8] c"%4d\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %3
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = load i32, i32* %1
%9 = icmp sge i32 %8, 2
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 2)
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 1
store i32 %13, i32* %3
br label %14
14: ; preds = %10, %0
store i32 3, i32* %2
br label %15
15: ; preds = %37, %14
%16 = load i32, i32* %2
%17 = load i32, i32* %1
%18 = icmp sle i32 %16, %17
br i1 %18, label %19, label %40
19: ; preds = %15
%20 = load i32, i32* %2
%21 = call i32 @prime(i32 %20)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %36
23: ; preds = %19
%24 = load i32, i32* %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %3
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %23
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
%31 = srem i32 %30, 10
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %33, %28, %23
br label %36
36: ; preds = %35, %19
br label %37
37: ; preds = %36
%38 = load i32, i32* %2
%39 = add nsw i32 %38, 1
store i32 %39, i32* %2
br label %15
40: ; preds = %15
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"n:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"\C3\90\C2\A1\C3\93\C3\9A\C2\B5\C3\88\C3\93\C3\9A%d\C2\B5\C3\84\C3\8B\C3\98\C3\8A\C3\BD:\0A\00"
@.str.3 = [4 x i8] c"%4d\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = load i32, i32* %1
%8 = icmp sgt i32 %7, 1
br i1 %8, label %9, label %32
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 2)
%11 = load i32, i32* %1
%12 = icmp slt i32 %11, 3
br i1 %12, label %32, label %13
13: ; preds = %9, %27
%14 = phi i32 [ %28, %27 ], [ 1, %9 ]
%15 = phi i32 [ %29, %27 ], [ 3, %9 ]
%16 = call i32 @prime(i32 %15)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %27
18: ; preds = %13
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%20 = icmp eq i32 %14, 0
br i1 %20, label %27, label %21
21: ; preds = %18
%22 = add nsw i32 %14, 1
%23 = srem i32 %22, 10
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @putchar(i32 10)
br label %27
27: ; preds = %13, %25, %21, %18
%28 = phi i32 [ %22, %25 ], [ %22, %21 ], [ 0, %18 ], [ %14, %13 ]
%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, %9
%33 = call i32 @putchar(i32 10)
ret void
}