#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 atoi(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, char *);
int sqrt(int);
scalar_t__ strcmp(char *, char *);
int main() {
  int i, k;
  char input[5];
  do {
    int notprime = 0;
    puts("請輸入一個數字");
    scanf("%s", input);
    if (atoi(input) < 2 && strcmp(input, "q")) {
      printf("請輸入比1大的數字\n");
    } else if (atoi(input) >= 2) {
      for (i = 2; i <= sqrt(atoi(input)); i++) {
        if ((atoi(input) % i) == 0) {
          notprime = 1;
        }
      }
      if (notprime) {
        printf("%s 不是質數\n有因數\n", input);
        for (k = 1; k <= atoi(input); k++) {
          if (atoi(input) % k == 0) {
            printf("%d ", k);
          }
        }
        puts("");
      } else {
        printf("%s 是質數\n", input);
      }
    }
  } while (strcmp(input, "q"));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
lea    -0x11(%rbp),%rsi
lea    0xe89(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x11(%rbp),%rdi
call   1070 <atoi@plt>
cmp    $0x2,%eax
jge    11d1 <main+0x71>
lea    -0x11(%rbp),%rdi
lea    0xe6a(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11d1 <main+0x71>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12e3 <main+0x183>
lea    -0x11(%rbp),%rdi
call   1070 <atoi@plt>
cmp    $0x2,%eax
jl     12de <main+0x17e>
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x11(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%edi
call   1080 <sqrt@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jg     123d <main+0xdd>
lea    -0x11(%rbp),%rdi
call   1070 <atoi@plt>
cltd
idivl  -0x8(%rbp)
cmp    $0x0,%edx
jne    122a <main+0xca>
movl   $0x1,-0x18(%rbp)
jmp    122f <main+0xcf>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ea <main+0x8a>
cmpl   $0x0,-0x18(%rbp)
je     12c7 <main+0x167>
lea    -0x11(%rbp),%rsi
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
lea    -0x11(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jg     12b6 <main+0x156>
lea    -0x11(%rbp),%rdi
call   1070 <atoi@plt>
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    12a3 <main+0x143>
mov    -0xc(%rbp),%esi
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a8 <main+0x148>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1260 <main+0x100>
lea    0xd78(%rip),%rdi
call   1030 <puts@plt>
jmp    12d9 <main+0x179>
lea    -0x11(%rbp),%rsi
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12de <main+0x17e>
jmp    12e3 <main+0x183>
jmp    12e8 <main+0x188>
lea    -0x11(%rbp),%rdi
lea    0xd26(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    116f <main+0xf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe7e(%rip),%r13
lea    0xe8d(%rip),%rbp
lea    0x3(%rsp),%r15
lea    0xe84(%rip),%rbx
mov    $0x1,%r14d
jmp    11c5 <main+0x55>
nopl   (%rax)
lea    0xe93(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     12de <main+0x16e>
mov    %r13,%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
mov    %r15,%rdi
call   1080 <atoi@plt>
cmp    $0x1,%eax
jg     1210 <main+0xa0>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1210 <main+0xa0>
lea    0xe4c(%rip),%rdi
call   1040 <puts@plt>
jmp    11b1 <main+0x41>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   1080 <atoi@plt>
cmp    $0x2,%eax
jl     11b1 <main+0x41>
mov    %eax,%edi
call   1090 <sqrt@plt>
cmp    $0x2,%eax
jl     11a0 <main+0x30>
mov    %rbp,%r12
xor    %ebp,%ebp
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
mov    %r15,%rdi
call   1080 <atoi@plt>
mov    %eax,%edi
cltd
idiv   %ebx
test   %edx,%edx
cmove  %r14d,%ebp
call   1090 <sqrt@plt>
cmp    %eax,%ebx
jl     1240 <main+0xd0>
test   %ebp,%ebp
mov    %r12,%rbp
lea    0xdae(%rip),%rbx
je     11a0 <main+0x30>
mov    %r13,%r12
lea    0xda0(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1080 <atoi@plt>
test   %eax,%eax
jle    12cc <main+0x15c>
xor    %r13d,%r13d
jmp    12ad <main+0x13d>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1080 <atoi@plt>
cmp    %eax,%r13d
jge    12cc <main+0x15c>
add    $0x1,%r13d
cltd
idiv   %r13d
test   %edx,%edx
jne    12a0 <main+0x130>
lea    0xd76(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12a0 <main+0x130>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12,%r13
jmp    11b1 <main+0x41>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"\E8\AB\8B\E8\BC\B8\E5\85\A5\E4\B8\80\E5\80\8B\E6\95\B8\E5\AD\97\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"q\00"
@.str.3 = [27 x i8] c"\E8\AB\8B\E8\BC\B8\E5\85\A5\E6\AF\941\E5\A4\A7\E7\9A\84\E6\95\B8\E5\AD\97\0A\00"
@.str.4 = [27 x i8] c"%s \E4\B8\8D\E6\98\AF\E8\B3\AA\E6\95\B8\0A\E6\9C\89\E5\9B\A0\E6\95\B8\0A\00"
@.str.5 = [4 x i8] c"%d \00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [14 x i8] c"%s \E6\98\AF\E8\B3\AA\E6\95\B8\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [5 x i8]
%5 = alloca i32
store i32 0, i32* %1
br label %6
6: ; preds = %73, %0
store i32 0, i32* %5
%7 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%11 = call i32 @atoi(i8* %10)
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %19
13: ; preds = %6
%14 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %72
19: ; preds = %13, %6
%20 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%21 = call i32 @atoi(i8* %20)
%22 = icmp sge i32 %21, 2
br i1 %22, label %23, label %71
23: ; preds = %19
store i32 2, i32* %2
br label %24
24: ; preds = %38, %23
%25 = load i32, i32* %2
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%27 = call i32 @atoi(i8* %26)
%28 = call i32 @sqrt(i32 %27)
%29 = icmp sle i32 %25, %28
br i1 %29, label %30, label %41
30: ; preds = %24
%31 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%32 = call i32 @atoi(i8* %31)
%33 = load i32, i32* %2
%34 = srem i32 %32, %33
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %30
store i32 1, i32* %5
br label %37
37: ; preds = %36, %30
br label %38
38: ; preds = %37
%39 = load i32, i32* %2
%40 = add nsw i32 %39, 1
store i32 %40, i32* %2
br label %24
41: ; preds = %24
%42 = load i32, i32* %5
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %67
44: ; preds = %41
%45 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %45)
store i32 1, i32* %3
br label %47
47: ; preds = %62, %44
%48 = load i32, i32* %3
%49 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%50 = call i32 @atoi(i8* %49)
%51 = icmp sle i32 %48, %50
br i1 %51, label %52, label %65
52: ; preds = %47
%53 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%54 = call i32 @atoi(i8* %53)
%55 = load i32, i32* %3
%56 = srem i32 %54, %55
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %52
%59 = load i32, i32* %3
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %58, %52
br label %62
62: ; preds = %61
%63 = load i32, i32* %3
%64 = add nsw i32 %63, 1
store i32 %64, i32* %3
br label %47
65: ; preds = %47
%66 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0))
br label %70
67: ; preds = %41
%68 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %68)
br label %70
70: ; preds = %67, %65
br label %71
71: ; preds = %70, %19
br label %72
72: ; preds = %71, %17
br label %73
73: ; preds = %72
%74 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%75 = call i64 @strcmp(i8* %74, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%76 = icmp ne i64 %75, 0
br i1 %76, label %6, label %77
77: ; preds = %73
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"\E8\AB\8B\E8\BC\B8\E5\85\A5\E4\B8\80\E5\80\8B\E6\95\B8\E5\AD\97\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"q\00"
@.str.4 = [27 x i8] c"%s \E4\B8\8D\E6\98\AF\E8\B3\AA\E6\95\B8\0A\E6\9C\89\E5\9B\A0\E6\95\B8\0A\00"
@.str.5 = [4 x i8] c"%d \00"
@.str.7 = [14 x i8] c"%s \E6\98\AF\E8\B3\AA\E6\95\B8\0A\00"
@str = [26 x i8] c"\E8\AB\8B\E8\BC\B8\E5\85\A5\E6\AF\941\E5\A4\A7\E7\9A\84\E6\95\B8\E5\AD\97\00"
define i32 @main() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %50, %0
%4 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 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), i8* %2)
%6 = call i32 @atoi(i8* %2)
%7 = icmp slt i32 %6, 2
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %50
13: ; preds = %8, %3
%14 = call i32 @atoi(i8* %2)
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %50
16: ; preds = %13
%17 = call i32 @sqrt(i32 %14)
%18 = icmp slt i32 %17, 2
br i1 %18, label %48, label %19
19: ; preds = %16, %19
%20 = phi i32 [ %25, %19 ], [ 0, %16 ]
%21 = phi i32 [ %26, %19 ], [ 2, %16 ]
%22 = call i32 @atoi(i8* %2)
%23 = srem i32 %22, %21
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i32 1, i32 %20
%26 = add nuw nsw i32 %21, 1
%27 = call i32 @sqrt(i32 %22)
%28 = icmp slt i32 %21, %27
br i1 %28, label %19, label %29
29: ; preds = %19
%30 = icmp eq i32 %25, 0
br i1 %30, label %48, label %31
31: ; preds = %29
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %2)
%33 = call i32 @atoi(i8* %2)
%34 = icmp slt i32 %33, 1
br i1 %34, label %46, label %35
35: ; preds = %31, %42
%36 = phi i32 [ %44, %42 ], [ %33, %31 ]
%37 = phi i32 [ %43, %42 ], [ 1, %31 ]
%38 = srem i32 %36, %37
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %37)
br label %42
42: ; preds = %35, %40
%43 = add nuw nsw i32 %37, 1
%44 = call i32 @atoi(i8* %2)
%45 = icmp slt i32 %37, %44
br i1 %45, label %35, label %46
46: ; preds = %42, %31
%47 = call i32 @putchar(i32 10)
br label %50
48: ; preds = %16, %29
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %2)
br label %50
50: ; preds = %13, %48, %46, %11
%51 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %3
53: ; preds = %50
ret i32 0
}