#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*/ naive_printf(char *, int);
int naive_scanf(char *, ...);
int solve(char *, char *, int, int);
int strlen(char *);
int program_main() {
  char s1[26 + 1], s2[26 + 1];
  int m, k;
  int ans;
  while (naive_scanf("%d", &m) == 1 && m) {
    naive_scanf("%s%s", s1, s2);
    k = strlen(s1);
    ans = solve(s1, s2, k, m);
    naive_printf("%d\n", ans);
  }
  return 0;
}


x86 assembly (clang, -O0):
<program_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    0xeb1(%rip),%rdi
lea    -0x44(%rbp),%rsi
mov    $0x0,%al
call   1050 <naive_scanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x4d(%rbp)
jne    1174 <program_main+0x34>
cmpl   $0x0,-0x44(%rbp)
setne  %al
mov    %al,-0x4d(%rbp)
mov    -0x4d(%rbp),%al
test   $0x1,%al
jne    1184 <program_main+0x44>
jmp    11d0 <program_main+0x90>
lea    -0x20(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1050 <naive_scanf@plt>
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x48(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%edx
mov    -0x44(%rbp),%ecx
call   1030 <solve@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%esi
lea    0xe42(%rip),%rdi
call   1060 <naive_printf@plt>
jmp    1148 <program_main+0x8>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<program_main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xeab(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <naive_scanf@plt>
cmp    $0x1,%eax
jne    11ec <program_main+0xac>
cmpl   $0x0,0xc(%rsp)
je     11ec <program_main+0xac>
lea    0xe8b(%rip),%r14
lea    0x30(%rsp),%rbx
lea    0x10(%rsp),%r15
lea    0xe7f(%rip),%r12
lea    0xe70(%rip),%r13
lea    0xc(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <naive_scanf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    0xc(%rsp),%ecx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <solve@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   1060 <naive_printf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <naive_scanf@plt>
cmp    $0x1,%eax
jne    11ec <program_main+0xac>
cmpl   $0x0,0xc(%rsp)
jne    11a0 <program_main+0x60>
xor    %eax,%eax
add    $0x58,%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 = [5 x i8] c"%s%s\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @program_main() {
%1 = alloca [27 x i8]
%2 = alloca [27 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
br label %6
6: ; preds = %14, %0
%7 = call i32 (i8*, ...) @naive_scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 0
br label %12
12: ; preds = %9, %6
%13 = phi i1 [ false, %6 ], [ %11, %9 ]
br i1 %13, label %14, label %27
14: ; preds = %12
%15 = getelementptr inbounds [27 x i8], [27 x i8]* %1, i64 0, i64 0
%16 = getelementptr inbounds [27 x i8], [27 x i8]* %2, i64 0, i64 0
%17 = call i32 (i8*, ...) @naive_scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %16)
%18 = getelementptr inbounds [27 x i8], [27 x i8]* %1, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %4
%20 = getelementptr inbounds [27 x i8], [27 x i8]* %1, i64 0, i64 0
%21 = getelementptr inbounds [27 x i8], [27 x i8]* %2, i64 0, i64 0
%22 = load i32, i32* %4
%23 = load i32, i32* %3
%24 = call i32 @solve(i8* %20, i8* %21, i32 %22, i32 %23)
store i32 %24, i32* %5
%25 = load i32, i32* %5
%26 = call i32 @naive_printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %6
27: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"%s%s\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @program_main() {
%1 = alloca [27 x i8]
%2 = alloca [27 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [27 x i8], [27 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [27 x i8], [27 x i8]* %2, i64 0, i64 0
%6 = bitcast i32* %3 to i8*
%7 = call i32 (i8*, ...) @naive_scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = icmp eq i32 %7, 1
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 0
%11 = select i1 %8, i1 %10, i1 false
br i1 %11, label %12, label %23
12: ; preds = %0, %12
%13 = call i32 (i8*, ...) @naive_scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %5)
%14 = call i32 @strlen(i8* %4)
%15 = load i32, i32* %3
%16 = call i32 @solve(i8* %4, i8* %5, i32 %14, i32 %15)
%17 = call i32 @naive_printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = call i32 (i8*, ...) @naive_scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%19 = icmp eq i32 %18, 1
%20 = load i32, i32* %3
%21 = icmp ne i32 %20, 0
%22 = select i1 %19, i1 %21, i1 false
br i1 %22, label %12, label %23
23: ; preds = %12, %0
ret i32 0
}