#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 */
unsigned int _diy_safe_mul_size_t(size_t, size_t, size_t *);
size_t _factorial_size_t_loop(size_t n) {
  size_t result, last_result;
  unsigned overflow;
  result = n;
  do {
    last_result = result;
    overflow = _diy_safe_mul_size_t(last_result, --n, &result);
  } while ((!overflow) && (n > 1));
  return overflow ? 0 : result;
}


x86 assembly (clang, -O0):
<_factorial_size_t_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
mov    %rsi,-0x8(%rbp)
lea    -0x10(%rbp),%rdx
call   1030 <_diy_safe_mul_size_t@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
jne    1162 <_factorial_size_t_loop+0x52>
cmpq   $0x1,-0x8(%rbp)
seta   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1124 <_factorial_size_t_loop+0x14>
cmpl   $0x0,-0x1c(%rbp)
je     1182 <_factorial_size_t_loop+0x72>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    118a <_factorial_size_t_loop+0x7a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_factorial_size_t_loop>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rdi,(%rsp)
lea    -0x1(%rdi),%r14
mov    %rsp,%rdx
mov    %r14,%rsi
call   1030 <_diy_safe_mul_size_t@plt>
test   %eax,%eax
sete   %cl
cmp    $0x2,%r14
jb     1162 <_factorial_size_t_loop+0x52>
test   %eax,%eax
jne    1162 <_factorial_size_t_loop+0x52>
add    $0xfffffffffffffffe,%rbx
mov    %rsp,%r14
mov    (%rsp),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <_diy_safe_mul_size_t@plt>
test   %eax,%eax
sete   %cl
cmp    $0x2,%rbx
jb     1162 <_factorial_size_t_loop+0x52>
add    $0xffffffffffffffff,%rbx
test   %eax,%eax
je     1140 <_factorial_size_t_loop+0x30>
test   %cl,%cl
je     116c <_factorial_size_t_loop+0x5c>
mov    (%rsp),%rax
jmp    116e <_factorial_size_t_loop+0x5e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @_factorial_size_t_loop(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
store i64 %0, i64* %2
%6 = load i64, i64* %2
store i64 %6, i64* %3
br label %7
7: ; preds = %19, %1
%8 = load i64, i64* %3
store i64 %8, i64* %4
%9 = load i64, i64* %4
%10 = load i64, i64* %2
%11 = add i64 %10, -1
store i64 %11, i64* %2
%12 = call i32 @_diy_safe_mul_size_t(i64 %9, i64 %11, i64* %3)
store i32 %12, i32* %5
br label %13
13: ; preds = %7
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = load i64, i64* %2
%18 = icmp ugt i64 %17, 1
br label %19
19: ; preds = %16, %13
%20 = phi i1 [ false, %13 ], [ %18, %16 ]
br i1 %20, label %7, label %21
21: ; preds = %19
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %21
br label %27
25: ; preds = %21
%26 = load i64, i64* %3
br label %27
27: ; preds = %25, %24
%28 = phi i64 [ 0, %24 ], [ %26, %25 ]
ret i64 %28
}

LLVM IR (-O2):
define i64 @_factorial_size_t_loop(i64 %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
store i64 %0, i64* %2
%4 = add i64 %0, -1
%5 = call i32 @_diy_safe_mul_size_t(i64 %0, i64 %4, i64* %2)
%6 = icmp eq i32 %5, 0
%7 = icmp ugt i64 %4, 1
%8 = and i1 %7, %6
br i1 %8, label %9, label %17
9: ; preds = %1, %9
%10 = phi i64 [ %12, %9 ], [ %4, %1 ]
%11 = load i64, i64* %2
%12 = add i64 %10, -1
%13 = call i32 @_diy_safe_mul_size_t(i64 %11, i64 %12, i64* %2)
%14 = icmp eq i32 %13, 0
%15 = icmp ugt i64 %12, 1
%16 = and i1 %15, %14
br i1 %16, label %9, label %17
17: ; preds = %9, %1
%18 = phi i1 [ %6, %1 ], [ %14, %9 ]
%19 = load i64, i64* %2
%20 = select i1 %18, i64 %19, i64 0
ret i64 %20
}