#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void primeFactorization() {
  int input;
  printf("Enter number to be factorized:\n");
  scanf("%d", &input);
  printf("The prime factorization of %d is:\n", input);
  while (input > 1) {
    for (int i = 2; i <= input; i++) {
      if (input % i == 0) {
        input /= i;
        printf("%d, ", i);
        break;
      }
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<primeFactorization>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee3(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x4(%rbp),%esi
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1,-0x4(%rbp)
jle    11be <primeFactorization+0x9e>
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11b9 <primeFactorization+0x99>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
cmp    $0x0,%edx
jne    11a6 <primeFactorization+0x86>
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%esi
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b9 <primeFactorization+0x99>
jmp    11ab <primeFactorization+0x8b>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1168 <primeFactorization+0x48>
jmp    1157 <primeFactorization+0x37>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<primeFactorization>:
push   %rbx
sub    $0x10,%rsp
lea    0xedf(%rip),%rdi
call   1040 <puts@plt>
lea    0xea8(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%esi
lea    0xe96(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%ecx
cmp    $0x2,%ecx
jl     11cd <primeFactorization+0x8d>
lea    0xea2(%rip),%rbx
jmp    11a7 <primeFactorization+0x67>
cs nopw 0x0(%rax,%rax,1)
mov    %eax,0xc(%rsp)
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%ecx
cmp    $0x1,%ecx
jle    11cd <primeFactorization+0x8d>
mov    %ecx,%edi
neg    %edi
mov    $0x2,%esi
mov    %ecx,%eax
cltd
idiv   %esi
test   %edx,%edx
je     1190 <primeFactorization+0x50>
lea    (%rdi,%rsi,1),%eax
add    $0x1,%eax
mov    %esi,%edx
add    $0x1,%edx
mov    %edx,%esi
cmp    $0x1,%eax
jne    11b0 <primeFactorization+0x70>
jmp    11a2 <primeFactorization+0x62>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Enter number to be factorized:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [35 x i8] c"The prime factorization of %d is:\0A\00"
@.str.3 = [5 x i8] c"%d, \00"
@.str.4 = [2 x i8] c"\0A\00"
define void @primeFactorization() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %5)
br label %7
7: ; preds = %30, %0
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %31
10: ; preds = %7
store i32 2, i32* %2
br label %11
11: ; preds = %27, %10
%12 = load i32, i32* %2
%13 = load i32, i32* %1
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = load i32, i32* %1
%17 = load i32, i32* %2
%18 = srem i32 %16, %17
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = load i32, i32* %2
%22 = load i32, i32* %1
%23 = sdiv i32 %22, %21
store i32 %23, i32* %1
%24 = load i32, i32* %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %24)
br label %30
26: ; preds = %15
br label %27
27: ; preds = %26
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %11
30: ; preds = %20, %11
br label %7
31: ; preds = %7
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [35 x i8] c"The prime factorization of %d is:\0A\00"
@.str.3 = [5 x i8] c"%d, \00"
@str = [31 x i8] c"Enter number to be factorized:\00"
define void @primeFactorization() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = load i32, i32* %1
%8 = icmp sgt i32 %7, 1
br i1 %8, label %9, label %25
9: ; preds = %0, %22
%10 = phi i32 [ %23, %22 ], [ %7, %0 ]
br label %11
11: ; preds = %9, %19
%12 = phi i32 [ %20, %19 ], [ 2, %9 ]
%13 = srem i32 %10, %12
%14 = sdiv i32 %10, %12
%15 = icmp eq i32 %13, 0
br i1 %15, label %16, label %19
16: ; preds = %11
store i32 %14, i32* %1
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%18 = load i32, i32* %1
br label %22
19: ; preds = %11
%20 = add nuw i32 %12, 1
%21 = icmp eq i32 %12, %10
br i1 %21, label %22, label %11
22: ; preds = %19, %16
%23 = phi i32 [ %18, %16 ], [ %10, %19 ]
%24 = icmp sgt i32 %23, 1
br i1 %24, label %9, label %25
25: ; preds = %22, %0
%26 = call i32 @putchar(i32 10)
ret void
}