#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*/ tmul_ok_64(long long, int);
int largest_factorial_64(void) {
  long long int result = 1;
  int n = 1, overflow;
  for (;;) {
    n++;
    overflow = !tmul_ok_64(result, n);
    if (overflow)
      break;
    result *= n;
  }
  return n - 1;
}


x86 assembly (clang, -O0):
<largest_factorial_64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x1,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <tmul_ok_64@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     115b <largest_factorial_64+0x4b>
jmp    116d <largest_factorial_64+0x5d>
movslq -0xc(%rbp),%rax
imul   -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1127 <largest_factorial_64+0x17>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<largest_factorial_64>:
push   %r15
push   %r14
push   %rbx
mov    $0x1,%r14d
mov    $0x1,%edi
mov    $0x2,%esi
call   1030 <tmul_ok_64@plt>
test   %eax,%eax
je     115e <largest_factorial_64+0x4e>
mov    $0x2,%ebx
mov    $0x1,%r15d
nopl   0x0(%rax)
imul   %rbx,%r14
add    $0x1,%rbx
lea    0x2(%r15),%esi
mov    %r14,%rdi
call   1030 <tmul_ok_64@plt>
add    $0x1,%r15d
test   %eax,%eax
jne    1140 <largest_factorial_64+0x30>
jmp    1164 <largest_factorial_64+0x54>
mov    $0x1,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @largest_factorial_64() {
%1 = alloca i64
%2 = alloca i32
%3 = alloca i32
store i64 1, i64* %1
store i32 1, i32* %2
br label %4
4: ; preds = %16, %0
%5 = load i32, i32* %2
%6 = add nsw i32 %5, 1
store i32 %6, i32* %2
%7 = load i64, i64* %1
%8 = load i32, i32* %2
%9 = call i32 @tmul_ok_64(i64 %7, i32 %8)
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
%12 = zext i1 %11 to i32
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %4
br label %21
16: ; preds = %4
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = load i64, i64* %1
%20 = mul nsw i64 %19, %18
store i64 %20, i64* %1
br label %4
21: ; preds = %15
%22 = load i32, i32* %2
%23 = sub nsw i32 %22, 1
ret i32 %23
}

LLVM IR (-O2):
define i32 @largest_factorial_64() {
%1 = tail call i32 @tmul_ok_64(i64 1, i32 2)
%2 = icmp eq i32 %1, 0
br i1 %2, label %13, label %3
3: ; preds = %0, %3
%4 = phi i64 [ %7, %3 ], [ 2, %0 ]
%5 = phi i64 [ %6, %3 ], [ 1, %0 ]
%6 = mul nuw nsw i64 %5, %4
%7 = add nuw i64 %4, 1
%8 = trunc i64 %7 to i32
%9 = tail call i32 @tmul_ok_64(i64 %6, i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %3
11: ; preds = %3
%12 = trunc i64 %4 to i32
br label %13
13: ; preds = %11, %0
%14 = phi i32 [ 1, %0 ], [ %12, %11 ]
ret i32 %14
}