#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 */
scalar_t__ atoi(char *);
unsigned int factorial(scalar_t__);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("Usage:\n> factorial N\n\nWhere N >= 0\n");
    return 1;
  }
  char n = *argv[1];
  if (!isdigit(n)) {
    printf("'%c' is not a number\n", n);
    return 1;
  }
  if (atoi(argv[1]) < 0) {
    printf("Number have to be greater or equal to 0\n");
    return 1;
  }
  unsigned int num = factorial(atoi(argv[1]));
  printf("%d\n", num);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     117a <main+0x3a>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1218 <main+0xd8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11b7 <main+0x77>
movsbl -0x11(%rbp),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1218 <main+0xd8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
cmp    $0x0,%rax
jge    11e8 <main+0xa8>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1218 <main+0xd8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %rax,%rdi
call   1040 <factorial@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    1197 <main+0x47>
mov    %rsi,%rbx
mov    0x8(%rsi),%rax
movsbl (%rax),%ebp
mov    %ebp,%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     11a0 <main+0x50>
mov    0x8(%rbx),%rdi
call   1070 <atoi@plt>
test   %rax,%rax
js     11b2 <main+0x62>
mov    %rax,%rdi
call   1050 <factorial@plt>
lea    0xe8c(%rip),%rdi
xor    %ebx,%ebx
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11c3 <main+0x73>
lea    0xea4(%rip),%rdi
jmp    11b9 <main+0x69>
lea    0xe59(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11be <main+0x6e>
lea    0xe61(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Usage:\0A> factorial N\0A\0AWhere N >= 0\0A\00"
@.str.1 = [22 x i8] c"'%c' is not a number\0A\00"
@.str.2 = [41 x i8] c"Number have to be greater or equal to 0\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %40
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i8, i8* %15
store i8 %16, i8* %6
%17 = load i8, i8* %6
%18 = call i32 @isdigit(i8 signext %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %12
%21 = load i8, i8* %6
%22 = sext i8 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %22)
store i32 1, i32* %3
br label %40
24: ; preds = %12
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i64 @atoi(i8* %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %40
32: ; preds = %24
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i64 @atoi(i8* %35)
%37 = call i32 @factorial(i64 %36)
store i32 %37, i32* %7
%38 = load i32, i32* %7
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %38)
store i32 0, i32* %3
br label %40
40: ; preds = %32, %30, %20, %10
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"'%c' is not a number\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@str = [40 x i8] c"Number have to be greater or equal to 0\00"
@str.4 = [35 x i8] c"Usage:\0A> factorial N\0A\0AWhere N >= 0\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.4, i64 0, i64 0))
br label %24
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i8, i8* %8
%10 = tail call i32 @isdigit(i8 signext %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %6
%13 = sext i8 %9 to i32
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %24
15: ; preds = %6
%16 = load i8*, i8** %7
%17 = tail call i64 @atoi(i8* %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %24
21: ; preds = %15
%22 = tail call i32 @factorial(i64 %17)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %12, %19, %21, %4
%25 = phi i32 [ 1, %4 ], [ 1, %19 ], [ 0, %21 ], [ 1, %12 ]
ret i32 %25
}