#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 *, char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int number;
  int counter = 0;
  int factorial = 1;
  printf("%s", "Enter number(-1 to exit): ");
  scanf("%d", &number);
  while (number >= 0) {
    if (number == 0) {
      factorial = 1;
    } else if (number > 0) {
      while (counter < number) {
        factorial = factorial * (number - counter);
        printf("%s%d\n", "number: ", number);
        printf("%s%d\n", "counter: ", counter);
        printf("%s%d\n", "factorial: ", factorial);
        puts("");
        counter++;
      }
    }
    printf("%s%d\n\n", "The factorial is: ", factorial);
    printf("%s", "Enter number(-1 to exit): ");
    scanf("%d", &number);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
lea    0xeac(%rip),%rdi
lea    0xea8(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jl     126a <main+0x13a>
cmpl   $0x0,-0x8(%rbp)
jne    1192 <main+0x62>
movl   $0x1,-0x10(%rbp)
jmp    1228 <main+0xf8>
cmpl   $0x0,-0x8(%rbp)
jle    1223 <main+0xf3>
jmp    11a1 <main+0x71>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    121e <main+0xee>
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    -0xc(%rbp),%ecx
imul   %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edx
lea    0xe5b(%rip),%rdi
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edx
lea    0xe43(%rip),%rdi
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%edx
lea    0xe2b(%rip),%rdi
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe41(%rip),%rdi
call   1030 <puts@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a1 <main+0x71>
jmp    1223 <main+0xf3>
jmp    1228 <main+0xf8>
mov    -0x10(%rbp),%edx
lea    0xe14(%rip),%rdi
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdb9(%rip),%rdi
lea    0xdb5(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdc2(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
jmp    1172 <main+0x42>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rdi
lea    0xeba(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec7(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%edx
test   %edx,%edx
js     1247 <main+0x117>
mov    $0x1,%ebp
lea    0xea8(%rip),%r13
lea    0xeb0(%rip),%rbx
lea    0xeb3(%rip),%r15
xor    %r14d,%r14d
jmp    11da <main+0xaa>
nopl   0x0(%rax)
mov    $0x1,%ebp
lea    0xeaa(%rip),%rdi
lea    0xeaa(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe4d(%rip),%rdi
lea    0xe49(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe56(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%edx
test   %edx,%edx
js     1247 <main+0x117>
test   %edx,%edx
je     1190 <main+0x60>
cmp    %r14d,%edx
jle    1195 <main+0x65>
mov    %r14d,%r12d
neg    %r12d
nopl   0x0(%rax)
lea    (%rdx,%r12,1),%eax
imul   %eax,%ebp
mov    %r13,%rdi
lea    0xe26(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r14d
mov    0x4(%rsp),%edx
add    $0xffffffff,%r12d
cmp    %r14d,%edx
jg     11f0 <main+0xc0>
jmp    1195 <main+0x65>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [27 x i8] c"Enter number(-1 to exit): \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [6 x i8] c"%s%d\0A\00"
@.str.4 = [9 x i8] c"number: \00"
@.str.5 = [10 x i8] c"counter: \00"
@.str.6 = [12 x i8] c"factorial: \00"
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [7 x i8] c"%s%d\0A\0A\00"
@.str.9 = [19 x i8] c"The factorial is: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 1, i32* %4
%5 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
br label %7
7: ; preds = %39, %0
%8 = load i32, i32* %2
%9 = icmp sge i32 %8, 0
br i1 %9, label %10, label %44
10: ; preds = %7
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 1, i32* %4
br label %39
14: ; preds = %10
%15 = load i32, i32* %2
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %38
17: ; preds = %14
br label %18
18: ; preds = %22, %17
%19 = load i32, i32* %3
%20 = load i32, i32* %2
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %37
22: ; preds = %18
%23 = load i32, i32* %4
%24 = load i32, i32* %2
%25 = load i32, i32* %3
%26 = sub nsw i32 %24, %25
%27 = mul nsw i32 %23, %26
store i32 %27, i32* %4
%28 = load i32, i32* %2
%29 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %3
%31 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %4
%33 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %32)
%34 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0))
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %18
37: ; preds = %18
br label %38
38: ; preds = %37, %14
br label %39
39: ; preds = %38, %13
%40 = load i32, i32* %4
%41 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i32 %40)
%42 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%43 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
br label %7
44: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [27 x i8] c"Enter number(-1 to exit): \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [6 x i8] c"%s%d\0A\00"
@.str.4 = [9 x i8] c"number: \00"
@.str.5 = [10 x i8] c"counter: \00"
@.str.6 = [12 x i8] c"factorial: \00"
@.str.8 = [7 x i8] c"%s%d\0A\0A\00"
@.str.9 = [19 x i8] c"The factorial is: \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %35
7: ; preds = %0, %27
%8 = phi i32 [ %33, %27 ], [ %5, %0 ]
%9 = phi i32 [ %29, %27 ], [ 1, %0 ]
%10 = phi i32 [ %28, %27 ], [ 0, %0 ]
%11 = icmp eq i32 %8, 0
br i1 %11, label %27, label %12
12: ; preds = %7
%13 = icmp sgt i32 %8, %10
br i1 %13, label %14, label %27
14: ; preds = %12, %14
%15 = phi i32 [ %25, %14 ], [ %8, %12 ]
%16 = phi i32 [ %19, %14 ], [ %9, %12 ]
%17 = phi i32 [ %24, %14 ], [ %10, %12 ]
%18 = sub nsw i32 %15, %17
%19 = mul nsw i32 %18, %16
%20 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %15)
%21 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %17)
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %19)
%23 = call i32 @putchar(i32 10)
%24 = add nsw i32 %17, 1
%25 = load i32, i32* %1
%26 = icmp sgt i32 %25, %24
br i1 %26, label %14, label %27
27: ; preds = %14, %12, %7
%28 = phi i32 [ %10, %7 ], [ %10, %12 ], [ %24, %14 ]
%29 = phi i32 [ 1, %7 ], [ %9, %12 ], [ %19, %14 ]
%30 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i32 %29)
%31 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%33 = load i32, i32* %1
%34 = icmp sgt i32 %33, -1
br i1 %34, label %7, label %35
35: ; preds = %27, %0
ret i32 0
}