#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 */
char getForward(char, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ scanf(char *, ...);
size_t strlen(char *);
int main() {
  while (1) {
    int n;
    scanf("%d", &n);
    if (!n)
      break;
    char str[41];
    scanf("%s", str);
    size_t len = strlen(str);
    str[len] = '\0';
    char output[41];
    int i;
    for (i = len - 1; i >= 0; i--) {
      output[len - 1 - i] = getForward(str[i], n);
    }
    output[len] = '\0';
    printf("%s\n", output);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1173 <main+0x33>
jmp    1216 <main+0xd6>
lea    -0x40(%rbp),%rsi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
movb   $0x0,-0x40(%rbp,%rax,1)
mov    -0x48(%rbp),%rax
sub    $0x1,%rax
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jl     11f8 <main+0xb8>
movslq -0x84(%rbp),%rax
mov    -0x40(%rbp,%rax,1),%al
mov    -0x8(%rbp),%esi
movsbl %al,%edi
call   1050 <getForward@plt>
mov    %al,%cl
mov    -0x48(%rbp),%rax
sub    $0x1,%rax
movslq -0x84(%rbp),%rdx
sub    %rdx,%rax
mov    %cl,-0x80(%rbp,%rax,1)
mov    -0x84(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x84(%rbp)
jmp    11a9 <main+0x69>
mov    -0x48(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rsi
lea    0xdfa(%rip),%rdi
call   1040 <printf@plt>
jmp    1152 <main+0x12>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
lea    0xeab(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
je     1220 <main+0xe0>
lea    0x40(%rsp),%rbx
lea    0xc(%rsp),%rbp
jmp    11af <main+0x6f>
nopl   0x0(%rax,%rax,1)
movb   $0x0,0x10(%rsp,%r14,1)
lea    0xe79(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <printf@plt>
lea    0xe62(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
je     1220 <main+0xe0>
lea    0xe4d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%r14
movb   $0x0,0x40(%rsp,%rax,1)
add    $0xffffffffffffffff,%rax
test   $0x80000000,%eax
jne    1180 <main+0x40>
mov    %eax,%r15d
lea    (%rsp,%r14,1),%r12
add    $0x10,%r12
lea    (%rsp,%r15,1),%r13
add    $0x40,%r13
not    %r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl 0x0(%r13),%edi
mov    0xc(%rsp),%esi
call   1050 <getForward@plt>
mov    %al,(%r12,%r15,1)
add    $0xffffffffffffffff,%r13
inc    %r15
jne    1200 <main+0xc0>
jmp    1180 <main+0x40>
xor    %eax,%eax
add    $0x78,%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 = [3 x i8] c"%s\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [41 x i8]
%4 = alloca i64
%5 = alloca [41 x i8]
%6 = alloca i32
store i32 0, i32* %1
br label %7
7: ; preds = %0, %41
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %7
br label %46
12: ; preds = %7
%13 = getelementptr inbounds [41 x i8], [41 x i8]* %3, i64 0, i64 0
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [41 x i8], [41 x i8]* %3, i64 0, i64 0
%16 = call i64 @strlen(i8* %15)
store i64 %16, i64* %4
%17 = load i64, i64* %4
%18 = getelementptr inbounds [41 x i8], [41 x i8]* %3, i64 0, i64 %17
store i8 0, i8* %18
%19 = load i64, i64* %4
%20 = sub i64 %19, 1
%21 = trunc i64 %20 to i32
store i32 %21, i32* %6
br label %22
22: ; preds = %38, %12
%23 = load i32, i32* %6
%24 = icmp sge i32 %23, 0
br i1 %24, label %25, label %41
25: ; preds = %22
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [41 x i8], [41 x i8]* %3, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = load i32, i32* %2
%31 = call signext i8 @getForward(i8 signext %29, i32 %30)
%32 = load i64, i64* %4
%33 = sub i64 %32, 1
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = sub i64 %33, %35
%37 = getelementptr inbounds [41 x i8], [41 x i8]* %5, i64 0, i64 %36
store i8 %31, i8* %37
br label %38
38: ; preds = %25
%39 = load i32, i32* %6
%40 = add nsw i32 %39, -1
store i32 %40, i32* %6
br label %22
41: ; preds = %22
%42 = load i64, i64* %4
%43 = getelementptr inbounds [41 x i8], [41 x i8]* %5, i64 0, i64 %42
store i8 0, i8* %43
%44 = getelementptr inbounds [41 x i8], [41 x i8]* %5, i64 0, i64 0
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %44)
br label %7
46: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [41 x i8]
%3 = alloca [41 x i8]
%4 = bitcast i32* %1 to i8*
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp eq i32 %6, 0
br i1 %7, label %36, label %8
8: ; preds = %0
%9 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%10 = getelementptr inbounds [41 x i8], [41 x i8]* %3, i64 0, i64 0
br label %11
11: ; preds = %8, %30
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%13 = call i64 @strlen(i8* %9)
%14 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 %13
store i8 0, i8* %14
%15 = add i64 %13, -1
%16 = and i64 %15, 2147483648
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %30
18: ; preds = %11
%19 = and i64 %15, 4294967295
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ %19, %18 ], [ %28, %20 ]
%22 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = load i32, i32* %1
%25 = call signext i8 @getForward(i8 signext %23, i32 %24)
%26 = sub i64 %15, %21
%27 = getelementptr inbounds [41 x i8], [41 x i8]* %3, i64 0, i64 %26
store i8 %25, i8* %27
%28 = add nsw i64 %21, -1
%29 = icmp eq i64 %21, 0
br i1 %29, label %30, label %20
30: ; preds = %20, %11
%31 = getelementptr inbounds [41 x i8], [41 x i8]* %3, i64 0, i64 %13
store i8 0, i8* %31
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%33 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%34 = load i32, i32* %1
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %11
36: ; preds = %30, %0
ret i32 0
}