#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(scalar_t__);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char);
scalar_t__ strlen(char *);
void gen(char *old_prefix, char current, char *pattern, char *charset,
         char wildcard) {
  char *p;
  char *prefix = (char *)malloc(strlen(old_prefix) + 2);
  sprintf(prefix, "%s%c", old_prefix, current);
  if (!*pattern) {
    printf("%s\n", prefix);
  } else {
    if (*pattern == wildcard) {
      for (p = charset; *p; p++) {
        gen(prefix, *p, pattern + 1, charset, wildcard);
      }
    } else {
      gen(prefix, *pattern, pattern + 1, charset, wildcard);
    }
  }
  free(prefix);
}


x86 assembly (clang, -O0):
<gen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %r8b,%al
mov    %rdi,-0x8(%rbp)
mov    %sil,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %al,-0x21(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe5a(%rip),%rsi
movsbl -0x9(%rbp),%ecx
call   1080 <sprintf@plt>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11d1 <gen+0x71>
mov    -0x38(%rbp),%rsi
lea    0xe3e(%rip),%rdi
call   1050 <printf@plt>
jmp    125a <gen+0xfa>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x21(%rbp),%ecx
cmp    %ecx,%eax
jne    1232 <gen+0xd2>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
je     122d <gen+0xcd>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%al
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
mov    -0x20(%rbp),%rcx
movsbl %al,%esi
movsbl -0x21(%rbp),%r8d
call   1070 <gen@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11ec <gen+0x8c>
jmp    1255 <gen+0xf5>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
mov    -0x20(%rbp),%rcx
movsbl %al,%esi
movsbl -0x21(%rbp),%r8d
call   1070 <gen@plt>
jmp    125a <gen+0xfa>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%ebx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%r13d
mov    %rdi,%rbp
call   1040 <strlen@plt>
lea    0x2(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r12
lea    0xe6e(%rip),%rsi
mov    %rax,%rdi
mov    %rbp,%rdx
mov    %r13d,%ecx
call   1080 <sprintf@plt>
mov    (%r15),%al
test   %al,%al
je     11e1 <gen+0x81>
cmp    %bl,%al
jne    11f2 <gen+0x92>
mov    (%r14),%al
test   %al,%al
je     120b <gen+0xab>
add    $0x1,%r15
mov    %ebx,%ecx
lea    0x1(%r14),%rbx
movsbl %cl,%ebp
nop
movsbl %al,%esi
mov    %r12,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %ebp,%r8d
call   1070 <gen@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11c0 <gen+0x60>
jmp    120b <gen+0xab>
lea    0xe1d(%rip),%rdi
mov    %r12,%rsi
call   1050 <printf@plt>
jmp    120b <gen+0xab>
add    $0x1,%r15
movsbl %al,%esi
movsbl %bl,%r8d
mov    %r12,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1070 <gen@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%s%c\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @gen(i8* %0, i8 signext %1, i8* %2, i8* %3, i8 signext %4) {
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8
%11 = alloca i8*
%12 = alloca i8*
store i8* %0, i8** %6
store i8 %1, i8* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8 %4, i8* %10
%13 = load i8*, i8** %6
%14 = call i64 @strlen(i8* %13)
%15 = add nsw i64 %14, 2
%16 = call i64 @malloc(i64 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %12
%18 = load i8*, i8** %12
%19 = load i8*, i8** %6
%20 = load i8, i8* %7
%21 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %19, i8 signext %20)
%22 = load i8*, i8** %8
%23 = load i8, i8* %22
%24 = icmp ne i8 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %5
%26 = load i8*, i8** %12
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %62
28: ; preds = %5
%29 = load i8*, i8** %8
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = load i8, i8* %10
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %31, %33
br i1 %34, label %35, label %53
35: ; preds = %28
%36 = load i8*, i8** %9
store i8* %36, i8** %11
br label %37
37: ; preds = %49, %35
%38 = load i8*, i8** %11
%39 = load i8, i8* %38
%40 = icmp ne i8 %39, 0
br i1 %40, label %41, label %52
41: ; preds = %37
%42 = load i8*, i8** %12
%43 = load i8*, i8** %11
%44 = load i8, i8* %43
%45 = load i8*, i8** %8
%46 = getelementptr inbounds i8, i8* %45, i64 1
%47 = load i8*, i8** %9
%48 = load i8, i8* %10
br label %49
49: ; preds = %41
%50 = load i8*, i8** %11
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %11
br label %37
52: ; preds = %37
br label %61
53: ; preds = %28
%54 = load i8*, i8** %12
%55 = load i8*, i8** %8
%56 = load i8, i8* %55
%57 = load i8*, i8** %8
%58 = getelementptr inbounds i8, i8* %57, i64 1
%59 = load i8*, i8** %9
%60 = load i8, i8* %10
br label %61
61: ; preds = %53, %52
br label %62
62: ; preds = %61, %25
%63 = load i8*, i8** %12
%64 = call i32 @free(i8* %63)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%c\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @gen(i8* %0, i8 signext %1, i8* %2, i8* %3, i8 signext %4) {
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = add nsw i64 %6, 2
%8 = tail call i64 @malloc(i64 %7)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i8 signext %1)
%11 = load i8, i8* %2
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %5
%14 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %30
15: ; preds = %5
%16 = icmp eq i8 %11, %4
br i1 %16, label %17, label %28
17: ; preds = %15
%18 = load i8, i8* %3
%19 = icmp eq i8 %18, 0
br i1 %19, label %30, label %20
20: ; preds = %17
%21 = getelementptr inbounds i8, i8* %2, i64 1
br label %22
22: ; preds = %20, %22
%23 = phi i8 [ %18, %20 ], [ %26, %22 ]
%24 = phi i8* [ %3, %20 ], [ %25, %22 ]
tail call void @gen(i8* %9, i8 signext %23, i8* %21, i8* %3, i8 signext %4)
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
br i1 %27, label %30, label %22
28: ; preds = %15
%29 = getelementptr inbounds i8, i8* %2, i64 1
tail call void @gen(i8* %9, i8 signext %11, i8* %29, i8* %3, i8 signext %4)
br label %30
30: ; preds = %22, %17, %28, %13
%31 = tail call i32 @free(i8* %9)
ret void
}