#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 INT_MAX;
char getchar();
scalar_t__ prime(int);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, int *);
int main(void) {
  int boundary;
  printf("Input the boudary(between 0 and %d):", INT_MAX - 1);
  int ret1, ret2;
  while ((ret1 = scanf("%d", &boundary)) != 1 || boundary < 0 ||
         boundary > INT_MAX - 1 || (ret2 = getchar()) != '\n') {
    if (ret1 != 1 || ret2 != '\n')
      while (getchar() != '\n')
        ;
    printf("invalid input!\n");
    printf("Input the boudary(between 0 and %d):", INT_MAX - 1);
  }
  int num;
  for (num = 2; num < boundary + 1; num++) {
    if (prime(num))
      printf("%d\t", num);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
sub    $0x1,%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
mov    $0x1,%al
cmp    $0x1,%ecx
mov    %al,-0x15(%rbp)
jne    11cd <main+0x8d>
mov    $0x1,%al
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x15(%rbp)
jl     11cd <main+0x8d>
mov    -0x8(%rbp),%ecx
mov    0x2e43(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
mov    $0x1,%al
cmp    %edx,%ecx
mov    %al,-0x15(%rbp)
jg     11cd <main+0x8d>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
mov    %eax,-0x10(%rbp)
cmp    $0xa,%eax
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    11dd <main+0x9d>
jmp    1240 <main+0x100>
cmpl   $0x1,-0xc(%rbp)
jne    11f1 <main+0xb1>
cmpl   $0xa,-0x10(%rbp)
je     1213 <main+0xd3>
jmp    11f6 <main+0xb6>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     120e <main+0xce>
jmp    11f6 <main+0xb6>
jmp    1213 <main+0xd3>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
sub    $0x1,%esi
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1169 <main+0x29>
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    128e <main+0x14e>
mov    -0x14(%rbp),%edi
call   1060 <prime@plt>
cmp    $0x0,%rax
je     127b <main+0x13b>
mov    -0x14(%rbp),%esi
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1280 <main+0x140>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1247 <main+0x107>
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
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
mov    0x2e76(%rip),%rbx
mov    (%rbx),%esi
add    $0xffffffff,%esi
lea    0xe82(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe99(%rip),%r15
lea    0x4(%rsp),%r13
lea    0xe94(%rip),%r12
jmp    11bb <main+0x5b>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1040 <puts@plt>
mov    (%rbx),%esi
add    $0xffffffff,%esi
lea    0xe4c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1070 <scanf@plt>
mov    %eax,%ebp
cmp    $0x1,%eax
jne    11e8 <main+0x88>
mov    0x4(%rsp),%eax
test   %eax,%eax
js     11e8 <main+0x88>
cmp    (%rbx),%eax
jge    11e8 <main+0x88>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
je     120d <main+0xad>
movsbl %al,%r14d
cmp    $0x1,%ebp
jne    1200 <main+0xa0>
cmp    $0xa,%r14d
je     11a0 <main+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
jne    1200 <main+0xa0>
jmp    11a0 <main+0x40>
cmpl   $0x2,0x4(%rsp)
jge    122f <main+0xcf>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebx
lea    0xded(%rip),%rbp
jmp    1246 <main+0xe6>
nopl   (%rax)
cmp    0x4(%rsp),%ebx
jge    1214 <main+0xb4>
add    $0x1,%ebx
mov    %ebx,%edi
call   1080 <prime@plt>
test   %rax,%rax
je     1240 <main+0xe0>
mov    %rbp,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1240 <main+0xe0>

LLVM IR (-O0):
@.str = [37 x i8] c"Input the boudary(between 0 and %d):\00"
@INT_MAX = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"invalid input!\0A\00"
@.str.3 = [4 x i8] c"%d\09\00"
@.str.4 = [2 x i8] c"\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 = load i32, i32* @INT_MAX
%7 = sub nsw i32 %6, 1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %39, %0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
store i32 %10, i32* %3
%11 = icmp ne i32 %10, 1
br i1 %11, label %24, label %12
12: ; preds = %9
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %12
%16 = load i32, i32* %2
%17 = load i32, i32* @INT_MAX
%18 = sub nsw i32 %17, 1
%19 = icmp sgt i32 %16, %18
br i1 %19, label %24, label %20
20: ; preds = %15
%21 = call signext i8 (...) @getchar()
%22 = sext i8 %21 to i32
store i32 %22, i32* %4
%23 = icmp ne i32 %22, 10
br label %24
24: ; preds = %20, %15, %12, %9
%25 = phi i1 [ true, %15 ], [ true, %12 ], [ true, %9 ], [ %23, %20 ]
br i1 %25, label %26, label %44
26: ; preds = %24
%27 = load i32, i32* %3
%28 = icmp ne i32 %27, 1
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i32, i32* %4
%31 = icmp ne i32 %30, 10
br i1 %31, label %32, label %39
32: ; preds = %29, %26
br label %33
33: ; preds = %37, %32
%34 = call signext i8 (...) @getchar()
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 10
br i1 %36, label %37, label %38
37: ; preds = %33
br label %33
38: ; preds = %33
br label %39
39: ; preds = %38, %29
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32, i32* @INT_MAX
%42 = sub nsw i32 %41, 1
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %42)
br label %9
44: ; preds = %24
store i32 2, i32* %5
br label %45
45: ; preds = %58, %44
%46 = load i32, i32* %5
%47 = load i32, i32* %2
%48 = add nsw i32 %47, 1
%49 = icmp slt i32 %46, %48
br i1 %49, label %50, label %61
50: ; preds = %45
%51 = load i32, i32* %5
%52 = call i64 @prime(i32 %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = load i32, i32* %5
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %54, %50
br label %58
58: ; preds = %57
%59 = load i32, i32* %5
%60 = add nsw i32 %59, 1
store i32 %60, i32* %5
br label %45
61: ; preds = %45
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [37 x i8] c"Input the boudary(between 0 and %d):\00"
@INT_MAX = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d\09\00"
@str = [15 x i8] c"invalid input!\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @INT_MAX
%4 = add nsw i32 %3, -1
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %6
6: ; preds = %31, %0
%7 = phi i32 [ undef, %0 ], [ %25, %31 ]
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = icmp ne i32 %8, 1
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, -1
%12 = xor i1 %9, true
%13 = select i1 %12, i1 %11, i1 false
%14 = load i32, i32* @INT_MAX
%15 = icmp slt i32 %10, %14
%16 = select i1 %13, i1 %15, i1 false
br i1 %16, label %17, label %24
17: ; preds = %6
%18 = call signext i8 (...) @getchar()
%19 = sext i8 %18 to i32
%20 = icmp eq i8 %18, 10
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* %1
%23 = icmp slt i32 %22, 2
br i1 %23, label %46, label %36
24: ; preds = %6, %17
%25 = phi i32 [ %7, %6 ], [ %19, %17 ]
%26 = icmp ne i32 %25, 10
%27 = select i1 %9, i1 true, i1 %26
br i1 %27, label %28, label %31
28: ; preds = %24, %28
%29 = call signext i8 (...) @getchar()
%30 = icmp eq i8 %29, 10
br i1 %30, label %31, label %28
31: ; preds = %28, %24
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%33 = load i32, i32* @INT_MAX
%34 = add nsw i32 %33, -1
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %34)
br label %6
36: ; preds = %21, %42
%37 = phi i32 [ %43, %42 ], [ 2, %21 ]
%38 = call i64 @prime(i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %36
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %37)
br label %42
42: ; preds = %36, %40
%43 = add nuw nsw i32 %37, 1
%44 = load i32, i32* %1
%45 = icmp slt i32 %37, %44
br i1 %45, label %36, label %46
46: ; preds = %42, %21
%47 = call i32 @putchar(i32 10)
ret i32 0
}