#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 /*<<< orphan*/ scanf(char *, int *);
int primoate() {
  int numf, numd, num, i, p, n;
  n = 0;
  printf("\n--------< Print prime numbers: >--------\n\nEnter numbers: ");
  scanf("%d", &numf);
  for (num = 1; num <= numf; num++) {
    p = 0;
    numd = num / 2;
    i = 2;
    while (i < numd) {
      if ((num % (i)) == 0) {
        p = 1;
        break;
      }
      i++;
    }
    if (p == 0) {
      printf("%d\n", num);
      n++;
    }
  }
  printf("\nthere are %d prime numbers from 0 to %d\n", n, numf);
  numf = num = i = p = n = 0;
  return 0;
}


x86 assembly (clang, -O0):
<primoate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x18(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef7(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11e9 <primoate+0xc9>
movl   $0x0,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
movl   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b2 <primoate+0x92>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    11a4 <primoate+0x84>
movl   $0x1,-0x14(%rbp)
jmp    11b2 <primoate+0x92>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117c <primoate+0x5c>
cmpl   $0x0,-0x14(%rbp)
jne    11d6 <primoate+0xb6>
mov    -0xc(%rbp),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11db <primoate+0xbb>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1154 <primoate+0x34>
mov    -0x18(%rbp),%esi
mov    -0x4(%rbp),%edx
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<primoate>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xed2(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xefd(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%ecx
test   %ecx,%ecx
jle    11c3 <primoate+0xa3>
mov    $0x1,%ebx
mov    $0x3,%r15d
lea    0xf02(%rip),%r14
xor    %ebp,%ebp
jmp    118c <primoate+0x6c>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebp
mov    0x4(%rsp),%ecx
lea    0x1(%rbx),%eax
cmp    %ecx,%ebx
mov    %eax,%ebx
jge    11c3 <primoate+0xa3>
mov    %ebx,%esi
shr    %esi
cmp    $0x4,%esi
cmovb  %r15d,%esi
cmp    $0x6,%ebx
jb     1170 <primoate+0x50>
mov    $0x2,%edi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %edi
test   %edx,%edx
je     1183 <primoate+0x63>
add    $0x1,%edi
cmp    %edi,%esi
jne    11b0 <primoate+0x90>
jmp    1170 <primoate+0x50>
lea    0xe74(%rip),%rdi
mov    %ebp,%esi
mov    %ecx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [59 x i8] c"\0A--------< Print prime numbers: >--------\0A\0AEnter numbers: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [42 x i8] c"\0Athere are %d prime numbers from 0 to %d\0A\00"
define i32 @primoate() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
store i32 1, i32* %3
br label %9
9: ; preds = %38, %0
%10 = load i32, i32* %3
%11 = load i32, i32* %1
%12 = icmp sle i32 %10, %11
br i1 %12, label %13, label %41
13: ; preds = %9
store i32 0, i32* %5
%14 = load i32, i32* %3
%15 = sdiv i32 %14, 2
store i32 %15, i32* %2
store i32 2, i32* %4
br label %16
16: ; preds = %26, %13
%17 = load i32, i32* %4
%18 = load i32, i32* %2
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = srem i32 %21, %22
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 1, i32* %5
br label %29
26: ; preds = %20
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %16
29: ; preds = %25, %16
%30 = load i32, i32* %5
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i32, i32* %3
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %37
37: ; preds = %32, %29
br label %38
38: ; preds = %37
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %3
br label %9
41: ; preds = %9
%42 = load i32, i32* %6
%43 = load i32, i32* %1
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %42, i32 %43)
store i32 0, i32* %6
store i32 0, i32* %5
store i32 0, i32* %4
store i32 0, i32* %3
store i32 0, i32* %1
ret i32 0
}

LLVM IR (-O2):
@.str = [59 x i8] c"\0A--------< Print prime numbers: >--------\0A\0AEnter numbers: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [42 x i8] c"\0Athere are %d prime numbers from 0 to %d\0A\00"
define i32 @primoate() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 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 = icmp slt i32 %5, 1
br i1 %6, label %30, label %7
7: ; preds = %0, %25
%8 = phi i32 [ %26, %25 ], [ %5, %0 ]
%9 = phi i32 [ %27, %25 ], [ 0, %0 ]
%10 = phi i32 [ %28, %25 ], [ 1, %0 ]
%11 = lshr i32 %10, 1
%12 = call i32 @llvm.umax.i32(i32 %11, i32 3)
%13 = icmp ugt i32 %10, 5
br i1 %13, label %16, label %21
14: ; preds = %16
%15 = icmp eq i32 %20, %12
br i1 %15, label %21, label %16
16: ; preds = %7, %14
%17 = phi i32 [ %20, %14 ], [ 2, %7 ]
%18 = urem i32 %10, %17
%19 = icmp eq i32 %18, 0
%20 = add nuw nsw i32 %17, 1
br i1 %19, label %25, label %14
21: ; preds = %14, %7
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%23 = add nsw i32 %9, 1
%24 = load i32, i32* %1
br label %25
25: ; preds = %16, %21
%26 = phi i32 [ %24, %21 ], [ %8, %16 ]
%27 = phi i32 [ %23, %21 ], [ %9, %16 ]
%28 = add nuw nsw i32 %10, 1
%29 = icmp slt i32 %10, %26
br i1 %29, label %7, label %30
30: ; preds = %25, %0
%31 = phi i32 [ 0, %0 ], [ %27, %25 ]
%32 = phi i32 [ %5, %0 ], [ %26, %25 ]
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %32)
ret i32 0
}