#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 verificaprimo() {
  int num, numd, i, p;
  printf("\n--------<check whether a number is prime: >--------\n\nEnter a "
         "number: ");
  scanf("%d", &num);
  numd = num / 2;
  i = 2;
  while (i < numd) {
    printf("divider -> %d  number -> %d  remainder -> %d\n", i, num, num % (i));
    if ((num % (i)) == 0) {
      p = 1;
      break;
    }
    i++;
  }
  if (p != 1)
    printf("Number %d is prime\n", num);
  else
    printf("Number %d is not prime\n", num);
  num = i = p = 0;
  return 0;
}


x86 assembly (clang, -O0):
<verificaprimo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf0a(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b4 <verificaprimo+0x94>
mov    -0xc(%rbp),%esi
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %edx,%ecx
mov    -0x14(%rbp),%edx
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11a6 <verificaprimo+0x86>
movl   $0x1,-0x10(%rbp)
jmp    11b4 <verificaprimo+0x94>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115b <verificaprimo+0x3b>
cmpl   $0x1,-0x10(%rbp)
je     11d4 <verificaprimo+0xb4>
mov    -0x4(%rbp),%esi
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e5 <verificaprimo+0xc5>
mov    -0x4(%rbp),%esi
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
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):
<verificaprimo>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xed2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf0b(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%r8d
cmp    $0x6,%r8d
jl     11a3 <verificaprimo+0x83>
mov    %r8d,%r15d
shr    $0x1f,%r15d
add    %r8d,%r15d
sar    %r15d
mov    $0x3,%ebx
lea    0xee0(%rip),%r14
nopw   0x0(%rax,%rax,1)
lea    -0x1(%rbx),%ebp
mov    %r8d,%eax
cltd
idiv   %ebp
mov    %edx,%ecx
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r8d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x4(%rsp),%r8d
mov    %r8d,%eax
cltd
idiv   %ebp
test   %edx,%edx
je     11a3 <verificaprimo+0x83>
lea    0x1(%rbx),%eax
cmp    %r15d,%ebx
mov    %eax,%ebx
jl     1170 <verificaprimo+0x50>
lea    0xece(%rip),%rdi
mov    %r8d,%esi
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 = [71 x i8] c"\0A--------<check whether a number is prime: >--------\0A\0AEnter a number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [46 x i8] c"divider -> %d number -> %d remainder -> %d\0A\00"
@.str.3 = [20 x i8] c"Number %d is prime\0A\00"
@.str.4 = [24 x i8] c"Number %d is not prime\0A\00"
define i32 @verificaprimo() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = sdiv i32 %7, 2
store i32 %8, i32* %2
store i32 2, i32* %3
br label %9
9: ; preds = %25, %0
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %28
13: ; preds = %9
%14 = load i32, i32* %3
%15 = load i32, i32* %1
%16 = load i32, i32* %1
%17 = load i32, i32* %3
%18 = srem i32 %16, %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %15, i32 %18)
%20 = load i32, i32* %1
%21 = load i32, i32* %3
%22 = srem i32 %20, %21
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %13
store i32 1, i32* %4
br label %28
25: ; preds = %13
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %9
28: ; preds = %24, %9
%29 = load i32, i32* %4
%30 = icmp ne i32 %29, 1
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* %1
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %32)
br label %37
34: ; preds = %28
%35 = load i32, i32* %1
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %34, %31
store i32 0, i32* %4
store i32 0, i32* %3
store i32 0, i32* %1
ret i32 0
}

LLVM IR (-O2):
@.str = [71 x i8] c"\0A--------<check whether a number is prime: >--------\0A\0AEnter a number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [46 x i8] c"divider -> %d number -> %d remainder -> %d\0A\00"
@.str.4 = [24 x i8] c"Number %d is not prime\0A\00"
define i32 @verificaprimo() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 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 = sdiv i32 %5, 2
%7 = icmp sgt i32 %5, 5
br i1 %7, label %8, label %19
8: ; preds = %0, %8
%9 = phi i32 [ %13, %8 ], [ %5, %0 ]
%10 = phi i32 [ %16, %8 ], [ 2, %0 ]
%11 = srem i32 %9, %10
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %10, i32 %9, i32 %11)
%13 = load i32, i32* %1
%14 = srem i32 %13, %10
%15 = icmp ne i32 %14, 0
%16 = add nuw nsw i32 %10, 1
%17 = icmp slt i32 %16, %6
%18 = select i1 %15, i1 %17, i1 false
br i1 %18, label %8, label %19
19: ; preds = %8, %0
%20 = phi i32 [ %5, %0 ], [ %13, %8 ]
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %20)
ret i32 0
}