#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 */
struct timeval {
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  struct timeval stop, start;
  gettimeofday(&start, NULL);
  long long number = 600851475143;
  int maxprimenumber = 2, primenumber = 2;
  while (number > 2) {
    primenumber = 1;
    while (number % (++primenumber))
      ;
    number /= primenumber;
    if (maxprimenumber < primenumber) {
      maxprimenumber = primenumber;
    }
  }
  printf("max prime number = %d", maxprimenumber);
  gettimeofday(&stop, NULL);
  printf("\ntook %lu usec\n", stop.tv_usec - start.tv_usec);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movabs $0x8be589eac7,%rax
mov    %rax,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
movl   $0x2,-0x20(%rbp)
cmpq   $0x2,-0x18(%rbp)
jle    11b6 <main+0x96>
movl   $0x1,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x20(%rbp)
movslq %ecx,%rcx
cqto
idiv   %rcx
cmp    $0x0,%rdx
je     118e <main+0x6e>
jmp    116a <main+0x4a>
movslq -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11b1 <main+0x91>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1158 <main+0x38>
mov    -0x1c(%rbp),%esi
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x8(%rbp),%esi
sub    -0x10(%rbp),%esi
lea    0xe37(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movabs $0x8be589eac7,%rcx
mov    $0x2,%esi
jmp    1174 <main+0x54>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %esi,%r9d
mov    %rcx,%rax
shr    $0x20,%rax
je     11b0 <main+0x90>
mov    %rcx,%rax
cqto
idiv   %r9
mov    %rax,%rcx
cmp    %edi,%r8d
cmovg  %r8d,%esi
cmp    $0x2,%rcx
jle    11bb <main+0x9b>
mov    %esi,%r8d
mov    $0x1,%esi
xor    %edi,%edi
jmp    1190 <main+0x70>
mov    %rcx,%rax
cqto
idiv   %rsi
add    $0x1,%edi
test   %rdx,%rdx
je     1150 <main+0x30>
add    $0x1,%rsi
mov    %rcx,%rax
or     %rsi,%rax
shr    $0x20,%rax
jne    1180 <main+0x60>
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
jmp    1188 <main+0x68>
nopl   0x0(%rax,%rax,1)
mov    %ecx,%eax
xor    %edx,%edx
div    %r9d
mov    %eax,%ecx
jmp    1167 <main+0x47>
lea    0xe3e(%rip),%rdi
call   1030 <printf@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x10(%rsp),%esi
sub    0x8(%rsp),%esi
lea    0xe34(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@.str = [22 x i8] c"max prime number = %d\00"
@.str.1 = [16 x i8] c"\0Atook %lu usec\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
store i64 600851475143, i64* %4
store i32 2, i32* %5
store i32 2, i32* %6
br label %8
8: ; preds = %30, %0
%9 = load i64, i64* %4
%10 = icmp sgt i64 %9, 2
br i1 %10, label %11, label %31
11: ; preds = %8
store i32 1, i32* %6
br label %12
12: ; preds = %19, %11
%13 = load i64, i64* %4
%14 = load i32, i32* %6
%15 = add nsw i32 %14, 1
store i32 %15, i32* %6
%16 = sext i32 %15 to i64
%17 = srem i64 %13, %16
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %12
br label %12
20: ; preds = %12
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = load i64, i64* %4
%24 = sdiv i64 %23, %22
store i64 %24, i64* %4
%25 = load i32, i32* %5
%26 = load i32, i32* %6
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = load i32, i32* %6
store i32 %29, i32* %5
br label %30
30: ; preds = %28, %20
br label %8
31: ; preds = %8
%32 = load i32, i32* %5
%33 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%36 = load i32, i32* %35
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%38 = load i32, i32* %37
%39 = sub nsw i32 %36, %38
%40 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@.str = [22 x i8] c"max prime number = %d\00"
@.str.1 = [16 x i8] c"\0Atook %lu usec\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
br label %6
6: ; preds = %0, %14
%7 = phi i32 [ 2, %0 ], [ %20, %14 ]
%8 = phi i64 [ 600851475143, %0 ], [ %18, %14 ]
br label %9
9: ; preds = %6, %9
%10 = phi i64 [ 1, %6 ], [ %11, %9 ]
%11 = add nuw nsw i64 %10, 1
%12 = srem i64 %8, %11
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %9
14: ; preds = %9
%15 = trunc i64 %10 to i32
%16 = trunc i64 %11 to i32
%17 = and i64 %11, 4294967295
%18 = sdiv i64 %8, %17
%19 = icmp sgt i32 %7, %15
%20 = select i1 %19, i32 %7, i32 %16
%21 = icmp sgt i64 %18, 2
br i1 %21, label %6, label %22
22: ; preds = %14
%23 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %20)
%24 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%28 = load i32, i32* %27
%29 = sub nsw i32 %26, %28
%30 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %29)
ret i32 0
}