#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*/ printf(char *, ...);
int scanf(char *, int *);
int main(void) {
  int num, test;
  int i, count;
  printf("Please enter a positive integer (<= 0 to quit):\n");
  while (scanf("%d", &num) == 1) {
    if (num <= 0)
      break;
    for (test = 1; test <= num; test++) {
      for (i = 2, count = 0; i * i <= test; i++) {
        if (test % i == 0)
          count++;
      }
      if (0 == count)
        printf("%d is prime!\n", test);
    }
    printf("Please enter a positive integer (<= 0 to quit):\n");
  }
  printf("Bye!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeed(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    1204 <main+0xe4>
cmpl   $0x0,-0x8(%rbp)
jg     1165 <main+0x45>
jmp    1204 <main+0xe4>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11f1 <main+0xd1>
movl   $0x2,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11c2 <main+0xa2>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    11af <main+0x8f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b4 <main+0x94>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1186 <main+0x66>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    11de <main+0xbe>
mov    -0xc(%rbp),%esi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e3 <main+0xc3>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116c <main+0x4c>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    113d <main+0x1d>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xecd(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb0(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1201 <main+0xd1>
mov    0xc(%rsp),%r8d
test   %r8d,%r8d
jle    1201 <main+0xd1>
mov    $0x1,%ebx
lea    0xe86(%rip),%r13
lea    0xe8d(%rip),%r14
lea    0xe75(%rip),%r15
lea    0xc(%rsp),%r12
cmp    $0x4,%ebx
jb     11bf <main+0x8f>
xor    %esi,%esi
mov    $0x3,%edi
nopl   0x0(%rax)
lea    -0x1(%rdi),%ecx
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
cmp    $0x1,%edx
adc    $0x0,%esi
mov    %edi,%eax
imul   %edi,%eax
add    $0x1,%edi
cmp    %ebx,%eax
jbe    11a0 <main+0x70>
test   %esi,%esi
jne    11d0 <main+0xa0>
mov    %r13,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%r8d
lea    0x1(%rbx),%eax
cmp    %r8d,%ebx
mov    %eax,%ebx
jl     1190 <main+0x60>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1201 <main+0xd1>
mov    0xc(%rsp),%r8d
mov    $0x1,%ebx
test   %r8d,%r8d
jg     1190 <main+0x60>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [49 x i8] c"Please enter a positive integer (<= 0 to quit):\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [14 x i8] c"%d is prime!\0A\00"
@.str.3 = [6 x i8] c"Bye!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %48, %0
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %50
10: ; preds = %7
%11 = load i32, i32* %2
%12 = icmp sle i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10
br label %50
14: ; preds = %10
store i32 1, i32* %3
br label %15
15: ; preds = %45, %14
%16 = load i32, i32* %3
%17 = load i32, i32* %2
%18 = icmp sle i32 %16, %17
br i1 %18, label %19, label %48
19: ; preds = %15
store i32 2, i32* %4
store i32 0, i32* %5
br label %20
20: ; preds = %35, %19
%21 = load i32, i32* %4
%22 = load i32, i32* %4
%23 = mul nsw i32 %21, %22
%24 = load i32, i32* %3
%25 = icmp sle i32 %23, %24
br i1 %25, label %26, label %38
26: ; preds = %20
%27 = load i32, i32* %3
%28 = load i32, i32* %4
%29 = srem i32 %27, %28
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %34
34: ; preds = %31, %26
br label %35
35: ; preds = %34
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %20
38: ; preds = %20
%39 = load i32, i32* %5
%40 = icmp eq i32 0, %39
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i32, i32* %3
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %41, %38
br label %45
45: ; preds = %44
%46 = load i32, i32* %3
%47 = add nsw i32 %46, 1
store i32 %47, i32* %3
br label %15
48: ; preds = %15
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %7
50: ; preds = %13, %7
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [14 x i8] c"%d is prime!\0A\00"
@str.4 = [48 x i8] c"Please enter a positive integer (<= 0 to quit):\00"
@str.5 = [5 x i8] c"Bye!\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.4, 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 = icmp ne i32 %4, 1
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 1
%8 = select i1 %5, i1 true, i1 %7
br i1 %8, label %42, label %9
9: ; preds = %0, %32
%10 = phi i32 [ %33, %32 ], [ %6, %0 ]
%11 = phi i32 [ %34, %32 ], [ 1, %0 ]
%12 = icmp ult i32 %11, 4
br i1 %12, label %25, label %13
13: ; preds = %9, %13
%14 = phi i32 [ %19, %13 ], [ 0, %9 ]
%15 = phi i32 [ %20, %13 ], [ 2, %9 ]
%16 = urem i32 %11, %15
%17 = icmp eq i32 %16, 0
%18 = zext i1 %17 to i32
%19 = add nuw nsw i32 %14, %18
%20 = add nuw nsw i32 %15, 1
%21 = mul nsw i32 %20, %20
%22 = icmp ugt i32 %21, %11
br i1 %22, label %23, label %13
23: ; preds = %13
%24 = icmp eq i32 %19, 0
br i1 %24, label %25, label %28
25: ; preds = %9, %23
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%27 = load i32, i32* %1
br label %28
28: ; preds = %23, %25
%29 = phi i32 [ %10, %23 ], [ %27, %25 ]
%30 = add nuw nsw i32 %11, 1
%31 = icmp slt i32 %11, %29
br i1 %31, label %32, label %35
32: ; preds = %28, %35
%33 = phi i32 [ %29, %28 ], [ %39, %35 ]
%34 = phi i32 [ %30, %28 ], [ 1, %35 ]
br label %9
35: ; preds = %28
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.4, i64 0, i64 0))
%37 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%38 = icmp ne i32 %37, 1
%39 = load i32, i32* %1
%40 = icmp slt i32 %39, 1
%41 = select i1 %38, i1 true, i1 %40
br i1 %41, label %42, label %32
42: ; preds = %35, %0
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.5, i64 0, i64 0))
ret i32 0
}