#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 */
scalar_t__ isPrime(int);
int sumOfPrimeFactors(int n) {
  int sum = 0;
  int divisor = 2;
  while (n > 1) {
    if (isPrime(divisor) && (n % divisor == 0)) {
      sum += divisor;
      n /= divisor;
    } else {
      divisor++;
    }
  }
  return sum;
}


x86 assembly (clang, -O0):
<sumOfPrimeFactors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
cmpl   $0x1,-0x4(%rbp)
jle    117d <sumOfPrimeFactors+0x6d>
mov    -0xc(%rbp),%edi
call   1030 <isPrime@plt>
cmp    $0x0,%rax
je     116f <sumOfPrimeFactors+0x5f>
mov    -0x4(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    116f <sumOfPrimeFactors+0x5f>
mov    -0xc(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x4(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1178 <sumOfPrimeFactors+0x68>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1129 <sumOfPrimeFactors+0x19>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sumOfPrimeFactors>:
push   %rbp
push   %r14
push   %rbx
xor    %r14d,%r14d
cmp    $0x2,%edi
jl     1157 <sumOfPrimeFactors+0x47>
mov    %edi,%ebp
xor    %r14d,%r14d
mov    $0x2,%ebx
jmp    1138 <sumOfPrimeFactors+0x28>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    $0x1,%ebp
jle    1157 <sumOfPrimeFactors+0x47>
mov    %ebx,%edi
call   1030 <isPrime@plt>
test   %rax,%rax
je     1130 <sumOfPrimeFactors+0x20>
mov    %ebp,%eax
cltd
idiv   %ebx
test   %edx,%edx
jne    1130 <sumOfPrimeFactors+0x20>
add    %ebx,%r14d
mov    %eax,%ebp
cmp    $0x1,%ebp
jg     1138 <sumOfPrimeFactors+0x28>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sumOfPrimeFactors(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 2, i32* %4
br label %5
5: ; preds = %27, %1
%6 = load i32, i32* %2
%7 = icmp sgt i32 %6, 1
br i1 %7, label %8, label %28
8: ; preds = %5
%9 = load i32, i32* %4
%10 = call i64 @isPrime(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %8
%13 = load i32, i32* %2
%14 = load i32, i32* %4
%15 = srem i32 %13, %14
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %12
%18 = load i32, i32* %4
%19 = load i32, i32* %3
%20 = add nsw i32 %19, %18
store i32 %20, i32* %3
%21 = load i32, i32* %4
%22 = load i32, i32* %2
%23 = sdiv i32 %22, %21
store i32 %23, i32* %2
br label %27
24: ; preds = %12, %8
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %27
27: ; preds = %24, %17
br label %5
28: ; preds = %5
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @sumOfPrimeFactors(i32 %0) {
%2 = icmp sgt i32 %0, 1
br i1 %2, label %3, label %22
3: ; preds = %1, %17
%4 = phi i32 [ %20, %17 ], [ 2, %1 ]
%5 = phi i32 [ %19, %17 ], [ 0, %1 ]
%6 = phi i32 [ %18, %17 ], [ %0, %1 ]
%7 = tail call i64 @isPrime(i32 %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %3
%10 = srem i32 %6, %4
%11 = sdiv i32 %6, %4
%12 = icmp eq i32 %10, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = add nsw i32 %4, %5
br label %17
15: ; preds = %9, %3
%16 = add nsw i32 %4, 1
br label %17
17: ; preds = %15, %13
%18 = phi i32 [ %11, %13 ], [ %6, %15 ]
%19 = phi i32 [ %14, %13 ], [ %5, %15 ]
%20 = phi i32 [ %4, %13 ], [ %16, %15 ]
%21 = icmp sgt i32 %18, 1
br i1 %21, label %3, label %22
22: ; preds = %17, %1
%23 = phi i32 [ 0, %1 ], [ %19, %17 ]
ret i32 %23
}