#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 *, long *);
long sqrt(long);
int main() {
  long input, i, compound;
  long prime = -1;
  printf("Please insert an integer value: ");
  scanf("%ld", &input);
  compound = input;
  for (i = 2; i < sqrt(input); i++) {
    if (compound % i == 0) {
      compound = compound / i;
      if (i > prime) {
        prime = i;
      }
      i = 2;
    }
  }
  printf("The largest prime factor of %ld is: %ld\n", input, prime);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0xffffffffffffffff,-0x28(%rbp)
ff
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec5(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <sqrt@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jge    11ec <main+0xbc>
mov    -0x20(%rbp),%rax
cqto
idivq  -0x18(%rbp)
cmp    $0x0,%rdx
jne    11d6 <main+0xa6>
mov    -0x20(%rbp),%rax
cqto
idivq  -0x18(%rbp)
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jle    11ce <main+0x9e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x2,-0x18(%rbp)
jmp    11db <main+0xab>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1175 <main+0x45>
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xec1(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed4(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
mov    (%rsp),%r15
mov    %r15,%rdi
call   1050 <sqrt@plt>
mov    $0xffffffffffffffff,%r14
cmp    $0x3,%rax
jl     11c8 <main+0x98>
mov    $0x2,%ebx
mov    $0x2,%r12d
jmp    11b3 <main+0x83>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rax
cqto
idiv   %rbx
cmp    %r14,%rbx
mov    %r14,%rcx
cmovg  %rbx,%rcx
test   %rdx,%rdx
cmove  %r12,%rbx
cmove  %rax,%r15
cmove  %rcx,%r14
add    $0x1,%rbx
mov    (%rsp),%rdi
call   1050 <sqrt@plt>
cmp    %rax,%rbx
jge    11c8 <main+0x98>
mov    %r15,%rax
or     %rbx,%rax
shr    $0x20,%rax
jne    1180 <main+0x50>
mov    %r15d,%eax
xor    %edx,%edx
div    %ebx
jmp    1188 <main+0x58>
mov    (%rsp),%rsi
lea    0xe52(%rip),%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Please insert an integer value: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [41 x i8] c"The largest prime factor of %ld is: %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i32 0, i32* %1
store i64 -1, i64* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%8 = load i64, i64* %2
store i64 %8, i64* %4
store i64 2, i64* %3
br label %9
9: ; preds = %30, %0
%10 = load i64, i64* %3
%11 = load i64, i64* %2
%12 = call i64 @sqrt(i64 %11)
%13 = icmp slt i64 %10, %12
br i1 %13, label %14, label %33
14: ; preds = %9
%15 = load i64, i64* %4
%16 = load i64, i64* %3
%17 = srem i64 %15, %16
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %29
19: ; preds = %14
%20 = load i64, i64* %4
%21 = load i64, i64* %3
%22 = sdiv i64 %20, %21
store i64 %22, i64* %4
%23 = load i64, i64* %3
%24 = load i64, i64* %5
%25 = icmp sgt i64 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = load i64, i64* %3
store i64 %27, i64* %5
br label %28
28: ; preds = %26, %19
store i64 2, i64* %3
br label %29
29: ; preds = %28, %14
br label %30
30: ; preds = %29
%31 = load i64, i64* %3
%32 = add nsw i64 %31, 1
store i64 %32, i64* %3
br label %9
33: ; preds = %9
%34 = load i64, i64* %2
%35 = load i64, i64* %5
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i64 %34, i64 %35)
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@.str = [33 x i8] c"Please insert an integer value: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [41 x i8] c"The largest prime factor of %ld is: %ld\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%5 = load i64, i64* %1
%6 = call i64 @sqrt(i64 %5)
%7 = icmp sgt i64 %6, 2
br i1 %7, label %8, label %24
8: ; preds = %0, %8
%9 = phi i64 [ %19, %8 ], [ -1, %0 ]
%10 = phi i64 [ %18, %8 ], [ %5, %0 ]
%11 = phi i64 [ %20, %8 ], [ 2, %0 ]
%12 = srem i64 %10, %11
%13 = sdiv i64 %10, %11
%14 = icmp eq i64 %12, 0
%15 = icmp sgt i64 %11, %9
%16 = select i1 %15, i64 %11, i64 %9
%17 = select i1 %14, i64 2, i64 %11
%18 = select i1 %14, i64 %13, i64 %10
%19 = select i1 %14, i64 %16, i64 %9
%20 = add nsw i64 %17, 1
%21 = load i64, i64* %1
%22 = call i64 @sqrt(i64 %21)
%23 = icmp slt i64 %20, %22
br i1 %23, label %8, label %24
24: ; preds = %8, %0
%25 = phi i64 [ -1, %0 ], [ %19, %8 ]
%26 = load i64, i64* %1
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i64 %26, i64 %25)
ret i32 0
}