#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*/ scanf(char *, int *);
int main() {
  int x;
  double fattoriale;
  int i;
  printf("Calcolatore fattoriale\n");
  printf("Inserisci x: ");
  scanf("%d", &x);
  for (fattoriale = 1, i = 1; i <= x; i++) {
    printf("i=%d x=%d fattoriale=%f\n", i, x, fattoriale);
    fattoriale *= i;
  }
  printf("Fattoriale di %d calcolato: %f", x, fattoriale);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedc(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movsd  0xe9d(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11b1 <main+0x91>
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%edx
movsd  -0x10(%rbp),%xmm0
lea    0xea4(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
cvtsi2sdl -0x14(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116f <main+0x4f>
mov    -0x8(%rbp),%esi
movsd  -0x10(%rbp),%xmm0
lea    0xe8a(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xf13(%rip),%rdi
call   1030 <puts@plt>
lea    0xebe(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebc(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%edx
movsd  0xe90(%rip),%xmm0
test   %edx,%edx
jle    11c0 <main+0x90>
lea    0xe9e(%rip),%r14
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x10(%rsp)
add    $0x1,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x10(%rsp),%xmm0
mov    0xc(%rsp),%edx
cmp    %edx,%ebx
jl     1180 <main+0x50>
lea    0xe6b(%rip),%rdi
mov    %edx,%esi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Calcolatore fattoriale\0A\00"
@.str.1 = [14 x i8] c"Inserisci x: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [25 x i8] c"i=%d x=%d fattoriale=%f\0A\00"
@.str.4 = [31 x i8] c"Fattoriale di %d calcolato: %f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 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 double 1.000000e+00, double* %3
store i32 1, i32* %4
br label %8
8: ; preds = %21, %0
%9 = load i32, i32* %4
%10 = load i32, i32* %2
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %24
12: ; preds = %8
%13 = load i32, i32* %4
%14 = load i32, i32* %2
%15 = load double, double* %3
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 %14, double %15)
%17 = load i32, i32* %4
%18 = sitofp i32 %17 to double
%19 = load double, double* %3
%20 = fmul double %19, %18
store double %20, double* %3
br label %21
21: ; preds = %12
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %8
24: ; preds = %8
%25 = load i32, i32* %2
%26 = load double, double* %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %25, double %26)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [14 x i8] c"Inserisci x: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [25 x i8] c"i=%d x=%d fattoriale=%f\0A\00"
@.str.4 = [31 x i8] c"Fattoriale di %d calcolato: %f\00"
@str = [23 x i8] c"Calcolatore fattoriale\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 1
br i1 %7, label %18, label %8
8: ; preds = %0, %8
%9 = phi i32 [ %16, %8 ], [ %6, %0 ]
%10 = phi i32 [ %15, %8 ], [ 1, %0 ]
%11 = phi double [ %14, %8 ], [ 1.000000e+00, %0 ]
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %10, i32 %9, double %11)
%13 = sitofp i32 %10 to double
%14 = fmul double %11, %13
%15 = add nuw nsw i32 %10, 1
%16 = load i32, i32* %1
%17 = icmp slt i32 %10, %16
br i1 %17, label %8, label %18
18: ; preds = %8, %0
%19 = phi double [ 1.000000e+00, %0 ], [ %14, %8 ]
%20 = phi i32 [ %6, %0 ], [ %16, %8 ]
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %20, double %19)
ret i32 0
}