#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__ checksafe(char *, int, int);
int /*<<< orphan*/ printf(char *, char *);
void distance1_util(char str1[], char str2[], int pos, int len, int d) {
  if (pos == len) {
    str2[len] = '\0';
    printf("%s\n", str2);
    return;
  }
  for (int i = 0; i < len; i++) {
    str2[pos] = str1[i];
    if (checksafe(str2, pos, d)) {
      distance1_util(str1, str2, pos + 1, len, d);
    }
  }
}


x86 assembly (clang, -O0):
<distance1_util>:
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    -0x18(%rbp),%eax
jne    1177 <distance1_util+0x47>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rsi
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
jmp    11e6 <distance1_util+0xb6>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11e6 <distance1_util+0xb6>
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    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1050 <checksafe@plt>
cmp    $0x0,%rax
je     11d3 <distance1_util+0xa3>
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 <distance1_util@plt>
jmp    11d8 <distance1_util+0xa8>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    117e <distance1_util+0x4e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distance1_util>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
cmp    %ecx,%edx
jne    116c <distance1_util+0x3c>
movslq %r14d,%rax
movb   $0x0,(%rbx,%rax,1)
lea    0xeaa(%rip),%rdi
mov    %rbx,%rsi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>
mov    %ecx,0x8(%rsp)
test   %ecx,%ecx
jle    11e2 <distance1_util+0xb2>
mov    %r8d,%r12d
mov    %rdi,%rbp
movslq %r14d,%rax
mov    %rax,0x10(%rsp)
lea    0x1(%r14),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%r15d
xor    %r13d,%r13d
jmp    11a9 <distance1_util+0x79>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r13
cmp    %r13,%r15
je     11e2 <distance1_util+0xb2>
movzbl 0x0(%rbp,%r13,1),%eax
mov    0x10(%rsp),%rcx
mov    %al,(%rbx,%rcx,1)
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r12d,%edx
call   1050 <checksafe@plt>
test   %rax,%rax
je     11a0 <distance1_util+0x70>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    %r12d,%r8d
call   1040 <distance1_util@plt>
jmp    11a0 <distance1_util+0x70>
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 @distance1_util(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* %9
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %22
15: ; preds = %5
%16 = load i8*, i8** %7
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 0, i8* %19
%20 = load i8*, i8** %7
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %53
22: ; preds = %5
store i32 0, i32* %11
br label %23
23: ; preds = %50, %22
%24 = load i32, i32* %11
%25 = load i32, i32* %9
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %53
27: ; preds = %23
%28 = load i8*, i8** %6
%29 = load i32, i32* %11
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = load i8*, i8** %7
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 %32, i8* %36
%37 = load i8*, i8** %7
%38 = load i32, i32* %8
%39 = load i32, i32* %10
%40 = call i64 @checksafe(i8* %37, i32 %38, i32 %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %27
%43 = load i8*, i8** %6
%44 = load i8*, i8** %7
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
%47 = load i32, i32* %9
%48 = load i32, i32* %10
br label %49
49: ; preds = %42, %27
br label %50
50: ; preds = %49
%51 = load i32, i32* %11
%52 = add nsw i32 %51, 1
store i32 %52, i32* %11
br label %23
53: ; preds = %15, %23
ret void
}

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