#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*/ exit(int);
char *getPermutation(int, int);
int /*<<< orphan*/ printf(char *, ...);
void test(int n, int k, char *ret) {
  char *result;
  result = getPermutation(n, k);
  printf("n = %d, k = %d, result = %s\n", n, k, result);
  for (int i = 0; i < n; ++i) {
    if (!(result[i] == ret[i])) {
      printf("assert fail: %s\n", "test");
      exit(-1);
    };
  }
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <getPermutation@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ce <test+0x9e>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x10(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11bb <test+0x8b>
lea    0xe7a(%rip),%rdi
lea    0xe84(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
jmp    11c0 <test+0x90>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1170 <test+0x40>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%ebp
call   1040 <getPermutation@plt>
mov    %rax,%rbx
lea    0xeb2(%rip),%rdi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1030 <printf@plt>
test   %ebp,%ebp
jle    1183 <test+0x53>
mov    %ebp,%eax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rbx,%rcx,1),%edx
cmp    (%r14,%rcx,1),%dl
jne    118e <test+0x5e>
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1170 <test+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe88(%rip),%rdi
lea    0xe92(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"n = %d, k = %d, result = %s\0A\00"
@.str.1 = [17 x i8] c"assert fail: %s\0A\00"
@.str.2 = [5 x i8] c"test\00"
define void @test(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i32, i32* %4
%10 = load i32, i32* %5
%11 = call i8* @getPermutation(i32 %9, i32 %10)
store i8* %11, i8** %7
%12 = load i32, i32* %4
%13 = load i32, i32* %5
%14 = load i8*, i8** %7
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13, i8* %14)
store i32 0, i32* %8
br label %16
16: ; preds = %38, %3
%17 = load i32, i32* %8
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %41
20: ; preds = %16
%21 = load i8*, i8** %7
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = load i8*, i8** %6
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %26, %32
br i1 %33, label %37, label %34
34: ; preds = %20
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @exit(i32 -1)
unreachable
37: ; preds = %20
br label %38
38: ; preds = %37
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %16
41: ; preds = %16
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"n = %d, k = %d, result = %s\0A\00"
@.str.1 = [17 x i8] c"assert fail: %s\0A\00"
@.str.2 = [5 x i8] c"test\00"
define void @test(i32 %0, i32 %1, i8* nocapture %2) {
%4 = tail call i8* @getPermutation(i32 %0, i32 %1)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1, i8* %4)
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = zext i32 %0 to i64
br label %12
9: ; preds = %12
%10 = icmp eq i64 %19, %8
br i1 %10, label %11, label %12
11: ; preds = %9, %3
ret void
12: ; preds = %7, %9
%13 = phi i64 [ 0, %7 ], [ %19, %9 ]
%14 = getelementptr inbounds i8, i8* %4, i64 %13
%15 = load i8, i8* %14
%16 = getelementptr inbounds i8, i8* %2, i64 %13
%17 = load i8, i8* %16
%18 = icmp eq i8 %15, %17
%19 = add nuw nsw i64 %13, 1
br i1 %18, label %9, label %20
20: ; preds = %12
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%22 = tail call i32 @exit(i32 -1)
unreachable
}