#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 */
long *prime_factors(long);
int /*<<< orphan*/ printf(char *, long, ...);
int prime_factors_test(long num, long *expected_factors,
                       int num_of_expected_factors) {
  long *factor_list = prime_factors(num);
  int i;
  if (factor_list[0] != num_of_expected_factors) {
    printf("Incorrect factorization of prime %d: %d factors given instead of "
           "%d.\n\n",
           num, factor_list[0], num_of_expected_factors);
    return 1;
  } else {
    for (i = 0; i < num_of_expected_factors; i++) {
      if (factor_list[i + 1] != expected_factors[i]) {
        printf("Incorrect 0th factor of %d: %d given.\n\b", num,
               factor_list[1]);
        return 1;
      }
    }
  }
  printf("%d factored correctly.\n\n", num);
  return 0;
}


x86 assembly (clang, -O0):
<prime_factors_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <prime_factors@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
movslq -0x1c(%rbp),%rcx
cmp    %rcx,%rax
je     117c <prime_factors_test+0x5c>
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1209 <prime_factors_test+0xe9>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11eb <prime_factors_test+0xcb>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x18(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
cmp    (%rcx,%rdx,8),%rax
je     11d8 <prime_factors_test+0xb8>
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1209 <prime_factors_test+0xe9>
jmp    11dd <prime_factors_test+0xbd>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1183 <prime_factors_test+0x63>
jmp    11f0 <prime_factors_test+0xd0>
mov    -0x10(%rbp),%rsi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prime_factors_test>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r14
call   1040 <prime_factors@plt>
mov    (%rax),%rdx
movslq %ebx,%rcx
cmp    %rcx,%rdx
jne    1183 <prime_factors_test+0x63>
xor    %ecx,%ecx
test   %ebx,%ebx
cmovle %ecx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    %rcx,%rbx
je     119d <prime_factors_test+0x7d>
mov    0x8(%rax,%rcx,8),%rdx
lea    0x1(%rcx),%rsi
cmp    (%r15,%rcx,8),%rdx
mov    %rsi,%rcx
je     1150 <prime_factors_test+0x30>
mov    0x8(%rax),%rdx
lea    0xed5(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%ebx
jmp    11b0 <prime_factors_test+0x90>
lea    0xe76(%rip),%rdi
mov    %r14,%rsi
mov    %ebx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%ebx
jmp    11b0 <prime_factors_test+0x90>
lea    0xecb(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [71 x i8] c"Incorrect factorization of prime %d: %d factors given instead of %d.\0A\0A\00"
@.str.1 = [40 x i8] c"Incorrect 0th factor of %d: %d given.\0A\08\00"
@.str.2 = [25 x i8] c"%d factored correctly.\0A\0A\00"
define i32 @prime_factors_test(i64 %0, i64* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64*
%7 = alloca i32
%8 = alloca i64*
%9 = alloca i32
store i64 %0, i64* %5
store i64* %1, i64** %6
store i32 %2, i32* %7
%10 = load i64, i64* %5
%11 = call i64* @prime_factors(i64 %10)
store i64* %11, i64** %8
%12 = load i64*, i64** %8
%13 = getelementptr inbounds i64, i64* %12, i64 0
%14 = load i64, i64* %13
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = icmp ne i64 %14, %16
br i1 %17, label %18, label %25
18: ; preds = %3
%19 = load i64, i64* %5
%20 = load i64*, i64** %8
%21 = getelementptr inbounds i64, i64* %20, i64 0
%22 = load i64, i64* %21
%23 = load i32, i32* %7
%24 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i64 %19, i64 %22, i32 %23)
store i32 1, i32* %4
br label %57
25: ; preds = %3
store i32 0, i32* %9
br label %26
26: ; preds = %50, %25
%27 = load i32, i32* %9
%28 = load i32, i32* %7
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %53
30: ; preds = %26
%31 = load i64*, i64** %8
%32 = load i32, i32* %9
%33 = add nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i64, i64* %31, i64 %34
%36 = load i64, i64* %35
%37 = load i64*, i64** %6
%38 = load i32, i32* %9
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i64, i64* %37, i64 %39
%41 = load i64, i64* %40
%42 = icmp ne i64 %36, %41
br i1 %42, label %43, label %49
43: ; preds = %30
%44 = load i64, i64* %5
%45 = load i64*, i64** %8
%46 = getelementptr inbounds i64, i64* %45, i64 1
%47 = load i64, i64* %46
%48 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i64 %44, i64 %47)
store i32 1, i32* %4
br label %57
49: ; preds = %30
br label %50
50: ; preds = %49
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
br label %26
53: ; preds = %26
br label %54
54: ; preds = %53
%55 = load i64, i64* %5
%56 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i64 %55)
store i32 0, i32* %4
br label %57
57: ; preds = %54, %43, %18
%58 = load i32, i32* %4
ret i32 %58
}

LLVM IR (-O2):
@.str = [71 x i8] c"Incorrect factorization of prime %d: %d factors given instead of %d.\0A\0A\00"
@.str.1 = [40 x i8] c"Incorrect 0th factor of %d: %d given.\0A\08\00"
@.str.2 = [25 x i8] c"%d factored correctly.\0A\0A\00"
define i32 @prime_factors_test(i64 %0, i64* nocapture %1, i32 %2) {
%4 = tail call i64* @prime_factors(i64 %0)
%5 = load i64, i64* %4
%6 = sext i32 %2 to i64
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = call i32 @llvm.smax.i32(i32 %2, i32 0)
%10 = zext i32 %9 to i64
br label %13
11: ; preds = %3
%12 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i64 %0, i64 %5, i32 %2)
br label %29
13: ; preds = %8, %16
%14 = phi i64 [ 0, %8 ], [ %17, %16 ]
%15 = icmp eq i64 %14, %10
br i1 %15, label %27, label %16
16: ; preds = %13
%17 = add nuw nsw i64 %14, 1
%18 = getelementptr inbounds i64, i64* %4, i64 %17
%19 = load i64, i64* %18
%20 = getelementptr inbounds i64, i64* %1, i64 %14
%21 = load i64, i64* %20
%22 = icmp eq i64 %19, %21
br i1 %22, label %13, label %23
23: ; preds = %16
%24 = getelementptr inbounds i64, i64* %4, i64 1
%25 = load i64, i64* %24
%26 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i64 %0, i64 %25)
br label %29
27: ; preds = %13
%28 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i64 %0)
br label %29
29: ; preds = %27, %23, %11
%30 = phi i32 [ 1, %11 ], [ 1, %23 ], [ 0, %27 ]
ret i32 %30
}