#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 */
char EOF;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, unsigned int *);
char getc(int /*<<< orphan*/ *);
char *malloc(unsigned int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putchar(char);
char *realloc(char *, unsigned int);
int main(int argc, char *argv[]) {
  FILE *fp;
  unsigned sbs = 32, a, n = 0;
  char c;
  char *sb = malloc(sbs);
  if (argc != 2) {
    printf("Usage: %s [FILE]\n", argv[0]);
    return 1;
  }
  fp = fopen(*++argv, "r");
  while ((c = getc(fp)) != EOF) {
    if (c == '|') {
      while ((c = getc(fp)) == ' ') {
        fscanf(fp, "%u", &a);
        putchar(sb[a - 1]);
      }
      putchar('\n');
      n = 0;
    } else if (c != '\n') {
      if (n == sbs) {
        sbs += sbs / 2;
        sb = realloc(sb, sbs);
      }
      sb[n++] = c;
    }
  }
  free(sb);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x20,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d9 <main+0x59>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe38(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f1 <main+0x171>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xe1f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <getc@plt>
mov    %al,-0x25(%rbp)
movsbl %al,%eax
mov    0x2dd6(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12e1 <main+0x161>
movsbl -0x25(%rbp),%eax
cmp    $0x7c,%eax
jne    128b <main+0x10b>
jmp    122f <main+0xaf>
mov    -0x18(%rbp),%rdi
call   10a0 <getc@plt>
mov    %al,-0x25(%rbp)
movsbl %al,%eax
cmp    $0x20,%eax
jne    1275 <main+0xf5>
mov    -0x18(%rbp),%rdi
lea    0xdc2(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <fscanf@plt>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%edi
call   1040 <putchar@plt>
jmp    122f <main+0xaf>
mov    $0xa,%edi
call   1040 <putchar@plt>
movl   $0x0,-0x24(%rbp)
jmp    12dc <main+0x15c>
movsbl -0x25(%rbp),%eax
cmp    $0xa,%eax
je     12d7 <main+0x157>
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    12c0 <main+0x140>
mov    -0x1c(%rbp),%eax
shr    $0x1,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <realloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x25(%rbp),%dl
mov    -0x30(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
jmp    12dc <main+0x15c>
jmp    11fc <main+0x7c>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x20,%edi
call   1070 <malloc@plt>
cmp    $0x2,%ebp
jne    11d8 <main+0x58>
mov    %rax,%r14
mov    0x8(%rbx),%rdi
lea    0xe65(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <getc@plt>
mov    %eax,%r13d
mov    0x2e21(%rip),%rax
cmp    (%rax),%r13b
jne    11fb <main+0x7b>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11ec <main+0x6c>
mov    (%rbx),%rsi
lea    0xe1e(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x20,%eax
xor    %r15d,%r15d
lea    0xe0a(%rip),%r12
lea    0x4(%rsp),%rbp
jmp    1247 <main+0xc7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %r15d,%r15d
mov    %rbx,%rdi
call   10a0 <getc@plt>
mov    %eax,%r13d
mov    0x2da9(%rip),%rax
cmp    (%rax),%r13b
mov    (%rsp),%eax
je     11cc <main+0x4c>
cmp    $0xa,%r13b
je     1290 <main+0x110>
cmp    $0x7c,%r13b
jne    12a0 <main+0x120>
mov    %eax,(%rsp)
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10a0 <getc@plt>
cmp    $0x20,%al
jne    1220 <main+0xa0>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1060 <fscanf@plt>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
movsbl (%r14,%rax,1),%edi
call   1040 <putchar@plt>
jmp    1260 <main+0xe0>
nopl   (%rax)
mov    %eax,(%rsp)
jmp    122d <main+0xad>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    %eax,%r15d
jne    12bd <main+0x13d>
mov    %r15d,%esi
shr    %esi
add    %r15d,%esi
mov    %r14,%rdi
mov    %esi,(%rsp)
call   1080 <realloc@plt>
mov    %rax,%r14
jmp    12c0 <main+0x140>
mov    %eax,(%rsp)
mov    %r15d,%eax
add    $0x1,%r15d
mov    %r13b,(%r14,%rax,1)
jmp    122d <main+0xad>

LLVM IR (-O0):
@.str = [18 x i8] c"Usage: %s [FILE]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.2 = [3 x i8] c"%u\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 32, i32* %7
store i32 0, i32* %9
%12 = load i32, i32* %7
%13 = call i8* @malloc(i32 %12)
store i8* %13, i8** %11
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 1, i32* %3
br label %83
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i32 1
store i8** %23, i8*** %5
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %6
br label %26
26: ; preds = %79, %21
%27 = load i32*, i32** %6
%28 = call signext i8 @getc(i32* %27)
store i8 %28, i8* %10
%29 = sext i8 %28 to i32
%30 = load i8, i8* @EOF
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %29, %31
br i1 %32, label %33, label %80
33: ; preds = %26
%34 = load i8, i8* %10
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 124
br i1 %36, label %37, label %55
37: ; preds = %33
br label %38
38: ; preds = %43, %37
%39 = load i32*, i32** %6
%40 = call signext i8 @getc(i32* %39)
store i8 %40, i8* %10
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 32
br i1 %42, label %43, label %53
43: ; preds = %38
%44 = load i32*, i32** %6
%45 = call i32 @fscanf(i32* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%46 = load i8*, i8** %11
%47 = load i32, i32* %8
%48 = sub i32 %47, 1
%49 = zext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %46, i64 %49
%51 = load i8, i8* %50
%52 = call i32 @putchar(i8 signext %51)
br label %38
53: ; preds = %38
%54 = call i32 @putchar(i8 signext 10)
store i32 0, i32* %9
br label %79
55: ; preds = %33
%56 = load i8, i8* %10
%57 = sext i8 %56 to i32
%58 = icmp ne i32 %57, 10
br i1 %58, label %59, label %78
59: ; preds = %55
%60 = load i32, i32* %9
%61 = load i32, i32* %7
%62 = icmp eq i32 %60, %61
br i1 %62, label %63, label %71
63: ; preds = %59
%64 = load i32, i32* %7
%65 = udiv i32 %64, 2
%66 = load i32, i32* %7
%67 = add i32 %66, %65
store i32 %67, i32* %7
%68 = load i8*, i8** %11
%69 = load i32, i32* %7
%70 = call i8* @realloc(i8* %68, i32 %69)
store i8* %70, i8** %11
br label %71
71: ; preds = %63, %59
%72 = load i8, i8* %10
%73 = load i8*, i8** %11
%74 = load i32, i32* %9
%75 = add i32 %74, 1
store i32 %75, i32* %9
%76 = zext i32 %74 to i64
%77 = getelementptr inbounds i8, i8* %73, i64 %76
store i8 %72, i8* %77
br label %78
78: ; preds = %71, %55
br label %79
79: ; preds = %78, %53
br label %26
80: ; preds = %26
%81 = load i8*, i8** %11
%82 = call i32 @free(i8* %81)
store i32 0, i32* %3
br label %83
83: ; preds = %80, %16
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@.str = [18 x i8] c"Usage: %s [FILE]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.2 = [3 x i8] c"%u\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call dereferenceable_or_null(32) i8* @malloc(i32 32)
%6 = icmp eq i32 %0, 2
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %59
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = call signext i8 @getc(i32* %13)
%15 = load i8, i8* @EOF
%16 = icmp eq i8 %14, %15
br i1 %16, label %56, label %17
17: ; preds = %10, %49
%18 = phi i8 [ %53, %49 ], [ %14, %10 ]
%19 = phi i8* [ %52, %49 ], [ %5, %10 ]
%20 = phi i32 [ %51, %49 ], [ 0, %10 ]
%21 = phi i32 [ %50, %49 ], [ 32, %10 ]
switch i8 %18, label %37 [
i8 124, label %22
i8 10, label %49
]
22: ; preds = %17
%23 = call signext i8 @getc(i32* %13)
%24 = icmp eq i8 %23, 32
br i1 %24, label %25, label %35
25: ; preds = %22, %25
%26 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%27 = load i32, i32* %3
%28 = add i32 %27, -1
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %19, i64 %29
%31 = load i8, i8* %30
%32 = call i32 @putchar(i8 signext %31)
%33 = call signext i8 @getc(i32* %13)
%34 = icmp eq i8 %33, 32
br i1 %34, label %25, label %35
35: ; preds = %25, %22
%36 = call i32 @putchar(i8 signext 10)
br label %49
37: ; preds = %17
%38 = icmp eq i32 %20, %21
br i1 %38, label %39, label %43
39: ; preds = %37
%40 = lshr i32 %20, 1
%41 = add i32 %40, %20
%42 = call i8* @realloc(i8* %19, i32 %41)
br label %43
43: ; preds = %39, %37
%44 = phi i32 [ %41, %39 ], [ %21, %37 ]
%45 = phi i8* [ %42, %39 ], [ %19, %37 ]
%46 = add i32 %20, 1
%47 = zext i32 %20 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 %18, i8* %48
br label %49
49: ; preds = %17, %43, %35
%50 = phi i32 [ %21, %35 ], [ %44, %43 ], [ %21, %17 ]
%51 = phi i32 [ 0, %35 ], [ %46, %43 ], [ %20, %17 ]
%52 = phi i8* [ %19, %35 ], [ %45, %43 ], [ %19, %17 ]
%53 = call signext i8 @getc(i32* %13)
%54 = load i8, i8* @EOF
%55 = icmp eq i8 %53, %54
br i1 %55, label %56, label %17
56: ; preds = %49, %10
%57 = phi i8* [ %5, %10 ], [ %52, %49 ]
%58 = call i32 @free(i8* %57)
br label %59
59: ; preds = %56, %7
%60 = phi i32 [ 1, %7 ], [ 0, %56 ]
ret i32 %60
}