#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 long long faktnerek(long long);
unsigned long long faktrek(long long);
unsigned long long faktrektisk(long long);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, long long *, int *);
int /*<<< orphan*/ timer_start();
int /*<<< orphan*/ timer_stop(char *);
int main() {
  long long num;
  int option;
  if (scanf("%lld,%d", &num, &option) != 2 || (option != 0 && option != 1)) {
    printf("chybne zadani\n");
    return 1;
  }
  if (num < 0) {
    printf("chybne zadani\n");
    return 2;
  }
  timer_start();
  unsigned long long i, result = 1;
  for (i = num; i > 1; i--)
    result *= i;
  printf("%llu\n", result);
  timer_stop("smycka trvala");
  timer_start();
  printf("%llu\n", faktnerek(num));
  timer_stop("nerekurzivni funkce trvala");
  timer_start();
  printf("%llu\n", faktrek(num));
  timer_stop("rekurzivni funkce trvala");
  if (option) {
    timer_start();
    printf("%llu\n", faktrektisk(num));
    timer_stop("tisk s rekurzi trval");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1070 <scanf@plt>
cmp    $0x2,%eax
jne    11b0 <main+0x40>
cmpl   $0x0,-0x14(%rbp)
je     11ca <main+0x5a>
cmpl   $0x1,-0x14(%rbp)
je     11ca <main+0x5a>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e5 <main+0x175>
cmpq   $0x0,-0x10(%rbp)
jge    11ef <main+0x7f>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12e5 <main+0x175>
mov    $0x0,%al
call   1090 <timer_start@plt>
movq   $0x1,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x1,-0x20(%rbp)
jbe    122f <main+0xbf>
mov    -0x20(%rbp),%rax
imul   -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1206 <main+0x96>
mov    -0x28(%rbp),%rsi
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdd5(%rip),%rdi
call   1080 <timer_stop@plt>
mov    $0x0,%al
call   1090 <timer_start@plt>
mov    -0x10(%rbp),%rdi
call   1060 <faktnerek@plt>
mov    %rax,%rsi
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdb6(%rip),%rdi
call   1080 <timer_stop@plt>
mov    $0x0,%al
call   1090 <timer_start@plt>
mov    -0x10(%rbp),%rdi
call   1030 <faktrek@plt>
mov    %rax,%rsi
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd8b(%rip),%rdi
call   1080 <timer_stop@plt>
cmpl   $0x0,-0x14(%rbp)
je     12de <main+0x16e>
mov    $0x0,%al
call   1090 <timer_start@plt>
mov    -0x10(%rbp),%rdi
call   1050 <faktrektisk@plt>
mov    %rax,%rsi
lea    0xd4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd6d(%rip),%rdi
call   1080 <timer_stop@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xe6f(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0x14(%rsp),%rdx
call   1080 <scanf@plt>
cmp    $0x2,%eax
jne    11f9 <main+0x79>
cmpl   $0x2,0x14(%rsp)
jae    11f9 <main+0x79>
cmpq   $0x0,0x8(%rsp)
js     1210 <main+0x90>
xor    %r15d,%r15d
xor    %eax,%eax
call   10a0 <timer_start@plt>
mov    0x8(%rsp),%rax
mov    $0x1,%esi
cmp    $0x2,%rax
jb     12be <main+0x13e>
lea    -0x1(%rax),%r8
lea    -0x2(%rax),%rsi
mov    %r8d,%ecx
and    $0x7,%ecx
cmp    $0x7,%rsi
jae    1227 <main+0xa7>
mov    $0x1,%esi
test   %rcx,%rcx
jne    12b0 <main+0x130>
jmp    12be <main+0x13e>
lea    0xe4c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r15d
jmp    1367 <main+0x1e7>
lea    0xe35(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%r15d
jmp    1367 <main+0x1e7>
and    $0xfffffffffffffff8,%r8
neg    %r8
mov    $0x1,%esi
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%rax,%rdi,1),%rbx
imul   %rsi,%rbx
lea    (%rax,%rdi,1),%rsi
add    $0xffffffffffffffff,%rsi
lea    (%rax,%rdi,1),%rbp
add    $0xfffffffffffffffe,%rbp
imul   %rsi,%rbp
imul   %rbx,%rbp
lea    (%rax,%rdi,1),%rsi
add    $0xfffffffffffffffd,%rsi
lea    (%rax,%rdi,1),%rbx
add    $0xfffffffffffffffc,%rbx
imul   %rsi,%rbx
lea    (%rax,%rdi,1),%rdx
add    $0xfffffffffffffffb,%rdx
imul   %rbx,%rdx
imul   %rbp,%rdx
lea    (%rax,%rdi,1),%rbp
add    $0xfffffffffffffffa,%rbp
lea    (%rax,%rdi,1),%rsi
add    $0xfffffffffffffff9,%rsi
imul   %rbp,%rsi
imul   %rdx,%rsi
add    $0xfffffffffffffff8,%rdi
cmp    %rdi,%r8
jne    1240 <main+0xc0>
add    %rdi,%rax
test   %rcx,%rcx
je     12be <main+0x13e>
nopl   (%rax)
imul   %rax,%rsi
add    $0xffffffffffffffff,%rax
add    $0xffffffffffffffff,%rcx
jne    12b0 <main+0x130>
lea    0xd43(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd38(%rip),%rdi
call   1090 <timer_stop@plt>
xor    %eax,%eax
call   10a0 <timer_start@plt>
mov    0x8(%rsp),%rdi
call   1070 <faktnerek@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd1c(%rip),%rdi
call   1090 <timer_stop@plt>
xor    %eax,%eax
call   10a0 <timer_start@plt>
mov    0x8(%rsp),%rdi
call   1040 <faktrek@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xcf4(%rip),%rdi
call   1090 <timer_stop@plt>
cmpl   $0x0,0x14(%rsp)
je     1367 <main+0x1e7>
xor    %r15d,%r15d
xor    %eax,%eax
call   10a0 <timer_start@plt>
mov    0x8(%rsp),%rdi
call   1060 <faktrektisk@plt>
lea    0xcb7(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xcd5(%rip),%rdi
call   1090 <timer_stop@plt>
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%lld,%d\00"
@.str.1 = [15 x i8] c"chybne zadani\0A\00"
@.str.2 = [6 x i8] c"%llu\0A\00"
@.str.3 = [14 x i8] c"smycka trvala\00"
@.str.4 = [27 x i8] c"nerekurzivni funkce trvala\00"
@.str.5 = [25 x i8] c"rekurzivni funkce trvala\00"
@.str.6 = [21 x i8] c"tisk s rekurzi trval\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
store i32 0, i32* %1
%6 = call i32 @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64* %2, i32* %3)
%7 = icmp ne i32 %6, 2
br i1 %7, label %14, label %8
8: ; preds = %0
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %11, %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %57
16: ; preds = %11, %8
%17 = load i64, i64* %2
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %1
br label %57
21: ; preds = %16
%22 = call i32 (...) @timer_start()
store i64 1, i64* %5
%23 = load i64, i64* %2
store i64 %23, i64* %4
br label %24
24: ; preds = %31, %21
%25 = load i64, i64* %4
%26 = icmp ugt i64 %25, 1
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = load i64, i64* %4
%29 = load i64, i64* %5
%30 = mul i64 %29, %28
store i64 %30, i64* %5
br label %31
31: ; preds = %27
%32 = load i64, i64* %4
%33 = add i64 %32, -1
store i64 %33, i64* %4
br label %24
34: ; preds = %24
%35 = load i64, i64* %5
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %35)
%37 = call i32 @timer_stop(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 (...) @timer_start()
%39 = load i64, i64* %2
%40 = call i64 @faktnerek(i64 %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %40)
%42 = call i32 @timer_stop(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%43 = call i32 (...) @timer_start()
%44 = load i64, i64* %2
%45 = call i64 @faktrek(i64 %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %45)
%47 = call i32 @timer_stop(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%48 = load i32, i32* %3
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %34
%51 = call i32 (...) @timer_start()
%52 = load i64, i64* %2
%53 = call i64 @faktrektisk(i64 %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %53)
%55 = call i32 @timer_stop(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %56
56: ; preds = %50, %34
store i32 0, i32* %1
br label %57
57: ; preds = %56, %19, %14
%58 = load i32, i32* %1
ret i32 %58
}

LLVM IR (-O2):
@.str = [8 x i8] c"%lld,%d\00"
@.str.2 = [6 x i8] c"%llu\0A\00"
@.str.3 = [14 x i8] c"smycka trvala\00"
@.str.4 = [27 x i8] c"nerekurzivni funkce trvala\00"
@.str.5 = [25 x i8] c"rekurzivni funkce trvala\00"
@.str.6 = [21 x i8] c"tisk s rekurzi trval\00"
@str.7 = [14 x i8] c"chybne zadani\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i32
%3 = bitcast i64* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64* %1, i32* %2)
%6 = icmp eq i32 %5, 2
%7 = load i32, i32* %2
%8 = icmp ult i32 %7, 2
%9 = select i1 %6, i1 %8, i1 false
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.7, i64 0, i64 0))
br label %85
12: ; preds = %0
%13 = load i64, i64* %1
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.7, i64 0, i64 0))
br label %85
17: ; preds = %12
%18 = call i32 (...) @timer_start()
%19 = load i64, i64* %1
%20 = icmp ugt i64 %19, 1
br i1 %20, label %21, label %63
21: ; preds = %17
%22 = add i64 %19, -1
%23 = add i64 %19, -2
%24 = and i64 %22, 7
%25 = icmp ult i64 %23, 7
br i1 %25, label %50, label %26
26: ; preds = %21
%27 = and i64 %22, -8
br label %28
28: ; preds = %28, %26
%29 = phi i64 [ 1, %26 ], [ %46, %28 ]
%30 = phi i64 [ %19, %26 ], [ %47, %28 ]
%31 = phi i64 [ 0, %26 ], [ %48, %28 ]
%32 = mul i64 %29, %30
%33 = add i64 %30, -1
%34 = mul i64 %32, %33
%35 = add i64 %30, -2
%36 = mul i64 %34, %35
%37 = add i64 %30, -3
%38 = mul i64 %36, %37
%39 = add i64 %30, -4
%40 = mul i64 %38, %39
%41 = add i64 %30, -5
%42 = mul i64 %40, %41
%43 = add i64 %30, -6
%44 = mul i64 %42, %43
%45 = add i64 %30, -7
%46 = mul i64 %44, %45
%47 = add i64 %30, -8
%48 = add i64 %31, 8
%49 = icmp eq i64 %48, %27
br i1 %49, label %50, label %28
50: ; preds = %28, %21
%51 = phi i64 [ undef, %21 ], [ %46, %28 ]
%52 = phi i64 [ 1, %21 ], [ %46, %28 ]
%53 = phi i64 [ %19, %21 ], [ %47, %28 ]
%54 = icmp eq i64 %24, 0
br i1 %54, label %63, label %55
55: ; preds = %50, %55
%56 = phi i64 [ %59, %55 ], [ %52, %50 ]
%57 = phi i64 [ %60, %55 ], [ %53, %50 ]
%58 = phi i64 [ %61, %55 ], [ 0, %50 ]
%59 = mul i64 %56, %57
%60 = add i64 %57, -1
%61 = add i64 %58, 1
%62 = icmp eq i64 %61, %24
br i1 %62, label %63, label %55
63: ; preds = %50, %55, %17
%64 = phi i64 [ 1, %17 ], [ %51, %50 ], [ %59, %55 ]
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %64)
%66 = call i32 @timer_stop(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%67 = call i32 (...) @timer_start()
%68 = load i64, i64* %1
%69 = call i64 @faktnerek(i64 %68)
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %69)
%71 = call i32 @timer_stop(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%72 = call i32 (...) @timer_start()
%73 = load i64, i64* %1
%74 = call i64 @faktrek(i64 %73)
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %74)
%76 = call i32 @timer_stop(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%77 = load i32, i32* %2
%78 = icmp eq i32 %77, 0
br i1 %78, label %85, label %79
79: ; preds = %63
%80 = call i32 (...) @timer_start()
%81 = load i64, i64* %1
%82 = call i64 @faktrektisk(i64 %81)
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %82)
%84 = call i32 @timer_stop(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %85
85: ; preds = %63, %79, %15, %10
%86 = phi i32 [ 1, %10 ], [ 2, %15 ], [ 0, %79 ], [ 0, %63 ]
ret i32 %86
}