#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 */
double floorf(double);
int /*<<< orphan*/ printf(char *, double, ...);
int main() {
  double num = 600851475143;
  printf("Init Num: %f\n", num);
  double factor;
  double item;
  for (int i = 2; i < 100000; i++) {
    factor = num / i;
    if (floorf(factor) == factor) {
      printf("found factor: %f * %d\n", factor, i);
      item = factor;
    }
  }
  for (int i = 2; i < 1000000; i++) {
    double prime = item / i;
    if (floorf(prime) == prime) {
      printf("found primal factor: %f * %d\n", prime, i);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xec9(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    0xec0(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x2,-0x24(%rbp)
cmpl   $0x186a0,-0x24(%rbp)
jge    11c4 <main+0xa4>
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <floorf@plt>
ucomisd -0x18(%rbp),%xmm0
jne    11b1 <main+0x91>
jp     11b1 <main+0x91>
movsd  -0x18(%rbp),%xmm0
mov    -0x24(%rbp),%esi
lea    0xe76(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11b6 <main+0x96>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1156 <main+0x36>
movl   $0x2,-0x28(%rbp)
cmpl   $0xf4240,-0x28(%rbp)
jge    122f <main+0x10f>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <floorf@plt>
ucomisd -0x30(%rbp),%xmm0
jne    121c <main+0xfc>
jp     121c <main+0xfc>
movsd  -0x30(%rbp),%xmm0
mov    -0x28(%rbp),%esi
lea    0xe18(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1221 <main+0x101>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11cb <main+0xab>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xeea(%rip),%rdi
movsd  0xeca(%rip),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
mov    $0x2,%ebx
movsd  0xebe(%rip),%xmm1
lea    0xed5(%rip),%r14
jmp    1179 <main+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  0x8(%rsp),%xmm1
addsd  0xea2(%rip),%xmm1
add    $0x1,%ebx
cmp    $0x186a0,%ebx
je     11bf <main+0x9f>
movsd  0xe7f(%rip),%xmm0
movsd  %xmm1,0x8(%rsp)
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
call   1040 <floorf@plt>
movsd  (%rsp),%xmm2
ucomisd %xmm2,%xmm0
jne    1160 <main+0x40>
jp     1160 <main+0x40>
mov    %r14,%rdi
movapd %xmm2,%xmm0
mov    %ebx,%esi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  (%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
jmp    1160 <main+0x40>
mov    $0x2,%ebx
movsd  0xe3c(%rip),%xmm1
lea    0xe6a(%rip),%r14
jmp    11f8 <main+0xd8>
cs nopw 0x0(%rax,%rax,1)
nop
movsd  (%rsp),%xmm1
addsd  0xe23(%rip),%xmm1
add    $0x1,%ebx
cmp    $0xf4240,%ebx
je     1232 <main+0x112>
movsd  0x10(%rsp),%xmm0
movsd  %xmm1,(%rsp)
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1040 <floorf@plt>
movsd  0x8(%rsp),%xmm1
ucomisd %xmm1,%xmm0
jne    11e0 <main+0xc0>
jp     11e0 <main+0xc0>
movapd %xmm1,%xmm0
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    11e0 <main+0xc0>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Init Num: %f\0A\00"
@.str.1 = [23 x i8] c"found factor: %f * %d\0A\00"
@.str.2 = [30 x i8] c"found primal factor: %f * %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
store i32 0, i32* %1
store double 0x42617CB13D58E000, double* %2
%8 = load double, double* %2
%9 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double %8)
store i32 2, i32* %5
br label %10
10: ; preds = %28, %0
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 100000
br i1 %12, label %13, label %31
13: ; preds = %10
%14 = load double, double* %2
%15 = load i32, i32* %5
%16 = sitofp i32 %15 to double
%17 = fdiv double %14, %16
store double %17, double* %3
%18 = load double, double* %3
%19 = call double @floorf(double %18)
%20 = load double, double* %3
%21 = fcmp oeq double %19, %20
br i1 %21, label %22, label %27
22: ; preds = %13
%23 = load double, double* %3
%24 = load i32, i32* %5
%25 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), double %23, i32 %24)
%26 = load double, double* %3
store double %26, double* %4
br label %27
27: ; preds = %22, %13
br label %28
28: ; preds = %27
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %10
31: ; preds = %10
store i32 2, i32* %6
br label %32
32: ; preds = %49, %31
%33 = load i32, i32* %6
%34 = icmp slt i32 %33, 1000000
br i1 %34, label %35, label %52
35: ; preds = %32
%36 = load double, double* %4
%37 = load i32, i32* %6
%38 = sitofp i32 %37 to double
%39 = fdiv double %36, %38
store double %39, double* %7
%40 = load double, double* %7
%41 = call double @floorf(double %40)
%42 = load double, double* %7
%43 = fcmp oeq double %41, %42
br i1 %43, label %44, label %48
44: ; preds = %35
%45 = load double, double* %7
%46 = load i32, i32* %6
%47 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), double %45, i32 %46)
br label %48
48: ; preds = %44, %35
br label %49
49: ; preds = %48
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
br label %32
52: ; preds = %32
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"Init Num: %f\0A\00"
@.str.1 = [23 x i8] c"found factor: %f * %d\0A\00"
@.str.2 = [30 x i8] c"found primal factor: %f * %d\0A\00"
define i32 @main() {
%1 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double 0x42617CB13D58E000)
br label %2
2: ; preds = %0, %11
%3 = phi double [ undef, %0 ], [ %12, %11 ]
%4 = phi i32 [ 2, %0 ], [ %13, %11 ]
%5 = sitofp i32 %4 to double
%6 = fdiv double 0x42617CB13D58E000, %5
%7 = tail call double @floorf(double %6)
%8 = fcmp oeq double %7, %6
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), double %6, i32 %4)
br label %11
11: ; preds = %2, %9
%12 = phi double [ %6, %9 ], [ %3, %2 ]
%13 = add nuw nsw i32 %4, 1
%14 = icmp eq i32 %13, 100000
br i1 %14, label %16, label %2
15: ; preds = %24
ret i32 0
16: ; preds = %11, %24
%17 = phi i32 [ %25, %24 ], [ 2, %11 ]
%18 = sitofp i32 %17 to double
%19 = fdiv double %12, %18
%20 = tail call double @floorf(double %19)
%21 = fcmp oeq double %20, %19
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), double %19, i32 %17)
br label %24
24: ; preds = %22, %16
%25 = add nuw nsw i32 %17, 1
%26 = icmp eq i32 %25, 1000000
br i1 %26, label %15, label %16
}