#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 CheckSolution(int *, int *, int);
int *ConvertToIntMatrix(char *, int);
int *CreateIntMatrix(int);
int /*<<< orphan*/ PrintSolution(int *, int);
int SolutionDifferentDigitsThanNumber(int *, int *, int, int *);
int SolutionSameDigitsAsNumber(int *, int, int *);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ printf(char *);
void FindSolution(int *Number, int NumberOfDigits, char *NumberString) {
  if (Number[0] == 1) {
    int *SolutionBig;
    int *FirstTryNumber;
    bool Valid1 = false;
    bool Valid = false;
    SolutionBig = CreateIntMatrix(NumberOfDigits);
    FirstTryNumber = ConvertToIntMatrix(NumberString, NumberOfDigits);
    Valid1 =
        SolutionSameDigitsAsNumber(FirstTryNumber, NumberOfDigits, SolutionBig);
    Valid = CheckSolution(Number, SolutionBig, NumberOfDigits);
    if (Valid1 == true && Valid == true) {
      PrintSolution(SolutionBig, NumberOfDigits);
      free(SolutionBig);
      free(FirstTryNumber);
    } else {
      free(FirstTryNumber);
      free(SolutionBig);
      int *SolutionSmall;
      int *SecondTryNumber;
      bool Valid2 = false;
      Valid = false;
      SolutionSmall = CreateIntMatrix(NumberOfDigits);
      SecondTryNumber = ConvertToIntMatrix(NumberString, NumberOfDigits);
      Valid2 = SolutionDifferentDigitsThanNumber(Number, SecondTryNumber,
                                                 NumberOfDigits, SolutionSmall);
      Valid = CheckSolution(Number, SolutionSmall, NumberOfDigits - 1);
      if (Valid2 == true && Valid == true)
        PrintSolution(SolutionSmall, NumberOfDigits - 1);
      else
        printf("0\n");
      free(SolutionSmall);
      free(SecondTryNumber);
    }
  } else {
    int *Solution;
    int *NumberCopy;
    NumberCopy = ConvertToIntMatrix(NumberString, NumberOfDigits);
    bool Valid = false;
    Solution = CreateIntMatrix(NumberOfDigits);
    Valid = SolutionSameDigitsAsNumber(NumberCopy, NumberOfDigits, Solution);
    Valid = CheckSolution(Number, Solution, NumberOfDigits);
    if (Valid == false)
      printf("0\n");
    else
      PrintSolution(Solution, NumberOfDigits);
    free(Solution);
    free(NumberCopy);
  }
}


