#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*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  char result[35660];
  int i, j, number, dcounter, carry, tmp;
  printf("Factorial Simple Calculator\n\n");
  printf("Type a number (Example: 10000): ");
  scanf("%d", &number);
  result[0] = 1;
  dcounter = 1;
  carry = 0;
  puts("");
  for (i = 1; i <= number; i++) {
    for (j = 0; j < dcounter; j++) {
      tmp = result[j] * i + carry;
      result[j] = tmp % 10;
      carry = tmp / 10;
    }
    while (carry > 0) {
      result[dcounter] = carry % 10;
      carry /= 10;
      dcounter++;
    }
    printf("\r%d calculed digits...", dcounter);
  }
  puts("");
  printf("\nfactorial of %d is equal to:\n\n", number);
  for (i = dcounter - 1; i >= 0; i--) {
    printf("%d", result[i]);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8b70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeda(%rip),%rdi
lea    -0x8b5c(%rbp),%rsi
call   1050 <scanf@plt>
movb   $0x1,-0x8b50(%rbp)
movl   $0x1,-0x8b60(%rbp)
movl   $0x0,-0x8b64(%rbp)
lea    0xee5(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x8b54(%rbp)
mov    -0x8b54(%rbp),%eax
cmp    -0x8b5c(%rbp),%eax
jg     12b8 <main+0x188>
movl   $0x0,-0x8b58(%rbp)
mov    -0x8b58(%rbp),%eax
cmp    -0x8b60(%rbp),%eax
jge    1238 <main+0x108>
movslq -0x8b58(%rbp),%rax
movsbl -0x8b50(%rbp,%rax,1),%eax
ff
imul   -0x8b54(%rbp),%eax
add    -0x8b64(%rbp),%eax
mov    %eax,-0x8b68(%rbp)
mov    -0x8b68(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %dl,%cl
movslq -0x8b58(%rbp),%rax
mov    %cl,-0x8b50(%rbp,%rax,1)
mov    -0x8b68(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8b64(%rbp)
mov    -0x8b58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8b58(%rbp)
jmp    11be <main+0x8e>
jmp    123d <main+0x10d>
cmpl   $0x0,-0x8b64(%rbp)
jle    1290 <main+0x160>
mov    -0x8b64(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %dl,%cl
movslq -0x8b60(%rbp),%rax
mov    %cl,-0x8b50(%rbp,%rax,1)
mov    -0x8b64(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8b64(%rbp)
mov    -0x8b60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8b60(%rbp)
jmp    123d <main+0x10d>
mov    -0x8b60(%rbp),%esi
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8b54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8b54(%rbp)
jmp    11a2 <main+0x72>
lea    0xdb9(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8b5c(%rbp),%esi
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8b60(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x8b54(%rbp)
cmpl   $0x0,-0x8b54(%rbp)
jl     1325 <main+0x1f5>
movslq -0x8b54(%rbp),%rax
movsbl -0x8b50(%rbp,%rax,1),%esi
ff
lea    0xd35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8b54(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8b54(%rbp)
jmp    12e7 <main+0x1b7>
xor    %eax,%eax
add    $0x8b70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x8b60,%rsp
lea    0xf05(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb1(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
movb   $0x1,0x10(%rsp)
mov    $0xa,%edi
call   1030 <putchar@plt>
cmpl   $0x0,0xc(%rsp)
jle    125a <main+0x11a>
mov    $0x1,%r15d
mov    $0xcccccccd,%r12d
lea    0xe7d(%rip),%r14
xor    %eax,%eax
mov    $0x1,%ebp
jmp    11d2 <main+0x92>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x1(%r15),%ecx
mov    %ebx,%eax
cmp    0xc(%rsp),%r15d
mov    %ecx,%r15d
jge    125f <main+0x11f>
test   %ebp,%ebp
jle    1218 <main+0xd8>
mov    %ebp,%ecx
xor    %edx,%edx
nopw   0x0(%rax,%rax,1)
movsbl 0x10(%rsp,%rdx,1),%esi
imul   %r15d,%esi
add    %eax,%esi
movslq %esi,%rsi
imul   $0x66666667,%rsi,%rax
mov    %rax,%rdi
shr    $0x3f,%rdi
sar    $0x22,%rax
add    %edi,%eax
lea    (%rax,%rax,1),%edi
lea    (%rdi,%rdi,4),%edi
sub    %edi,%esi
mov    %sil,0x10(%rsp,%rdx,1)
add    $0x1,%rdx
cmp    %rdx,%rcx
jne    11e0 <main+0xa0>
test   %eax,%eax
jle    11b0 <main+0x70>
movslq %ebp,%rcx
add    %rsp,%rcx
add    $0x10,%rcx
cs nopw 0x0(%rax,%rax,1)
mov    %eax,%ebx
imul   %r12,%rbx
shr    $0x23,%rbx
lea    (%rbx,%rbx,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %eax,%esi
sub    %edx,%esi
mov    %sil,(%rcx)
add    $0x1,%rcx
add    $0x1,%ebp
cmp    $0x9,%eax
mov    %ebx,%eax
ja     1230 <main+0xf0>
jmp    11b2 <main+0x72>
mov    $0x1,%ebp
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%esi
lea    0xdc7(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebp,%ebp
jle    12ac <main+0x16c>
mov    %ebp,%ebp
add    $0x1,%rbp
lea    0xd95(%rip),%rbx
nopl   0x0(%rax)
lea    -0x2(%rbp),%eax
movsbl 0x10(%rsp,%rax,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xffffffffffffffff,%rbp
cmp    $0x1,%rbp
ja     1290 <main+0x150>
xor    %eax,%eax
add    $0x8b60,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Factorial Simple Calculator\0A\0A\00"
@.str.1 = [33 x i8] c"Type a number (Example: 10000): \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [23 x i8] c"\0D%d calculed digits...\00"
@.str.5 = [32 x i8] c"\0Afactorial of %d is equal to:\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [35660 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%12 = getelementptr inbounds [35660 x i8], [35660 x i8]* %2, i64 0, i64 0
store i8 1, i8* %12
store i32 1, i32* %6
store i32 0, i32* %7
%13 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %14
14: ; preds = %62, %0
%15 = load i32, i32* %3
%16 = load i32, i32* %5
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %65
18: ; preds = %14
store i32 0, i32* %4
br label %19
19: ; preds = %41, %18
%20 = load i32, i32* %4
%21 = load i32, i32* %6
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %44
23: ; preds = %19
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [35660 x i8], [35660 x i8]* %2, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = load i32, i32* %3
%30 = mul nsw i32 %28, %29
%31 = load i32, i32* %7
%32 = add nsw i32 %30, %31
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = srem i32 %33, 10
%35 = trunc i32 %34 to i8
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [35660 x i8], [35660 x i8]* %2, i64 0, i64 %37
store i8 %35, i8* %38
%39 = load i32, i32* %8
%40 = sdiv i32 %39, 10
store i32 %40, i32* %7
br label %41
41: ; preds = %23
%42 = load i32, i32* %4
%43 = add nsw i32 %42, 1
store i32 %43, i32* %4
br label %19
44: ; preds = %19
br label %45
45: ; preds = %48, %44
%46 = load i32, i32* %7
%47 = icmp sgt i32 %46, 0
br i1 %47, label %48, label %59
48: ; preds = %45
%49 = load i32, i32* %7
%50 = srem i32 %49, 10
%51 = trunc i32 %50 to i8
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [35660 x i8], [35660 x i8]* %2, i64 0, i64 %53
store i8 %51, i8* %54
%55 = load i32, i32* %7
%56 = sdiv i32 %55, 10
store i32 %56, i32* %7
%57 = load i32, i32* %6
%58 = add nsw i32 %57, 1
store i32 %58, i32* %6
br label %45
59: ; preds = %45
%60 = load i32, i32* %6
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %60)
br label %62
62: ; preds = %59
%63 = load i32, i32* %3
%64 = add nsw i32 %63, 1
store i32 %64, i32* %3
br label %14
65: ; preds = %14
%66 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%67 = load i32, i32* %5
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %67)
%69 = load i32, i32* %6
%70 = sub nsw i32 %69, 1
store i32 %70, i32* %3
br label %71
71: ; preds = %81, %65
%72 = load i32, i32* %3
%73 = icmp sge i32 %72, 0
br i1 %73, label %74, label %84
74: ; preds = %71
%75 = load i32, i32* %3
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [35660 x i8], [35660 x i8]* %2, i64 0, i64 %76
%78 = load i8, i8* %77
%79 = sext i8 %78 to i32
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %79)
br label %81
81: ; preds = %74
%82 = load i32, i32* %3
%83 = add nsw i32 %82, -1
store i32 %83, i32* %3
br label %71
84: ; preds = %71
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [33 x i8] c"Type a number (Example: 10000): \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.4 = [23 x i8] c"\0D%d calculed digits...\00"
@.str.5 = [32 x i8] c"\0Afactorial of %d is equal to:\0A\0A\00"
@str = [29 x i8] c"Factorial Simple Calculator\0A\00"
define i32 @main() {
%1 = alloca [35660 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [35660 x i8], [35660 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
store i8 1, i8* %3
%8 = call i32 @putchar(i32 10)
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 1
br i1 %10, label %54, label %11
11: ; preds = %0, %47
%12 = phi i32 [ %51, %47 ], [ 1, %0 ]
%13 = phi i32 [ %49, %47 ], [ 0, %0 ]
%14 = phi i32 [ %48, %47 ], [ 1, %0 ]
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = zext i32 %14 to i64
br label %23
18: ; preds = %23, %11
%19 = phi i32 [ %13, %11 ], [ %33, %23 ]
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %47
21: ; preds = %18
%22 = sext i32 %14 to i64
br label %36
23: ; preds = %16, %23
%24 = phi i64 [ 0, %16 ], [ %34, %23 ]
%25 = phi i32 [ %13, %16 ], [ %33, %23 ]
%26 = getelementptr inbounds [35660 x i8], [35660 x i8]* %1, i64 0, i64 %24
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = mul nsw i32 %12, %28
%30 = add nsw i32 %29, %25
%31 = srem i32 %30, 10
%32 = trunc i32 %31 to i8
store i8 %32, i8* %26
%33 = sdiv i32 %30, 10
%34 = add nuw nsw i64 %24, 1
%35 = icmp eq i64 %34, %17
br i1 %35, label %18, label %23
36: ; preds = %21, %36
%37 = phi i64 [ %22, %21 ], [ %43, %36 ]
%38 = phi i32 [ %19, %21 ], [ %42, %36 ]
%39 = urem i32 %38, 10
%40 = trunc i32 %39 to i8
%41 = getelementptr inbounds [35660 x i8], [35660 x i8]* %1, i64 0, i64 %37
store i8 %40, i8* %41
%42 = udiv i32 %38, 10
%43 = add i64 %37, 1
%44 = icmp ult i32 %38, 10
br i1 %44, label %45, label %36
45: ; preds = %36
%46 = trunc i64 %43 to i32
br label %47
47: ; preds = %45, %18
%48 = phi i32 [ %14, %18 ], [ %46, %45 ]
%49 = phi i32 [ %19, %18 ], [ %42, %45 ]
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %48)
%51 = add nuw nsw i32 %12, 1
%52 = load i32, i32* %2
%53 = icmp slt i32 %12, %52
br i1 %53, label %11, label %54
54: ; preds = %47, %0
%55 = phi i32 [ 1, %0 ], [ %48, %47 ]
%56 = call i32 @putchar(i32 10)
%57 = load i32, i32* %2
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %57)
%59 = icmp sgt i32 %55, 0
br i1 %59, label %60, label %71
60: ; preds = %54
%61 = zext i32 %55 to i64
br label %62
62: ; preds = %60, %62
%63 = phi i64 [ %61, %60 ], [ %64, %62 ]
%64 = add nsw i64 %63, -1
%65 = and i64 %64, 4294967295
%66 = getelementptr inbounds [35660 x i8], [35660 x i8]* %1, i64 0, i64 %65
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %68)
%70 = icmp ugt i64 %63, 1
br i1 %70, label %62, label %71
71: ; preds = %62, %54
ret i32 0
}