#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 next_result(char *, size_t, int, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, int *, ...);
unsigned magic_numbers_aux(char *pattern, size_t patt_i, int res_so_far) {
  if (patt_i > 0 && pattern[patt_i - 1] == '=') {
    int target;
    sscanf(&pattern[patt_i], "%d", &target);
    if (res_so_far == target) {
      printf("%s\n", pattern);
      return 1;
    }
    return 0;
  }
  if (pattern[patt_i] != '_') {
    int n;
    int read;
    sscanf(&pattern[patt_i], "%d%n", &n, &read);
    res_so_far = next_result(pattern, patt_i, n, res_so_far);
    return magic_numbers_aux(pattern, patt_i + read + 1, res_so_far);
  }
  int i;
  int matches = 0;
  for (i = 1; i < 10; i++) {
    int new_res = next_result(pattern, patt_i, i, res_so_far);
    pattern[patt_i] = '0' + i;
    matches += magic_numbers_aux(pattern, patt_i + 2, new_res);
  }
  pattern[patt_i] = '_';
  return matches;
}


x86 assembly (clang, -O0):
<magic_numbers_aux>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    11c5 <magic_numbers_aux+0x85>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
jne    11c5 <magic_numbers_aux+0x85>
mov    -0x10(%rbp),%rdi
add    -0x18(%rbp),%rdi
lea    0xe7a(%rip),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    11b9 <magic_numbers_aux+0x79>
mov    -0x10(%rbp),%rsi
lea    0xe5b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ac <magic_numbers_aux+0x16c>
movl   $0x0,-0x4(%rbp)
jmp    12ac <magic_numbers_aux+0x16c>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5f,%eax
je     1231 <magic_numbers_aux+0xf1>
mov    -0x10(%rbp),%rdi
add    -0x18(%rbp),%rdi
lea    0xe1e(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1060 <next_result@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x28(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
mov    -0x1c(%rbp),%edx
call   1040 <magic_numbers_aux@plt>
mov    %eax,-0x4(%rbp)
jmp    12ac <magic_numbers_aux+0x16c>
movl   $0x0,-0x30(%rbp)
movl   $0x1,-0x2c(%rbp)
cmpl   $0xa,-0x2c(%rbp)
jge    129a <magic_numbers_aux+0x15a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1060 <next_result@plt>
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x30,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x2,%rsi
mov    -0x34(%rbp),%edx
call   1040 <magic_numbers_aux@plt>
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    123f <magic_numbers_aux+0xff>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x5f,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<magic_numbers_aux>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rsi,%rsi
je     11a3 <magic_numbers_aux+0x63>
cmpb   $0x3d,-0x1(%r14,%rbx,1)
jne    11a3 <magic_numbers_aux+0x63>
add    %rbx,%r14
lea    0xe92(%rip),%rsi
xor    %ebp,%ebp
lea    0x14(%rsp),%rdx
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <sscanf@plt>
cmp    %r12d,0x14(%rsp)
jne    137f <magic_numbers_aux+0x23f>
lea    0xe72(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x1,%ebp
jmp    137f <magic_numbers_aux+0x23f>
cmpb   $0x5f,(%rbx,%r14,1)
jne    1338 <magic_numbers_aux+0x1f8>
lea    0x2(%r14),%r15
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
mov    %r12d,%ecx
call   1060 <next_result@plt>
movb   $0x31,(%rbx,%r14,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <magic_numbers_aux@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
mov    %r12d,%ecx
call   1060 <next_result@plt>
movb   $0x32,(%rbx,%r14,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <magic_numbers_aux@plt>
mov    %eax,%ebp
add    %r13d,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
mov    %r12d,%ecx
call   1060 <next_result@plt>
movb   $0x33,(%rbx,%r14,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <magic_numbers_aux@plt>
mov    %eax,%r13d
add    %ebp,%r13d
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
mov    %r12d,%ecx
call   1060 <next_result@plt>
movb   $0x34,(%rbx,%r14,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <magic_numbers_aux@plt>
mov    %eax,%ebp
add    %r13d,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
mov    %r12d,%ecx
call   1060 <next_result@plt>
movb   $0x35,(%rbx,%r14,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <magic_numbers_aux@plt>
mov    %eax,%r13d
add    %ebp,%r13d
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x6,%edx
mov    %r12d,%ecx
call   1060 <next_result@plt>
movb   $0x36,(%rbx,%r14,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <magic_numbers_aux@plt>
mov    %eax,%ebp
add    %r13d,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x7,%edx
mov    %r12d,%ecx
call   1060 <next_result@plt>
movb   $0x37,(%rbx,%r14,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <magic_numbers_aux@plt>
mov    %eax,%r13d
add    %ebp,%r13d
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
mov    %r12d,%ecx
call   1060 <next_result@plt>
movb   $0x38,(%rbx,%r14,1)
mov    %rbx,%rdi
mov    %r15,%rbp
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <magic_numbers_aux@plt>
mov    %eax,%r15d
add    %r13d,%r15d
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x9,%edx
mov    %r12d,%ecx
call   1060 <next_result@plt>
movb   $0x39,(%rbx,%r14,1)
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <magic_numbers_aux@plt>
mov    %eax,%ebp
add    %r15d,%ebp
movb   $0x5f,(%rbx,%r14,1)
jmp    137f <magic_numbers_aux+0x23f>
lea    (%rbx,%r14,1),%rdi
lea    0xcc4(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    0x10(%rsp),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12d,%ecx
call   1060 <next_result@plt>
movslq 0xc(%rsp),%rcx
lea    (%r14,%rcx,1),%rsi
add    $0x1,%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1040 <magic_numbers_aux@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [5 x i8] c"%d%n\00"
define i32 @magic_numbers_aux(i8* %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
%14 = load i64, i64* %6
%15 = icmp ugt i64 %14, 0
br i1 %15, label %16, label %36
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = load i64, i64* %6
%19 = sub i64 %18, 1
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 61
br i1 %23, label %24, label %36
24: ; preds = %16
%25 = load i8*, i8** %5
%26 = load i64, i64* %6
%27 = getelementptr inbounds i8, i8* %25, i64 %26
%28 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %35
32: ; preds = %24
%33 = load i8*, i8** %5
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %33)
store i32 1, i32* %4
br label %92
35: ; preds = %24
store i32 0, i32* %4
br label %92
36: ; preds = %16, %3
%37 = load i8*, i8** %5
%38 = load i64, i64* %6
%39 = getelementptr inbounds i8, i8* %37, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp ne i32 %41, 95
br i1 %42, label %43, label %61
43: ; preds = %36
%44 = load i8*, i8** %5
%45 = load i64, i64* %6
%46 = getelementptr inbounds i8, i8* %44, i64 %45
%47 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %46, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %9, i32* %10)
%48 = load i8*, i8** %5
%49 = load i64, i64* %6
%50 = load i32, i32* %9
%51 = load i32, i32* %7
%52 = call i32 @next_result(i8* %48, i64 %49, i32 %50, i32 %51)
store i32 %52, i32* %7
%53 = load i8*, i8** %5
%54 = load i64, i64* %6
%55 = load i32, i32* %10
%56 = sext i32 %55 to i64
%57 = add i64 %54, %56
%58 = add i64 %57, 1
%59 = load i32, i32* %7
%60 = call i32 @magic_numbers_aux(i8* %53, i64 %58, i32 %59)
store i32 %60, i32* %4
br label %92
61: ; preds = %36
store i32 0, i32* %12
store i32 1, i32* %11
br label %62
62: ; preds = %84, %61
%63 = load i32, i32* %11
%64 = icmp slt i32 %63, 10
br i1 %64, label %65, label %87
65: ; preds = %62
%66 = load i8*, i8** %5
%67 = load i64, i64* %6
%68 = load i32, i32* %11
%69 = load i32, i32* %7
%70 = call i32 @next_result(i8* %66, i64 %67, i32 %68, i32 %69)
store i32 %70, i32* %13
%71 = load i32, i32* %11
%72 = add nsw i32 48, %71
%73 = trunc i32 %72 to i8
%74 = load i8*, i8** %5
%75 = load i64, i64* %6
%76 = getelementptr inbounds i8, i8* %74, i64 %75
store i8 %73, i8* %76
%77 = load i8*, i8** %5
%78 = load i64, i64* %6
%79 = add i64 %78, 2
%80 = load i32, i32* %13
%81 = call i32 @magic_numbers_aux(i8* %77, i64 %79, i32 %80)
%82 = load i32, i32* %12
%83 = add i32 %82, %81
store i32 %83, i32* %12
br label %84
84: ; preds = %65
%85 = load i32, i32* %11
%86 = add nsw i32 %85, 1
store i32 %86, i32* %11
br label %62
87: ; preds = %62
%88 = load i8*, i8** %5
%89 = load i64, i64* %6
%90 = getelementptr inbounds i8, i8* %88, i64 %89
store i8 95, i8* %90
%91 = load i32, i32* %12
store i32 %91, i32* %4
br label %92
92: ; preds = %87, %43, %35, %32
%93 = load i32, i32* %4
ret i32 %93
}

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