#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*/ assert(int);
unsigned long __ecm_find_factor(const unsigned long N) {
  unsigned long i;
  assert(N != 0UL);
  if (N == 1UL)
    return 1UL;
  if (N % 2UL == 0UL)
    return 2UL;
  for (i = 3UL; i * i <= N; i += 2UL)
    if (N % i == 0UL)
      return i;
  return N;
}


x86 assembly (clang, -O0):
<__ecm_find_factor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x1,-0x10(%rbp)
jne    1146 <__ecm_find_factor+0x36>
movq   $0x1,-0x8(%rbp)
jmp    11c1 <__ecm_find_factor+0xb1>
mov    -0x10(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    1165 <__ecm_find_factor+0x55>
movq   $0x2,-0x8(%rbp)
jmp    11c1 <__ecm_find_factor+0xb1>
movq   $0x3,-0x18(%rbp)
mov    -0x18(%rbp),%rax
imul   -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     11b9 <__ecm_find_factor+0xa9>
mov    -0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
cmp    $0x0,%rdx
jne    11a3 <__ecm_find_factor+0x93>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c1 <__ecm_find_factor+0xb1>
jmp    11a8 <__ecm_find_factor+0x98>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    116d <__ecm_find_factor+0x5d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__ecm_find_factor>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
mov    $0x1,%ecx
cmp    $0x1,%rbx
je     118e <__ecm_find_factor+0x7e>
mov    $0x2,%ecx
test   $0x1,%bl
je     118e <__ecm_find_factor+0x7e>
cmp    $0x9,%rbx
jb     118b <__ecm_find_factor+0x7b>
mov    $0x3,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     1170 <__ecm_find_factor+0x60>
mov    %rbx,%rax
xor    %edx,%edx
div    %rcx
test   %rdx,%rdx
jne    117b <__ecm_find_factor+0x6b>
jmp    118e <__ecm_find_factor+0x7e>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
test   %rdx,%rdx
je     118e <__ecm_find_factor+0x7e>
add    $0x2,%rcx
mov    %rcx,%rax
imul   %rcx,%rax
cmp    %rbx,%rax
jbe    1150 <__ecm_find_factor+0x40>
mov    %rbx,%rcx
mov    %rcx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @__ecm_find_factor(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
%5 = load i64, i64* %3
%6 = icmp ne i64 %5, 0
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i64, i64* %3
%10 = icmp eq i64 %9, 1
br i1 %10, label %11, label %12
11: ; preds = %1
store i64 1, i64* %2
br label %37
12: ; preds = %1
%13 = load i64, i64* %3
%14 = urem i64 %13, 2
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
store i64 2, i64* %2
br label %37
17: ; preds = %12
store i64 3, i64* %4
br label %18
18: ; preds = %32, %17
%19 = load i64, i64* %4
%20 = load i64, i64* %4
%21 = mul i64 %19, %20
%22 = load i64, i64* %3
%23 = icmp ule i64 %21, %22
br i1 %23, label %24, label %35
24: ; preds = %18
%25 = load i64, i64* %3
%26 = load i64, i64* %4
%27 = urem i64 %25, %26
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = load i64, i64* %4
store i64 %30, i64* %2
br label %37
31: ; preds = %24
br label %32
32: ; preds = %31
%33 = load i64, i64* %4
%34 = add i64 %33, 2
store i64 %34, i64* %4
br label %18
35: ; preds = %18
%36 = load i64, i64* %3
store i64 %36, i64* %2
br label %37
37: ; preds = %35, %29, %16, %11
%38 = load i64, i64* %2
ret i64 %38
}

LLVM IR (-O2):
define i64 @__ecm_find_factor(i64 %0) {
%2 = icmp ne i64 %0, 0
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = icmp eq i64 %0, 1
br i1 %5, label %19, label %6
6: ; preds = %1
%7 = and i64 %0, 1
%8 = icmp eq i64 %7, 0
br i1 %8, label %19, label %9
9: ; preds = %6
%10 = icmp ult i64 %0, 9
br i1 %10, label %19, label %11
11: ; preds = %9, %15
%12 = phi i64 [ %16, %15 ], [ 3, %9 ]
%13 = urem i64 %0, %12
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = add i64 %12, 2
%17 = mul i64 %16, %16
%18 = icmp ugt i64 %17, %0
br i1 %18, label %19, label %11
19: ; preds = %11, %15, %9, %6, %1
%20 = phi i64 [ 1, %1 ], [ 2, %6 ], [ %0, %9 ], [ %12, %11 ], [ %0, %15 ]
ret i64 %20
}