#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ permute(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ sequences(char *, char *, unsigned int, int /*<<< orphan*/);
int /*<<< orphan*/ subsets(char *, char *, int /*<<< orphan*/);
void test_combinatorics() {
  char *buf = (char *)malloc(sizeof(char) * 32);
  char cs[] = "abc";
  printf("\npermutations of %s:\n", cs);
  permute(cs, buf, 0);
  printf("\nsubsets of %s:\n", cs);
  subsets(cs, buf, 0);
  unsigned len = 2;
  printf("\nsequences of alphabet %s, length = %d:\n", cs, len);
  sequences(cs, buf, len, 0);
  free(buf);
}


x86 assembly (clang, -O0):
<test_combinatorics>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x20,%edi
call   1080 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    0xe84(%rip),%eax
mov    %eax,-0xc(%rbp)
lea    -0xc(%rbp),%rsi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xc(%rbp),%rdi
mov    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1040 <permute@plt>
lea    -0xc(%rbp),%rsi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xc(%rbp),%rdi
mov    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1070 <subsets@plt>
movl   $0x2,-0x10(%rbp)
lea    -0xc(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xc(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%edx
xor    %ecx,%ecx
call   1050 <sequences@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_combinatorics>:
push   %r14
push   %rbx
push   %rax
mov    $0x20,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
movl   $0x636261,0x4(%rsp)
lea    0xe80(%rip),%rdi
lea    0x4(%rsp),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <permute@plt>
lea    0xe73(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1070 <subsets@plt>
lea    0xe66(%rip),%rdi
mov    %r14,%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1050 <sequences@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.test_combinatorics.cs = [4 x i8] c"abc\00"
@.str = [22 x i8] c"\0Apermutations of %s:\0A\00"
@.str.1 = [17 x i8] c"\0Asubsets of %s:\0A\00"
@.str.2 = [41 x i8] c"\0Asequences of alphabet %s, length = %d:\0A\00"
define void @test_combinatorics() {
%1 = alloca i8*
%2 = alloca [4 x i8]
%3 = alloca i32
%4 = call i64 @malloc(i32 32)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %1
%6 = bitcast [4 x i8]* %2 to i8*
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%8 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%10 = load i8*, i8** %1
%11 = call i32 @permute(i8* %9, i8* %10, i32 0)
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%15 = load i8*, i8** %1
%16 = call i32 @subsets(i8* %14, i8* %15, i32 0)
store i32 2, i32* %3
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%18 = load i32, i32* %3
%19 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %17, i32 %18)
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%21 = load i8*, i8** %1
%22 = load i32, i32* %3
%23 = call i32 @sequences(i8* %20, i8* %21, i32 %22, i32 0)
%24 = load i8*, i8** %1
%25 = call i32 @free(i8* %24)
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"\0Apermutations of %s:\0A\00"
@.str.1 = [17 x i8] c"\0Asubsets of %s:\0A\00"
@.str.2 = [41 x i8] c"\0Asequences of alphabet %s, length = %d:\0A\00"
define void @test_combinatorics() {
%1 = alloca i32
%2 = tail call i64 @malloc(i32 32)
%3 = inttoptr i64 %2 to i8*
%4 = bitcast i32* %1 to i8*
store i32 6513249, i32* %1
%5 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = call i32 @permute(i8* %4, i8* %3, i32 0)
%7 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%8 = call i32 @subsets(i8* %4, i8* %3, i32 0)
%9 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32 2)
%10 = call i32 @sequences(i8* %4, i8* %3, i32 2, i32 0)
%11 = call i32 @free(i8* %3)
ret void
}