#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 sqrt(int);
int main() {
  int num, aux, cont;
  aux = 0;
  printf("digite um nume:\n");
  scanf("%i", &num);
  for (int i = num; i >= 2; --i) {
    cont = 0;
    for (int j = 2; j < sqrt(i) + 1; ++j) {
      if (i % j == 0) {
        cont++;
        break;
      }
    }
    if (cont == 0) {
      aux = i;
      break;
    }
  }
  printf("O maior numero primo entre 0 e %d sera %d", num, aux);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb6(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jl     11f9 <main+0xc9>
movl   $0x0,-0x10(%rbp)
movl   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <sqrt@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11d1 <main+0xa1>
mov    -0x14(%rbp),%eax
cltd
idivl  -0x18(%rbp)
cmp    $0x0,%edx
jne    11be <main+0x8e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11d1 <main+0xa1>
jmp    11c3 <main+0x93>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1182 <main+0x52>
cmpl   $0x0,-0x10(%rbp)
jne    11e6 <main+0xb6>
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11f9 <main+0xc9>
jmp    11eb <main+0xbb>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    116a <main+0x3a>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
lea    0xea5(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%ebx
xor    %r14d,%r14d
cmp    $0x2,%ebx
jl     11bf <main+0x7f>
mov    %ebx,%edi
call   1060 <sqrt@plt>
cmp    $0x2,%eax
jl     11bc <main+0x7c>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebp
mov    %ebx,%eax
cltd
idiv   %ebp
test   %edx,%edx
je     11b0 <main+0x70>
mov    %ebx,%edi
call   1060 <sqrt@plt>
cmp    %eax,%ebp
jl     1190 <main+0x50>
jmp    11bc <main+0x7c>
nopl   0x0(%rax)
lea    -0x1(%rbx),%eax
cmp    $0x2,%ebx
mov    %eax,%ebx
jg     1171 <main+0x31>
jmp    11bf <main+0x7f>
mov    %ebx,%r14d
mov    0xc(%rsp),%esi
lea    0xe39(%rip),%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"digite um nume:\0A\00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [42 x i8] c"O maior numero primo entre 0 e %d sera %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 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* %2)
%9 = load i32, i32* %2
store i32 %9, i32* %5
br label %10
10: ; preds = %38, %0
%11 = load i32, i32* %5
%12 = icmp sge i32 %11, 2
br i1 %12, label %13, label %41
13: ; preds = %10
store i32 0, i32* %4
store i32 2, i32* %6
br label %14
14: ; preds = %29, %13
%15 = load i32, i32* %6
%16 = load i32, i32* %5
%17 = call i32 @sqrt(i32 %16)
%18 = add nsw i32 %17, 1
%19 = icmp slt i32 %15, %18
br i1 %19, label %20, label %32
20: ; preds = %14
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = srem i32 %21, %22
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %32
28: ; preds = %20
br label %29
29: ; preds = %28
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %14
32: ; preds = %25, %14
%33 = load i32, i32* %4
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = load i32, i32* %5
store i32 %36, i32* %3
br label %41
37: ; preds = %32
br label %38
38: ; preds = %37
%39 = load i32, i32* %5
%40 = add nsw i32 %39, -1
store i32 %40, i32* %5
br label %10
41: ; preds = %35, %10
%42 = load i32, i32* %2
%43 = load i32, i32* %3
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %42, i32 %43)
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [42 x i8] c"O maior numero primo entre 0 e %d sera %d\00"
@str = [16 x i8] c"digite um nume:\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 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 sgt i32 %5, 1
br i1 %6, label %7, label %22
7: ; preds = %0, %19
%8 = phi i32 [ %20, %19 ], [ %5, %0 ]
%9 = call i32 @sqrt(i32 %8)
%10 = icmp slt i32 %9, 2
br i1 %10, label %22, label %15
11: ; preds = %15
%12 = add nuw nsw i32 %16, 1
%13 = call i32 @sqrt(i32 %8)
%14 = icmp slt i32 %16, %13
br i1 %14, label %15, label %22
15: ; preds = %7, %11
%16 = phi i32 [ %12, %11 ], [ 2, %7 ]
%17 = srem i32 %8, %16
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %11
19: ; preds = %15
%20 = add nsw i32 %8, -1
%21 = icmp sgt i32 %8, 2
br i1 %21, label %7, label %22
22: ; preds = %19, %7, %11, %0
%23 = phi i32 [ 0, %0 ], [ %8, %11 ], [ %8, %7 ], [ 0, %19 ]
%24 = load i32, i32* %1
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 %23)
ret i32 0
}