#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*/ printf(char *, char *);
void print_string(char str[], char new_str[], int curr_len, int n, int len) {
  if (curr_len == len) {
    printf("%s\n", new_str);
    return;
  } else {
    int i;
    for (i = 0; i < n; i++) {
      new_str[curr_len] = str[i];
      print_string(str, new_str, curr_len + 1, n, len);
    }
  }
}


x86 assembly (clang, -O0):
<print_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    115b <print_string+0x3b>
mov    -0x10(%rbp),%rsi
lea    0xeaf(%rip),%rdi
call   1030 <printf@plt>
jmp    11b1 <print_string+0x91>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11ac <print_string+0x8c>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1040 <print_string@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1162 <print_string+0x42>
jmp    11b1 <print_string+0x91>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,0xc(%rsp)
mov    %rsi,%rbx
cmp    %r8d,%edx
jne    1157 <print_string+0x37>
lea    0xebf(%rip),%rdi
mov    %rbx,%rsi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11ac <print_string+0x8c>
mov    %r8d,%r13d
mov    %edx,%r12d
mov    %rdi,%rbp
movslq %edx,%rax
mov    %rax,0x10(%rsp)
add    $0x1,%r12d
mov    0xc(%rsp),%r14d
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%rbp,%r15,1),%eax
mov    0x10(%rsp),%rcx
mov    %al,(%rbx,%rcx,1)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
mov    0xc(%rsp),%ecx
mov    %r13d,%r8d
call   1040 <print_string@plt>
add    $0x1,%r15
cmp    %r15,%r14
jne    1180 <print_string+0x60>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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