#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 fact(int);
int /*<<< orphan*/ permute(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int strlen(char *);
int main(int argc, char *argv[]) {
  char str[100];
  int len;
  int takenatatime = 0;
  printf("Enter a string:");
  scanf("%s", str);
  printf("Items taken at a time :");
  scanf("%d", &takenatatime);
  printf("Permutation:\n");
  len = strlen(str);
  printf("expect %d! / (%d - %d)! = %d results\n", len, len, takenatatime,
         fact(len) / fact(len - takenatatime));
  permute(str, 0, len - 1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x88(%rbp)
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rsi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe8a(%rip),%rdi
lea    -0x88(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%eax
mov    %eax,-0x98(%rbp)
mov    -0x84(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x88(%rbp),%eax
mov    %eax,-0x94(%rbp)
mov    -0x84(%rbp),%edi
call   1060 <fact@plt>
mov    %eax,-0x90(%rbp)
mov    -0x84(%rbp),%edi
sub    -0x88(%rbp),%edi
call   1060 <fact@plt>
mov    -0x98(%rbp),%esi
mov    -0x94(%rbp),%ecx
mov    %eax,%edi
mov    -0x90(%rbp),%eax
cltd
idiv   %edi
mov    -0x8c(%rbp),%edx
mov    %eax,%r8d
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    -0x84(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <permute@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
movl   $0x0,0xc(%rsp)
lea    0xe87(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe89(%rip),%rdi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
lea    0xe76(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe80(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    0xc(%rsp),%r15d
mov    %eax,%edi
call   1070 <fact@plt>
mov    %eax,%ebx
mov    %ebp,%edi
sub    0xc(%rsp),%edi
call   1070 <fact@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
lea    0xe3a(%rip),%rdi
mov    %ebp,%esi
mov    %ebp,%edx
mov    %r15d,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <printf@plt>
add    $0xffffffff,%ebp
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <permute@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Enter a string:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [24 x i8] c"Items taken at a time :\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [14 x i8] c"Permutation:\0A\00"
@.str.5 = [38 x i8] c"expect %d! / (%d - %d)! = %d results\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [100 x i8]
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 0, i32* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = load i32, i32* %6
%18 = load i32, i32* %7
%19 = load i32, i32* %6
%20 = call i32 @fact(i32 %19)
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = sub nsw i32 %21, %22
%24 = call i32 @fact(i32 %23)
%25 = sdiv i32 %20, %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %16, i32 %17, i32 %18, i32 %25)
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%28 = load i32, i32* %6
%29 = sub nsw i32 %28, 1
%30 = call i32 @permute(i8* %27, i32 0, i32 %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"Enter a string:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [24 x i8] c"Items taken at a time :\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.5 = [38 x i8] c"expect %d! / (%d - %d)! = %d results\0A\00"
@str = [13 x i8] c"Permutation:\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%12 = call i32 @strlen(i8* %5)
%13 = load i32, i32* %4
%14 = call i32 @fact(i32 %12)
%15 = load i32, i32* %4
%16 = sub nsw i32 %12, %15
%17 = call i32 @fact(i32 %16)
%18 = sdiv i32 %14, %17
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %12, i32 %12, i32 %13, i32 %18)
%20 = add nsw i32 %12, -1
%21 = call i32 @permute(i8* %5, i32 0, i32 %20)
ret i32 0
}