#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 *);
int main() {
  long stevilo;
  printf("Please insert a number:\n");
  scanf("%ld", &stevilo);
  long printaj = stevilo;
  int max = 0;
  int i;
  while (stevilo % 2 == 0) {
    stevilo /= 2;
    max = 2;
  }
  for (i = 3; i <= stevilo; i++) {
    while (stevilo % i == 0) {
      stevilo /= i;
      max = i;
    }
  }
  printf("The largest prime factor of number %ld is:\n", printaj);
  if (max == 0) {
    printf("Number %ld doesnt have prime factor\n", printaj);
    return 0;
  }
  printf("%d\n", max);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed5(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    1192 <main+0x72>
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
movl   $0x2,-0x1c(%rbp)
jmp    115c <main+0x3c>
movl   $0x3,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jg     11f2 <main+0xd2>
jmp    11ac <main+0x8c>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    11df <main+0xbf>
movslq -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11ac <main+0x8c>
jmp    11e4 <main+0xc4>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1199 <main+0x79>
mov    -0x18(%rbp),%rsi
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    122c <main+0x10c>
mov    -0x18(%rbp),%rsi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1244 <main+0x124>
mov    -0x1c(%rbp),%esi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xf1f(%rip),%rdi
call   1030 <puts@plt>
lea    0xeba(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
mov    (%rsp),%rbx
xor    %ebp,%ebp
mov    %rbx,%rcx
test   $0x1,%bl
jne    117b <main+0x4b>
mov    %rbx,%rcx
nop
mov    %rcx,%rax
shr    $0x3f,%rax
add    %rax,%rcx
sar    %rcx
test   $0x1,%cl
je     1160 <main+0x30>
mov    %rcx,(%rsp)
mov    $0x2,%ebp
cmp    $0x3,%rcx
jge    11af <main+0x7f>
lea    0xe7c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
je     1254 <main+0x124>
lea    0xeb4(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1265 <main+0x135>
mov    $0x3,%esi
jmp    11d2 <main+0xa2>
cs nopw 0x0(%rax,%rax,1)
mov    %rcx,(%rsp)
mov    %esi,%ebp
lea    0x1(%rsi),%rax
cmp    %rsi,%rcx
mov    %rax,%rsi
jle    1181 <main+0x51>
mov    %rcx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     11f0 <main+0xc0>
mov    %rcx,%rax
cqto
idiv   %rsi
test   %rdx,%rdx
jne    11c6 <main+0x96>
jmp    120d <main+0xdd>
nopl   (%rax)
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
test   %rdx,%rdx
jne    11c6 <main+0x96>
jmp    120d <main+0xdd>
nopl   (%rax)
mov    %rcx,%rax
cqto
idiv   %rsi
test   %rdx,%rdx
jne    11c0 <main+0x90>
mov    %rcx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     1230 <main+0x100>
mov    %rcx,%rax
cqto
idiv   %rsi
mov    %rax,%rcx
jmp    1238 <main+0x108>
cs nopw 0x0(%rax,%rax,1)
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
mov    %eax,%ecx
mov    %rcx,%rax
or     %rsi,%rax
shr    $0x20,%rax
jne    1200 <main+0xd0>
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
test   %rdx,%rdx
je     120d <main+0xdd>
jmp    11c0 <main+0x90>
lea    0xdd5(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Please insert a number:\0A\00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [44 x i8] c"The largest prime factor of number %ld is:\0A\00"
@.str.3 = [37 x i8] c"Number %ld doesnt have prime factor\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 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* %3
store i32 0, i32* %4
br label %9
9: ; preds = %13, %0
%10 = load i64, i64* %2
%11 = srem i64 %10, 2
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i64, i64* %2
%15 = sdiv i64 %14, 2
store i64 %15, i64* %2
store i32 2, i32* %4
br label %9
16: ; preds = %9
store i32 3, i32* %5
br label %17
17: ; preds = %36, %16
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = load i64, i64* %2
%21 = icmp sle i64 %19, %20
br i1 %21, label %22, label %39
22: ; preds = %17
br label %23
23: ; preds = %29, %22
%24 = load i64, i64* %2
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = srem i64 %24, %26
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %23
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = load i64, i64* %2
%33 = sdiv i64 %32, %31
store i64 %33, i64* %2
%34 = load i32, i32* %5
store i32 %34, i32* %4
br label %23
35: ; preds = %23
br label %36
36: ; preds = %35
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %17
39: ; preds = %17
%40 = load i64, i64* %3
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i64 %40)
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = load i64, i64* %3
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i64 %45)
store i32 0, i32* %1
br label %50
47: ; preds = %39
%48 = load i32, i32* %4
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %48)
store i32 0, i32* %1
br label %50
50: ; preds = %47, %44
%51 = load i32, i32* %1
ret i32 %51
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [44 x i8] c"The largest prime factor of number %ld is:\0A\00"
@.str.3 = [37 x i8] c"Number %ld doesnt have prime factor\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@str = [24 x i8] c"Please insert a number:\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 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 = and i64 %5, 1
%7 = icmp eq i64 %6, 0
br i1 %7, label %13, label %9
8: ; preds = %13
store i64 %15, i64* %1
br label %9
9: ; preds = %8, %0
%10 = phi i64 [ %15, %8 ], [ %5, %0 ]
%11 = phi i32 [ 2, %8 ], [ 0, %0 ]
%12 = icmp slt i64 %10, 3
br i1 %12, label %36, label %18
13: ; preds = %0, %13
%14 = phi i64 [ %15, %13 ], [ %5, %0 ]
%15 = sdiv i64 %14, 2
%16 = and i64 %15, 1
%17 = icmp eq i64 %16, 0
br i1 %17, label %13, label %8
18: ; preds = %9, %31
%19 = phi i64 [ %34, %31 ], [ 3, %9 ]
%20 = phi i32 [ %33, %31 ], [ %11, %9 ]
%21 = phi i64 [ %32, %31 ], [ %10, %9 ]
%22 = srem i64 %21, %19
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %18, %24
%25 = phi i64 [ %26, %24 ], [ %21, %18 ]
%26 = sdiv i64 %25, %19
%27 = srem i64 %26, %19
%28 = icmp eq i64 %27, 0
br i1 %28, label %24, label %29
29: ; preds = %24
store i64 %26, i64* %1
%30 = trunc i64 %19 to i32
br label %31
31: ; preds = %29, %18
%32 = phi i64 [ %26, %29 ], [ %21, %18 ]
%33 = phi i32 [ %30, %29 ], [ %20, %18 ]
%34 = add nuw nsw i64 %19, 1
%35 = icmp sgt i64 %32, %19
br i1 %35, label %18, label %36
36: ; preds = %31, %9
%37 = phi i32 [ %11, %9 ], [ %33, %31 ]
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i64 %5)
%39 = icmp eq i32 %37, 0
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i64 %5)
br label %44
42: ; preds = %36
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %37)
br label %44
44: ; preds = %42, %40
ret i32 0
}