#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 int32_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fact(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int32_t n = 0;
  while (true) {
    printf("Please enter n or 999 for exit: ");
    scanf("%i", &n);
    if (n == 999) {
      break;
    }
    printf("(%i!) = %llu\n", n, fact(n));
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb6(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x3e7,-0x8(%rbp)
jne    1186 <main+0x46>
jmp    11ac <main+0x6c>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <fact@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1156 <main+0x16>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb8(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%ebp
cmp    $0x3e7,%ebp
je     11d6 <main+0x96>
lea    0xe9e(%rip),%r14
lea    0xe73(%rip),%r15
lea    0xe8d(%rip),%r12
lea    0xc(%rsp),%rbx
nopl   0x0(%rax)
mov    %ebp,%edi
call   1040 <fact@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%ebp
cmp    $0x3e7,%ebp
jne    11a0 <main+0x60>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"Please enter n or 999 for exit: \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [14 x i8] c"(%i!) = %llu\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
br label %3
3: ; preds = %0, %9
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 999
br i1 %7, label %8, label %9
8: ; preds = %3
br label %14
9: ; preds = %3
%10 = load i32, i32* %2
%11 = load i32, i32* %2
%12 = call i32 @fact(i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %10, i32 %12)
br label %3
14: ; preds = %8
%15 = load i32, i32* @EXIT_SUCCESS
%16 = call i32 @exit(i32 %15)
unreachable
}

LLVM IR (-O2):
@.str = [33 x i8] c"Please enter n or 999 for exit: \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [14 x i8] c"(%i!) = %llu\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp eq i32 %5, 999
br i1 %6, label %15, label %7
7: ; preds = %0, %7
%8 = phi i32 [ %13, %7 ], [ %5, %0 ]
%9 = call i32 @fact(i32 %8)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %8, i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%13 = load i32, i32* %1
%14 = icmp eq i32 %13, 999
br i1 %14, label %15, label %7
15: ; preds = %7, %0
%16 = load i32, i32* @EXIT_SUCCESS
%17 = call i32 @exit(i32 %16)
unreachable
}