#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 */
typedef int /*<<< orphan*/ mpz_t;
typedef int /*<<< orphan*/ clock_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ clock();
char *comify(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int findDigits(unsigned int);
int /*<<< orphan*/ *fopen(char *, char *);
int gmp_fprintf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
scalar_t__ isdigit(char);
int /*<<< orphan*/ mpz_add_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_init2(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_mul_ui(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ progress(int /*<<< orphan*/, int);
int /*<<< orphan*/ progress_format(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  char *number = "12345";
  if (argc > 1) {
    if (isdigit(argv[1][0]))
      number = argv[1];
    else {
      printf("%s computes the factorial of a number and writes the result to a "
             "file. "
             "\n"
             "The name of the file is made by tacking !.txt onto the number. "
             "\n"
             "For example, the factorial of 123 is written to 123!.txt"
             "\n",
             argv[0]);
      exit(-1);
    }
  }
  progress_format(number);
  unsigned int dog0 = atoi(number);
  int digits = findDigits(dog0);
  printf("Estimated number of digits in %s! ", comify(dog0));
  printf("is %s"
         "\n",
         comify(digits));
  mpz_t dog2;
  mpz_init2(dog2, digits);
  mpz_add_ui(dog2, dog2, 1);
  clock_t start = clock();
  while (dog0) {
    mpz_mul_ui(dog2, dog2, dog0--);
    progress(start, 0);
  }
  progress(start, 1);
  char buffer[100];
  strcpy(buffer, number);
  strcat(buffer, "!.txt");
  FILE *outfile = fopen(buffer, "w");
  int count = gmp_fprintf(outfile, "%Zd", dog2);
  fclose(outfile);
  printf("%s! has been written to file %s"
         "\n",
         comify(atoi(number)), buffer);
  printf("%s! has ", comify(atoi(number)));
  printf("%s digits."
         "\n",
         comify(count));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xdd0(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    128d <main+0x7d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     1269 <main+0x59>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1288 <main+0x78>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
jmp    128d <main+0x7d>
mov    -0x18(%rbp),%rdi
call   10a0 <progress_format@plt>
mov    -0x18(%rbp),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   10b0 <findDigits@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   10d0 <comify@plt>
mov    %rax,%rsi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x20(%rbp),%edi
call   10d0 <comify@plt>
mov    %rax,%rsi
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%esi
call   10e0 <mpz_init2@plt>
mov    -0x24(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    $0x1,%edx
call   1080 <mpz_add_ui@plt>
mov    $0x0,%al
call   1060 <clock@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1333 <main+0x123>
mov    -0x24(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    %edx,%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
call   1120 <mpz_mul_ui@plt>
mov    -0x28(%rbp),%edi
xor    %esi,%esi
call   1030 <progress@plt>
jmp    1304 <main+0xf4>
mov    -0x28(%rbp),%edi
mov    $0x1,%esi
call   1030 <progress@plt>
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcpy@plt>
lea    -0x90(%rbp),%rdi
lea    0xd94(%rip),%rsi
call   1100 <strcat@plt>
lea    -0x90(%rbp),%rdi
lea    0xd87(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xd6c(%rip),%rsi
call   1130 <gmp_fprintf@plt>
mov    %eax,-0x9c(%rbp)
mov    -0x98(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   10f0 <atoi@plt>
mov    %eax,%edi
call   10d0 <comify@plt>
mov    %rax,%rsi
lea    -0x90(%rbp),%rdx
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x18(%rbp),%rdi
call   10f0 <atoi@plt>
mov    %eax,%edi
call   10d0 <comify@plt>
mov    %rax,%rsi
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x9c(%rbp),%edi
call   10d0 <comify@plt>
mov    %rax,%rsi
lea    0xd25(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
cmp    $0x2,%edi
jl     123d <main+0x2d>
mov    %rsi,%rbx
mov    0x8(%rsi),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     1383 <main+0x173>
mov    0x8(%rbx),%r15
jmp    1244 <main+0x34>
lea    0xdbc(%rip),%r15
mov    %r15,%rdi
call   10a0 <progress_format@plt>
mov    %r15,%rdi
call   10f0 <atoi@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   10b0 <findDigits@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   10d0 <comify@plt>
lea    0xe5b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %ebx,%edi
call   10d0 <comify@plt>
lea    0xe66(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %ebx,%esi
call   10e0 <mpz_init2@plt>
mov    $0x1,%edx
call   1080 <mpz_add_ui@plt>
xor    %eax,%eax
call   1060 <clock@plt>
mov    %eax,%ebx
test   %ebp,%ebp
je     12c5 <main+0xb5>
nopl   (%rax)
mov    %ebp,%edx
call   1120 <mpz_mul_ui@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <progress@plt>
add    $0xffffffff,%ebp
jne    12b0 <main+0xa0>
mov    %ebx,%edi
mov    $0x1,%esi
call   1030 <progress@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <strcpy@plt>
lea    0xe0c(%rip),%rsi
mov    %rbp,%rdi
call   1100 <strcat@plt>
lea    0xe03(%rip),%rsi
mov    %rbp,%rdi
call   10c0 <fopen@plt>
mov    %rax,%rbx
lea    0xdf3(%rip),%rsi
mov    %rax,%rdi
call   1130 <gmp_fprintf@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    %r15,%rdi
call   10f0 <atoi@plt>
mov    %eax,%edi
call   10d0 <comify@plt>
lea    0xdce(%rip),%rdi
mov    %rax,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r15,%rdi
call   10f0 <atoi@plt>
mov    %eax,%edi
call   10d0 <comify@plt>
lea    0xdcc(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r14d,%edi
call   10d0 <comify@plt>
lea    0xdbc(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xc79(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"12345\00"
@.str.1 = [194 x i8] c"%s computes the factorial of a number and writes the result to a file. \0AThe name of the file is made by tacking !.txt onto the number. \0AFor example, the factorial of 123 is written to 123!.txt\0A\00"
@.str.2 = [35 x i8] c"Estimated number of digits in %s! \00"
@.str.3 = [7 x i8] c"is %s\0A\00"
@.str.4 = [6 x i8] c"!.txt\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [4 x i8] c"%Zd\00"
@.str.7 = [33 x i8] c"%s! has been written to file %s\0A\00"
@.str.8 = [9 x i8] c"%s! has \00"
@.str.9 = [12 x i8] c"%s digits.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [100 x i8]
%12 = alloca i32*
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %6
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %35
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = call i64 @isdigit(i8 signext %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %16
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
store i8* %27, i8** %6
br label %34
28: ; preds = %16
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([194 x i8], [194 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %24
br label %35
35: ; preds = %34, %2
%36 = load i8*, i8** %6
%37 = call i32 @progress_format(i8* %36)
%38 = load i8*, i8** %6
%39 = call i32 @atoi(i8* %38)
store i32 %39, i32* %7
%40 = load i32, i32* %7
%41 = call i32 @findDigits(i32 %40)
store i32 %41, i32* %8
%42 = load i32, i32* %7
%43 = call i8* @comify(i32 %42)
%44 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %43)
%45 = load i32, i32* %8
%46 = call i8* @comify(i32 %45)
%47 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = load i32, i32* %9
%49 = load i32, i32* %8
%50 = call i32 @mpz_init2(i32 %48, i32 %49)
%51 = load i32, i32* %9
%52 = load i32, i32* %9
%53 = call i32 @mpz_add_ui(i32 %51, i32 %52, i32 1)
%54 = call i32 (...) @clock()
store i32 %54, i32* %10
br label %55
55: ; preds = %58, %35
%56 = load i32, i32* %7
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %66
58: ; preds = %55
%59 = load i32, i32* %9
%60 = load i32, i32* %9
%61 = load i32, i32* %7
%62 = add i32 %61, -1
store i32 %62, i32* %7
%63 = call i32 @mpz_mul_ui(i32 %59, i32 %60, i32 %61)
%64 = load i32, i32* %10
%65 = call i32 @progress(i32 %64, i32 0)
br label %55
66: ; preds = %55
%67 = load i32, i32* %10
%68 = call i32 @progress(i32 %67, i32 1)
%69 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%70 = load i8*, i8** %6
%71 = call i32 @strcpy(i8* %69, i8* %70)
%72 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%73 = call i32 @strcat(i8* %72, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%74 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%75 = call i32* @fopen(i8* %74, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %75, i32** %12
%76 = load i32*, i32** %12
%77 = load i32, i32* %9
%78 = call i32 @gmp_fprintf(i32* %76, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %77)
store i32 %78, i32* %13
%79 = load i32*, i32** %12
%80 = call i32 @fclose(i32* %79)
%81 = load i8*, i8** %6
%82 = call i32 @atoi(i8* %81)
%83 = call i8* @comify(i32 %82)
%84 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%85 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i8* %83, i8* %84)
%86 = load i8*, i8** %6
%87 = call i32 @atoi(i8* %86)
%88 = call i8* @comify(i32 %87)
%89 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %88)
%90 = load i32, i32* %13
%91 = call i8* @comify(i32 %90)
%92 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i8* %91)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"12345\00"
@.str.1 = [194 x i8] c"%s computes the factorial of a number and writes the result to a file. \0AThe name of the file is made by tacking !.txt onto the number. \0AFor example, the factorial of 123 is written to 123!.txt\0A\00"
@.str.2 = [35 x i8] c"Estimated number of digits in %s! \00"
@.str.3 = [7 x i8] c"is %s\0A\00"
@.str.4 = [6 x i8] c"!.txt\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [4 x i8] c"%Zd\00"
@.str.7 = [33 x i8] c"%s! has been written to file %s\0A\00"
@.str.8 = [9 x i8] c"%s! has \00"
@.str.9 = [12 x i8] c"%s digits.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %17
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = load i8, i8* %7
%9 = tail call i64 @isdigit(i8 signext %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %5
%12 = load i8*, i8** %6
br label %17
13: ; preds = %5
%14 = load i8*, i8** %1
%15 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([194 x i8], [194 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = tail call i32 @exit(i32 -1)
unreachable
17: ; preds = %11, %2
%18 = phi i8* [ %12, %11 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %2 ]
%19 = tail call i32 @progress_format(i8* %18)
%20 = tail call i32 @atoi(i8* %18)
%21 = tail call i32 @findDigits(i32 %20)
%22 = tail call i8* @comify(i32 %20)
%23 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = tail call i8* @comify(i32 %21)
%25 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = tail call i32 @mpz_init2(i32 undef, i32 %21)
%27 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 1)
%28 = tail call i32 (...) @clock()
%29 = icmp eq i32 %20, 0
br i1 %29, label %36, label %30
30: ; preds = %17, %30
%31 = phi i32 [ %32, %30 ], [ %20, %17 ]
%32 = add i32 %31, -1
%33 = tail call i32 @mpz_mul_ui(i32 undef, i32 undef, i32 %31)
%34 = tail call i32 @progress(i32 %28, i32 0)
%35 = icmp eq i32 %32, 0
br i1 %35, label %36, label %30
36: ; preds = %30, %17
%37 = tail call i32 @progress(i32 %28, i32 1)
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%39 = call i32 @strcpy(i8* %38, i8* %18)
%40 = call i32 @strcat(i8* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%42 = call i32 @gmp_fprintf(i32* %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 undef)
%43 = call i32 @fclose(i32* %41)
%44 = call i32 @atoi(i8* %18)
%45 = call i8* @comify(i32 %44)
%46 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i8* %45, i8* %38)
%47 = call i32 @atoi(i8* %18)
%48 = call i8* @comify(i32 %47)
%49 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %48)
%50 = call i8* @comify(i32 %42)
%51 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i8* %50)
ret i32 0
}