#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
long long atoll(char *);
long long ceil(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ prime(long long);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sqrt(long long);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  long long n;
  long long sqrtn;
  long long i;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <n>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  n = atoll(argv[1]);
  sqrtn = ceil(sqrt(n));
  printf("sqrtn = %lld\n", sqrtn);
  printf("\n prime factors of %lld = ", n);
  for (i = 2; i < sqrtn; i++) {
    if (prime(i)) {
      while (n % i == 0) {
        printf(" %lld ", i);
        n = n / i;
      }
      if (n == 1)
        break;
    }
  }
  if (n > 1)
    printf(" %lld ", n);
  printf("\n");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ba <main+0x4a>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoll@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <sqrt@plt>
mov    %eax,%edi
call   1030 <ceil@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x2,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    1295 <main+0x125>
mov    -0x28(%rbp),%rdi
call   1070 <prime@plt>
cmp    $0x0,%rax
je     127f <main+0x10f>
jmp    1231 <main+0xc1>
mov    -0x18(%rbp),%rax
cqto
idivq  -0x28(%rbp)
cmp    $0x0,%rdx
jne    126a <main+0xfa>
mov    -0x28(%rbp),%rsi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
cqto
idivq  -0x28(%rbp)
mov    %rax,-0x18(%rbp)
jmp    1231 <main+0xc1>
cmpq   $0x1,-0x18(%rbp)
jne    127a <main+0x10a>
jmp    1295 <main+0x125>
jmp    127f <main+0x10f>
jmp    1284 <main+0x114>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    120b <main+0x9b>
cmpq   $0x1,-0x18(%rbp)
jle    12b2 <main+0x142>
mov    -0x18(%rbp),%rsi
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    1281 <main+0x101>
mov    0x8(%rsi),%rdi
call   1060 <atoll@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1090 <sqrt@plt>
mov    %eax,%edi
call   1040 <ceil@plt>
mov    %rax,%r14
lea    0xe59(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe56(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x3,%r14
jl     12a7 <main+0x127>
mov    $0x2,%ebx
lea    0xe51(%rip),%r12
jmp    1207 <main+0x87>
nopl   0x0(%rax)
cmp    $0x1,%r15
je     12be <main+0x13e>
add    $0x1,%rbx
cmp    %r14,%rbx
je     12a7 <main+0x127>
mov    %rbx,%rdi
call   1080 <prime@plt>
test   %rax,%rax
jne    122b <main+0xab>
jmp    11fa <main+0x7a>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rax
cqto
idiv   %rbx
mov    %rax,%r15
mov    %r15,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     1250 <main+0xd0>
mov    %r15,%rax
cqto
idiv   %rbx
test   %rdx,%rdx
je     125c <main+0xdc>
jmp    11f0 <main+0x70>
cs nopw 0x0(%rax,%rax,1)
mov    %r15d,%eax
xor    %edx,%edx
div    %ebx
test   %rdx,%rdx
jne    11f0 <main+0x70>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rax
or     %rbx,%rax
shr    $0x20,%rax
jne    1220 <main+0xa0>
mov    %r15d,%eax
xor    %edx,%edx
div    %ebx
mov    %eax,%r15d
jmp    122b <main+0xab>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd6c(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
cmp    $0x2,%r15
jl     12be <main+0x13e>
lea    0xd84(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"Usage: %s <n>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"sqrtn = %lld\0A\00"
@.str.2 = [27 x i8] c"\0A prime factors of %lld = \00"
@.str.3 = [7 x i8] c" %lld \00"
@.str.4 = [2 x i8] c"\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @atoll(i8* %22)
store i64 %23, i64* %6
%24 = load i64, i64* %6
%25 = call i32 @sqrt(i64 %24)
%26 = call i64 @ceil(i32 %25)
store i64 %26, i64* %7
%27 = load i64, i64* %7
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %27)
%29 = load i64, i64* %6
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 %29)
store i64 2, i64* %8
br label %31
31: ; preds = %57, %19
%32 = load i64, i64* %8
%33 = load i64, i64* %7
%34 = icmp slt i64 %32, %33
br i1 %34, label %35, label %60
35: ; preds = %31
%36 = load i64, i64* %8
%37 = call i64 @prime(i64 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %56
39: ; preds = %35
br label %40
40: ; preds = %45, %39
%41 = load i64, i64* %6
%42 = load i64, i64* %8
%43 = srem i64 %41, %42
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %51
45: ; preds = %40
%46 = load i64, i64* %8
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 %46)
%48 = load i64, i64* %6
%49 = load i64, i64* %8
%50 = sdiv i64 %48, %49
store i64 %50, i64* %6
br label %40
51: ; preds = %40
%52 = load i64, i64* %6
%53 = icmp eq i64 %52, 1
br i1 %53, label %54, label %55
54: ; preds = %51
br label %60
55: ; preds = %51
br label %56
56: ; preds = %55, %35
br label %57
57: ; preds = %56
%58 = load i64, i64* %8
%59 = add nsw i64 %58, 1
store i64 %59, i64* %8
br label %31
60: ; preds = %54, %31
%61 = load i64, i64* %6
%62 = icmp sgt i64 %61, 1
br i1 %62, label %63, label %66
63: ; preds = %60
%64 = load i64, i64* %6
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 %64)
br label %66
66: ; preds = %63, %60
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%68 = load i32, i32* @EXIT_SUCCESS
%69 = call i32 @exit(i32 %68)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"Usage: %s <n>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"sqrtn = %lld\0A\00"
@.str.2 = [27 x i8] c"\0A prime factors of %lld = \00"
@.str.3 = [7 x i8] c" %lld \00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @atoll(i8* %12)
%14 = tail call i32 @sqrt(i64 %13)
%15 = tail call i64 @ceil(i32 %14)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %15)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 %13)
%18 = icmp sgt i64 %15, 2
br i1 %18, label %19, label %40
19: ; preds = %10, %36
%20 = phi i64 [ %38, %36 ], [ 2, %10 ]
%21 = phi i64 [ %37, %36 ], [ %13, %10 ]
%22 = tail call i64 @prime(i64 %20)
%23 = icmp eq i64 %22, 0
br i1 %23, label %36, label %24
24: ; preds = %19
%25 = srem i64 %21, %20
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %24, %27
%28 = phi i64 [ %30, %27 ], [ %21, %24 ]
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 %20)
%30 = sdiv i64 %28, %20
%31 = srem i64 %30, %20
%32 = icmp eq i64 %31, 0
br i1 %32, label %27, label %33
33: ; preds = %27, %24
%34 = phi i64 [ %21, %24 ], [ %30, %27 ]
%35 = icmp eq i64 %34, 1
br i1 %35, label %45, label %36
36: ; preds = %19, %33
%37 = phi i64 [ %34, %33 ], [ %21, %19 ]
%38 = add nuw nsw i64 %20, 1
%39 = icmp eq i64 %38, %15
br i1 %39, label %40, label %19
40: ; preds = %36, %10
%41 = phi i64 [ %13, %10 ], [ %37, %36 ]
%42 = icmp sgt i64 %41, 1
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 %41)
br label %45
45: ; preds = %33, %43, %40
%46 = tail call i32 @putchar(i32 10)
%47 = load i32, i32* @EXIT_SUCCESS
%48 = tail call i32 @exit(i32 %47)
unreachable
}