#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 *, long long, ...);
void reverse_factorial(long long int factorial) {
  long long int n = 1, m = 0;
  while (m < 100) {
    m += 1;
    n *= m;
    if (factorial == n) {
      printf("%lli is %lli!\n", factorial, m);
      break;
    } else if (m == 100)
      printf("%lli is not a factorial product of any integer\n", factorial);
  }
}


x86 assembly (clang, -O0):
<reverse_factorial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x1,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x64,-0x18(%rbp)
jge    11a0 <reverse_factorial+0x90>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
imul   -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1179 <reverse_factorial+0x69>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a0 <reverse_factorial+0x90>
cmpq   $0x64,-0x18(%rbp)
jne    1196 <reverse_factorial+0x86>
mov    -0x8(%rbp),%rsi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119b <reverse_factorial+0x8b>
jmp    112c <reverse_factorial+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_factorial>:
mov    %rdi,%rsi
mov    $0x1,%ecx
mov    $0x5,%eax
nopl   (%rax)
lea    -0x4(%rax),%rdx
imul   %rdx,%rcx
cmp    %rsi,%rcx
je     1178 <reverse_factorial+0x68>
lea    -0x3(%rax),%rdx
imul   %rdx,%rcx
cmp    %rsi,%rcx
je     1178 <reverse_factorial+0x68>
lea    -0x2(%rax),%rdx
imul   %rdx,%rcx
cmp    %rsi,%rcx
je     1178 <reverse_factorial+0x68>
lea    -0x1(%rax),%rdx
imul   %rdx,%rcx
cmp    %rsi,%rcx
je     1178 <reverse_factorial+0x68>
imul   %rax,%rcx
cmp    %rsi,%rcx
je     1175 <reverse_factorial+0x65>
add    $0x5,%rax
cmp    $0x69,%rax
jne    1120 <reverse_factorial+0x10>
lea    0xea1(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
mov    %rax,%rdx
lea    0xe81(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"%lli is %lli!\0A\00"
@.str.1 = [48 x i8] c"%lli is not a factorial product of any integer\0A\00"
define void @reverse_factorial(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %2
store i64 1, i64* %3
store i64 0, i64* %4
br label %5
5: ; preds = %28, %1
%6 = load i64, i64* %4
%7 = icmp slt i64 %6, 100
br i1 %7, label %8, label %29
8: ; preds = %5
%9 = load i64, i64* %4
%10 = add nsw i64 %9, 1
store i64 %10, i64* %4
%11 = load i64, i64* %4
%12 = load i64, i64* %3
%13 = mul nsw i64 %12, %11
store i64 %13, i64* %3
%14 = load i64, i64* %2
%15 = load i64, i64* %3
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %21
17: ; preds = %8
%18 = load i64, i64* %2
%19 = load i64, i64* %4
%20 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 %18, i64 %19)
br label %29
21: ; preds = %8
%22 = load i64, i64* %4
%23 = icmp eq i64 %22, 100
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i64, i64* %2
%26 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i64 %25)
br label %27
27: ; preds = %24, %21
br label %28
28: ; preds = %27
br label %5
29: ; preds = %17, %5
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"%lli is %lli!\0A\00"
@.str.1 = [48 x i8] c"%lli is not a factorial product of any integer\0A\00"
define void @reverse_factorial(i64 %0) {
br label %2
2: ; preds = %27, %1
%3 = phi i64 [ 0, %1 ], [ %24, %27 ]
%4 = phi i64 [ 1, %1 ], [ %25, %27 ]
%5 = add nuw nsw i64 %3, 1
%6 = mul nsw i64 %5, %4
%7 = icmp eq i64 %6, %0
br i1 %7, label %8, label %11
8: ; preds = %23, %19, %15, %11, %2
%9 = phi i64 [ %5, %2 ], [ %12, %11 ], [ %16, %15 ], [ %20, %19 ], [ %24, %23 ]
%10 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 %0, i64 %9)
br label %31
11: ; preds = %2
%12 = add nuw nsw i64 %3, 2
%13 = mul nsw i64 %12, %6
%14 = icmp eq i64 %13, %0
br i1 %14, label %8, label %15
15: ; preds = %11
%16 = add nuw nsw i64 %3, 3
%17 = mul nsw i64 %16, %13
%18 = icmp eq i64 %17, %0
br i1 %18, label %8, label %19
19: ; preds = %15
%20 = add nuw nsw i64 %3, 4
%21 = mul nsw i64 %20, %17
%22 = icmp eq i64 %21, %0
br i1 %22, label %8, label %23
23: ; preds = %19
%24 = add nuw nsw i64 %3, 5
%25 = mul nsw i64 %24, %21
%26 = icmp eq i64 %25, %0
br i1 %26, label %8, label %27
27: ; preds = %23
%28 = icmp eq i64 %24, 100
br i1 %28, label %29, label %2
29: ; preds = %27
%30 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i64 %0)
br label %31
31: ; preds = %29, %8
ret void
}