x86 assembly (clang, -O0):
<FindSolution>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x1,(%rax)
jne    12db <FindSolution+0x15b>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0xc(%rbp),%edi
call   1080 <CreateIntMatrix@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <ConvertToIntMatrix@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   10a0 <SolutionSameDigitsAsNumber@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <CheckSolution@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jne    1227 <FindSolution+0xa7>
cmpl   $0x1,-0x30(%rbp)
jne    1227 <FindSolution+0xa7>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <PrintSolution@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    12d6 <FindSolution+0x156>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0xc(%rbp),%edi
call   1080 <CreateIntMatrix@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <ConvertToIntMatrix@plt>
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x38(%rbp),%rcx
call   1090 <SolutionDifferentDigitsThanNumber@plt>
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
call   1050 <CheckSolution@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x1,-0x44(%rbp)
jne    12b8 <FindSolution+0x138>
cmpl   $0x1,-0x30(%rbp)
jne    12b8 <FindSolution+0x138>
mov    -0x38(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
call   1070 <PrintSolution@plt>
jmp    12c4 <FindSolution+0x144>
lea    0xd41(%rip),%rdi
call   1060 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
jmp    135d <FindSolution+0x1dd>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <ConvertToIntMatrix@plt>
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0xc(%rbp),%edi
call   1080 <CreateIntMatrix@plt>
mov    %rax,-0x50(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x50(%rbp),%rdx
call   10a0 <SolutionSameDigitsAsNumber@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <CheckSolution@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jne    133f <FindSolution+0x1bf>
lea    0xccb(%rip),%rdi
call   1060 <printf@plt>
jmp    134b <FindSolution+0x1cb>
mov    -0x50(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <PrintSolution@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FindSolution>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %esi,%ebp
mov    %rdi,%r15
cmpl   $0x1,(%rdi)
jne    1242 <FindSolution+0xc2>
mov    %ebp,%edi
call   1080 <CreateIntMatrix@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %ebp,%esi
call   1050 <ConvertToIntMatrix@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
call   10a0 <SolutionSameDigitsAsNumber@plt>
mov    %eax,%r13d
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1060 <CheckSolution@plt>
cmp    $0x1,%r13d
jne    11df <FindSolution+0x5f>
cmp    $0x1,%eax
je     1277 <FindSolution+0xf7>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
call   1080 <CreateIntMatrix@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %ebp,%esi
call   1050 <ConvertToIntMatrix@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    %rax,%rsi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1090 <SolutionDifferentDigitsThanNumber@plt>
mov    %eax,%r12d
add    $0xffffffff,%ebp
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1060 <CheckSolution@plt>
cmp    $0x1,%r12d
jne    1234 <FindSolution+0xb4>
cmp    $0x1,%eax
je     1277 <FindSolution+0xf7>
lea    0xdc5(%rip),%rdi
call   1040 <puts@plt>
jmp    1281 <FindSolution+0x101>
mov    %r12,%rdi
mov    %ebp,%esi
call   1050 <ConvertToIntMatrix@plt>
mov    %rax,%r14
mov    %ebp,%edi
call   1080 <CreateIntMatrix@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   10a0 <SolutionSameDigitsAsNumber@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1060 <CheckSolution@plt>
test   %eax,%eax
je     1234 <FindSolution+0xb4>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <PrintSolution@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"0\0A\00"
define void @FindSolution(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%17 = load i32*, i32** %4
%18 = getelementptr inbounds i32, i32* %17, i64 0
%19 = load i32, i32* %18
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %86
21: ; preds = %3
store i32 0, i32* %9
store i32 0, i32* %10
%22 = load i32, i32* %5
%23 = call i32* @CreateIntMatrix(i32 %22)
store i32* %23, i32** %7
%24 = load i8*, i8** %6
%25 = load i32, i32* %5
%26 = call i32* @ConvertToIntMatrix(i8* %24, i32 %25)
store i32* %26, i32** %8
%27 = load i32*, i32** %8
%28 = load i32, i32* %5
%29 = load i32*, i32** %7
%30 = call i32 @SolutionSameDigitsAsNumber(i32* %27, i32 %28, i32* %29)
store i32 %30, i32* %9
%31 = load i32*, i32** %4
%32 = load i32*, i32** %7
%33 = load i32, i32* %5
%34 = call i32 @CheckSolution(i32* %31, i32* %32, i32 %33)
store i32 %34, i32* %10
%35 = load i32, i32* %9
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %48
37: ; preds = %21
%38 = load i32, i32* %10
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %48
40: ; preds = %37
%41 = load i32*, i32** %7
%42 = load i32, i32* %5
%43 = call i32 @PrintSolution(i32* %41, i32 %42)
%44 = load i32*, i32** %7
%45 = call i32 @free(i32* %44)
%46 = load i32*, i32** %8
%47 = call i32 @free(i32* %46)
br label %85
48: ; preds = %37, %21
%49 = load i32*, i32** %8
%50 = call i32 @free(i32* %49)
%51 = load i32*, i32** %7
%52 = call i32 @free(i32* %51)
store i32 0, i32* %13
store i32 0, i32* %10
%53 = load i32, i32* %5
%54 = call i32* @CreateIntMatrix(i32 %53)
store i32* %54, i32** %11
%55 = load i8*, i8** %6
%56 = load i32, i32* %5
%57 = call i32* @ConvertToIntMatrix(i8* %55, i32 %56)
store i32* %57, i32** %12
%58 = load i32*, i32** %4
%59 = load i32*, i32** %12
%60 = load i32, i32* %5
%61 = load i32*, i32** %11
%62 = call i32 @SolutionDifferentDigitsThanNumber(i32* %58, i32* %59, i32 %60, i32* %61)
store i32 %62, i32* %13
%63 = load i32*, i32** %4
%64 = load i32*, i32** %11
%65 = load i32, i32* %5
%66 = sub nsw i32 %65, 1
%67 = call i32 @CheckSolution(i32* %63, i32* %64, i32 %66)
store i32 %67, i32* %10
%68 = load i32, i32* %13
%69 = icmp eq i32 %68, 1
br i1 %69, label %70, label %78
70: ; preds = %48
%71 = load i32, i32* %10
%72 = icmp eq i32 %71, 1
br i1 %72, label %73, label %78
73: ; preds = %70
%74 = load i32*, i32** %11
%75 = load i32, i32* %5
%76 = sub nsw i32 %75, 1
%77 = call i32 @PrintSolution(i32* %74, i32 %76)
br label %80
78: ; preds = %70, %48
%79 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %80
80: ; preds = %78, %73
%81 = load i32*, i32** %11
%82 = call i32 @free(i32* %81)
%83 = load i32*, i32** %12
%84 = call i32 @free(i32* %83)
br label %85
85: ; preds = %80, %40
br label %113
86: ; preds = %3
%87 = load i8*, i8** %6
%88 = load i32, i32* %5
%89 = call i32* @ConvertToIntMatrix(i8* %87, i32 %88)
store i32* %89, i32** %15
store i32 0, i32* %16
%90 = load i32, i32* %5
%91 = call i32* @CreateIntMatrix(i32 %90)
store i32* %91, i32** %14
%92 = load i32*, i32** %15
%93 = load i32, i32* %5
%94 = load i32*, i32** %14
%95 = call i32 @SolutionSameDigitsAsNumber(i32* %92, i32 %93, i32* %94)
store i32 %95, i32* %16
%96 = load i32*, i32** %4
%97 = load i32*, i32** %14
%98 = load i32, i32* %5
%99 = call i32 @CheckSolution(i32* %96, i32* %97, i32 %98)
store i32 %99, i32* %16
%100 = load i32, i32* %16
%101 = icmp eq i32 %100, 0
br i1 %101, label %102, label %104
102: ; preds = %86
%103 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %108
104: ; preds = %86
%105 = load i32*, i32** %14
%106 = load i32, i32* %5
%107 = call i32 @PrintSolution(i32* %105, i32 %106)
br label %108
108: ; preds = %104, %102
%109 = load i32*, i32** %14
%110 = call i32 @free(i32* %109)
%111 = load i32*, i32** %15
%112 = call i32 @free(i32* %111)
br label %113
113: ; preds = %108, %85
ret void
}

LLVM IR (-O2):
@str.1 = [2 x i8] c"0\00"
define void @FindSolution(i32* %0, i32 %1, i8* %2) {
%4 = load i32, i32* %0
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %31
6: ; preds = %3
%7 = tail call i32* @CreateIntMatrix(i32 %1)
%8 = tail call i32* @ConvertToIntMatrix(i8* %2, i32 %1)
%9 = tail call i32 @SolutionSameDigitsAsNumber(i32* %8, i32 %1, i32* %7)
%10 = tail call i32 @CheckSolution(i32* %0, i32* %7, i32 %1)
%11 = icmp eq i32 %9, 1
%12 = icmp eq i32 %10, 1
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = tail call i32 @PrintSolution(i32* %7, i32 %1)
br label %41
16: ; preds = %6
%17 = tail call i32 @free(i32* %8)
%18 = tail call i32 @free(i32* %7)
%19 = tail call i32* @CreateIntMatrix(i32 %1)
%20 = tail call i32* @ConvertToIntMatrix(i8* %2, i32 %1)
%21 = tail call i32 @SolutionDifferentDigitsThanNumber(i32* %0, i32* %20, i32 %1, i32* %19)
%22 = add nsw i32 %1, -1
%23 = tail call i32 @CheckSolution(i32* %0, i32* %19, i32 %22)
%24 = icmp eq i32 %21, 1
%25 = icmp eq i32 %23, 1
%26 = select i1 %24, i1 %25, i1 false
br i1 %26, label %27, label %29
27: ; preds = %16
%28 = tail call i32 @PrintSolution(i32* %19, i32 %22)
br label %41
29: ; preds = %16
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.1, i64 0, i64 0))
br label %41
31: ; preds = %3
%32 = tail call i32* @ConvertToIntMatrix(i8* %2, i32 %1)
%33 = tail call i32* @CreateIntMatrix(i32 %1)
%34 = tail call i32 @SolutionSameDigitsAsNumber(i32* %32, i32 %1, i32* %33)
%35 = tail call i32 @CheckSolution(i32* %0, i32* %33, i32 %1)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.1, i64 0, i64 0))
br label %41
39: ; preds = %31
%40 = tail call i32 @PrintSolution(i32* %33, i32 %1)
br label %41
41: ; preds = %37, %39, %27, %29, %14
%42 = phi i32* [ %7, %14 ], [ %19, %29 ], [ %19, %27 ], [ %33, %39 ], [ %33, %37 ]
%43 = phi i32* [ %8, %14 ], [ %20, %29 ], [ %20, %27 ], [ %32, %39 ], [ %32, %37 ]
%44 = tail call i32 @free(i32* %42)
%45 = tail call i32 @free(i32* %43)
ret void
}