#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ sscanf(char *, char *, char *, int *);
int strlen(char *);
int main() {
  FILE *fp;
  char filename[1050], temp[2060], c, string[1050][130];
  int i = 0, N, sum = 0, j, length, k = 0;
  char *ptr;
  scanf("%s", filename);
  fp = fopen(filename, "r");
  assert(fp != NULL);
  while ((fgets(temp, 2048, fp)) != NULL) {
    ptr = temp;
    k = 0;
    for (i = 0; sscanf(ptr + k, "%s %n", string[i], &length) != EOF;
         k += length) {
      if (isdigit(string[i][0])) {
        for (j = 0; j < strlen(string[i]); j++) {
          sum = sum * 10 + string[i][j] - '0';
        }
        printf("%s", string[sum]);
        sum = 0;
      } else {
        printf("%s", string[i]);
        i++;
      }
      printf(" ");
    }
    N = i;
    for (i = 0; i < N; i++) {
    }
    printf("\n");
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x221b0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x22184(%rbp)
movl   $0x0,-0x2218c(%rbp)
movl   $0x0,-0x22198(%rbp)
lea    -0x430(%rbp),%rsi
lea    0xe32(%rip),%rdi
call   10a0 <scanf@plt>
lea    -0x430(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0xc40(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x800,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1422 <main+0x292>
lea    -0xc40(%rbp),%rax
mov    %rax,-0x221a0(%rbp)
movl   $0x0,-0x22198(%rbp)
movl   $0x0,-0x22184(%rbp)
mov    -0x221a0(%rbp),%rdi
movslq -0x22198(%rbp),%rax
add    %rax,%rdi
movslq -0x22184(%rbp),%rax
lea    -0x22180(%rbp),%rdx
imul   $0x82,%rax,%rax
add    %rax,%rdx
lea    0xd98(%rip),%rsi
lea    -0x22194(%rbp),%rcx
call   1090 <sscanf@plt>
mov    0x2d68(%rip),%rcx
cmp    (%rcx),%rax
je     13ce <main+0x23e>
movslq -0x22184(%rbp),%rcx
lea    -0x22180(%rbp),%rax
imul   $0x82,%rcx,%rcx
add    %rcx,%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1374 <main+0x1e4>
movl   $0x0,-0x22190(%rbp)
mov    -0x22190(%rbp),%eax
mov    %eax,-0x221a4(%rbp)
movslq -0x22184(%rbp),%rax
lea    -0x22180(%rbp),%rdi
imul   $0x82,%rax,%rax
add    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x221a4(%rbp),%eax
cmp    %ecx,%eax
jge    133f <main+0x1af>
imul   $0xa,-0x2218c(%rbp),%eax
movslq -0x22184(%rbp),%rdx
lea    -0x22180(%rbp),%rcx
imul   $0x82,%rdx,%rdx
add    %rdx,%rcx
movslq -0x22190(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0x2218c(%rbp)
mov    -0x22190(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x22190(%rbp)
jmp    12bd <main+0x12d>
movslq -0x2218c(%rbp),%rax
lea    -0x22180(%rbp),%rsi
imul   $0x82,%rax,%rax
add    %rax,%rsi
lea    0xca2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x2218c(%rbp)
jmp    13a9 <main+0x219>
movslq -0x22184(%rbp),%rax
lea    -0x22180(%rbp),%rsi
imul   $0x82,%rax,%rax
add    %rax,%rsi
lea    0xc6d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x22184(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x22184(%rbp)
lea    0xc5b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x22194(%rbp),%eax
add    -0x22198(%rbp),%eax
mov    %eax,-0x22198(%rbp)
jmp    123d <main+0xad>
mov    -0x22184(%rbp),%eax
mov    %eax,-0x22188(%rbp)
movl   $0x0,-0x22184(%rbp)
mov    -0x22184(%rbp),%eax
cmp    -0x22188(%rbp),%eax
jge    140f <main+0x27f>
jmp    13fb <main+0x26b>
mov    -0x22184(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x22184(%rbp)
jmp    13e4 <main+0x254>
lea    0xbf7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    11fc <main+0x6c>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x221b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x22178,%rsp
lea    0xe48(%rip),%rdi
lea    0x820(%rsp),%rbx
mov    %rbx,%rsi
call   10b0 <scanf@plt>
lea    0xe34(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1090 <assert@plt>
lea    0x10(%rsp),%rdi
mov    $0x800,%esi
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     138e <main+0x1ee>
lea    0x10(%rsp),%rbx
jmp    123a <main+0x9a>
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x800,%esi
mov    0x8(%rsp),%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     138e <main+0x1ee>
mov    %rbx,%rdi
lea    0xdc1(%rip),%rsi
lea    0xc40(%rsp),%rdx
lea    0x4(%rsp),%rcx
call   10a0 <sscanf@plt>
mov    0x2d8b(%rip),%rcx
cmp    (%rcx),%rax
je     1210 <main+0x70>
xor    %r13d,%r13d
lea    0xc40(%rsp),%r12
xor    %r14d,%r14d
xor    %r15d,%r15d
jmp    12ef <main+0x14f>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xd79(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%r15d
mov    $0x20,%edi
call   1030 <putchar@plt>
movslq 0x4(%rsp),%rax
movslq %r14d,%r14
add    %rax,%r14
lea    (%rsp,%r14,1),%rdi
add    $0x10,%rdi
movslq %r15d,%r13
mov    %r13,%rax
shl    $0x7,%rax
lea    (%rax,%r13,2),%rax
lea    (%rsp,%rax,1),%r12
add    $0xc40,%r12
lea    0xd33(%rip),%rsi
mov    %r12,%rdx
lea    0x4(%rsp),%rcx
call   10a0 <sscanf@plt>
mov    0x2d02(%rip),%rcx
cmp    (%rcx),%rax
je     1210 <main+0x70>
movsbl (%r12),%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     1280 <main+0xe0>
mov    %r12,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    1360 <main+0x1c0>
mov    %r13,%rax
shl    $0x7,%rax
lea    (%rax,%r13,2),%rax
lea    (%rsp,%rax,1),%r13
add    $0xc40,%r13
xor    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%rbx,%rbx,4),%eax
movsbl 0x0(%r13,%rbp,1),%ecx
lea    (%rcx,%rax,2),%ebx
add    $0xffffffd0,%ebx
add    $0x1,%rbp
mov    %r12,%rdi
call   1060 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1330 <main+0x190>
jmp    1362 <main+0x1c2>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ebx,%ebx
movslq %ebx,%rax
mov    %rax,%rcx
shl    $0x7,%rcx
lea    (%rcx,%rax,2),%rax
lea    (%rsp,%rax,1),%rsi
add    $0xc40,%rsi
lea    0xc7e(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1295 <main+0xf5>
mov    0x8(%rsp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x22178,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%s %n\00"
@EOF = global i64 0
@.str.3 = [2 x i8] c" \00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [1050 x i8]
%4 = alloca [2060 x i8]
%5 = alloca i8
%6 = alloca [1050 x [130 x i8]]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %7
store i32 0, i32* %9
store i32 0, i32* %12
%14 = getelementptr inbounds [1050 x i8], [1050 x i8]* %3, i64 0, i64 0
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = getelementptr inbounds [1050 x i8], [1050 x i8]* %3, i64 0, i64 0
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %2
%18 = load i32*, i32** %2
%19 = icmp ne i32* %18, null
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
br label %22
22: ; preds = %104, %0
%23 = getelementptr inbounds [2060 x i8], [2060 x i8]* %4, i64 0, i64 0
%24 = load i32*, i32** %2
%25 = call i32* @fgets(i8* %23, i32 2048, i32* %24)
%26 = icmp ne i32* %25, null
br i1 %26, label %27, label %106
27: ; preds = %22
%28 = getelementptr inbounds [2060 x i8], [2060 x i8]* %4, i64 0, i64 0
store i8* %28, i8** %13
store i32 0, i32* %12
store i32 0, i32* %7
br label %29
29: ; preds = %90, %27
%30 = load i8*, i8** %13
%31 = load i32, i32* %12
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [1050 x [130 x i8]], [1050 x [130 x i8]]* %6, i64 0, i64 %35
%37 = getelementptr inbounds [130 x i8], [130 x i8]* %36, i64 0, i64 0
%38 = call i64 @sscanf(i8* %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %37, i32* %11)
%39 = load i64, i64* @EOF
%40 = icmp ne i64 %38, %39
br i1 %40, label %41, label %94
41: ; preds = %29
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [1050 x [130 x i8]], [1050 x [130 x i8]]* %6, i64 0, i64 %43
%45 = getelementptr inbounds [130 x i8], [130 x i8]* %44, i64 0, i64 0
%46 = load i8, i8* %45
%47 = call i64 @isdigit(i8 signext %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %80
49: ; preds = %41
store i32 0, i32* %10
br label %50
50: ; preds = %71, %49
%51 = load i32, i32* %10
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [1050 x [130 x i8]], [1050 x [130 x i8]]* %6, i64 0, i64 %53
%55 = getelementptr inbounds [130 x i8], [130 x i8]* %54, i64 0, i64 0
%56 = call i32 @strlen(i8* %55)
%57 = icmp slt i32 %51, %56
br i1 %57, label %58, label %74
58: ; preds = %50
%59 = load i32, i32* %9
%60 = mul nsw i32 %59, 10
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [1050 x [130 x i8]], [1050 x [130 x i8]]* %6, i64 0, i64 %62
%64 = load i32, i32* %10
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [130 x i8], [130 x i8]* %63, i64 0, i64 %65
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = add nsw i32 %60, %68
%70 = sub nsw i32 %69, 48
store i32 %70, i32* %9
br label %71
71: ; preds = %58
%72 = load i32, i32* %10
%73 = add nsw i32 %72, 1
store i32 %73, i32* %10
br label %50
74: ; preds = %50
%75 = load i32, i32* %9
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [1050 x [130 x i8]], [1050 x [130 x i8]]* %6, i64 0, i64 %76
%78 = getelementptr inbounds [130 x i8], [130 x i8]* %77, i64 0, i64 0
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %78)
store i32 0, i32* %9
br label %88
80: ; preds = %41
%81 = load i32, i32* %7
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [1050 x [130 x i8]], [1050 x [130 x i8]]* %6, i64 0, i64 %82
%84 = getelementptr inbounds [130 x i8], [130 x i8]* %83, i64 0, i64 0
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %84)
%86 = load i32, i32* %7
%87 = add nsw i32 %86, 1
store i32 %87, i32* %7
br label %88
88: ; preds = %80, %74
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %90
90: ; preds = %88
%91 = load i32, i32* %11
%92 = load i32, i32* %12
%93 = add nsw i32 %92, %91
store i32 %93, i32* %12
br label %29
94: ; preds = %29
%95 = load i32, i32* %7
store i32 %95, i32* %8
store i32 0, i32* %7
br label %96
96: ; preds = %101, %94
%97 = load i32, i32* %7
%98 = load i32, i32* %8
%99 = icmp slt i32 %97, %98
br i1 %99, label %100, label %104
100: ; preds = %96
br label %101
101: ; preds = %100
%102 = load i32, i32* %7
%103 = add nsw i32 %102, 1
store i32 %103, i32* %7
br label %96
104: ; preds = %96
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %22
106: ; preds = %22
%107 = load i32*, i32** %2
%108 = call i32 @fclose(i32* %107)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%s %n\00"
@EOF = global i64 0
define i32 @main() {
%1 = alloca [1050 x i8]
%2 = alloca [2060 x i8]
%3 = alloca [1050 x [130 x i8]]
%4 = alloca i32
%5 = getelementptr inbounds [1050 x i8], [1050 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [2060 x i8], [2060 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [1050 x [130 x i8]], [1050 x [130 x i8]]* %3, i64 0, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%10 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp ne i32* %10, null
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = call i32* @fgets(i8* %6, i32 2048, i32* %10)
%15 = icmp eq i32* %14, null
br i1 %15, label %68, label %16
16: ; preds = %0, %20
%17 = call i64 @sscanf(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %7, i32* %4)
%18 = load i64, i64* @EOF
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %56, %16
%21 = call i32 @putchar(i32 10)
%22 = call i32* @fgets(i8* %6, i32 2048, i32* %10)
%23 = icmp eq i32* %22, null
br i1 %23, label %68, label %16
24: ; preds = %16, %56
%25 = phi i8* [ %64, %56 ], [ %7, %16 ]
%26 = phi i64 [ %63, %56 ], [ 0, %16 ]
%27 = phi i32 [ %60, %56 ], [ 0, %16 ]
%28 = phi i32 [ %57, %56 ], [ 0, %16 ]
%29 = load i8, i8* %25
%30 = call i64 @isdigit(i8 signext %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %53, label %32
32: ; preds = %24
%33 = call i32 @strlen(i8* %25)
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %48
35: ; preds = %32, %35
%36 = phi i64 [ %44, %35 ], [ 0, %32 ]
%37 = phi i32 [ %43, %35 ], [ 0, %32 ]
%38 = mul nsw i32 %37, 10
%39 = getelementptr inbounds [1050 x [130 x i8]], [1050 x [130 x i8]]* %3, i64 0, i64 %26, i64 %36
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = add i32 %38, -48
%43 = add i32 %42, %41
%44 = add nuw nsw i64 %36, 1
%45 = call i32 @strlen(i8* %25)
%46 = sext i32 %45 to i64
%47 = icmp slt i64 %44, %46
br i1 %47, label %35, label %48
48: ; preds = %35, %32
%49 = phi i32 [ 0, %32 ], [ %43, %35 ]
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [1050 x [130 x i8]], [1050 x [130 x i8]]* %3, i64 0, i64 %50, i64 0
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %51)
br label %56
53: ; preds = %24
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %25)
%55 = add nsw i32 %28, 1
br label %56
56: ; preds = %53, %48
%57 = phi i32 [ %28, %48 ], [ %55, %53 ]
%58 = call i32 @putchar(i32 32)
%59 = load i32, i32* %4
%60 = add nsw i32 %59, %27
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [2060 x i8], [2060 x i8]* %2, i64 0, i64 %61
%63 = sext i32 %57 to i64
%64 = getelementptr inbounds [1050 x [130 x i8]], [1050 x [130 x i8]]* %3, i64 0, i64 %63, i64 0
%65 = call i64 @sscanf(i8* %62, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %64, i32* %4)
%66 = load i64, i64* @EOF
%67 = icmp eq i64 %65, %66
br i1 %67, label %20, label %24
68: ; preds = %20, %0
%69 = call i32 @fclose(i32* %10)
ret i32 0
}