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

/* Variables and functions */
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, char *, int *);
int main() {
  char line[20];
  signed int posx = 0;
  signed int posy = 0;
  signed int xincr = 0;
  signed int yincr = 1;
  signed int txincr = 0;
  signed int tyincr = 0;
  signed int steps = 0;
  char dummy[20];
  FILE *fd = fopen("coordinates_input.txt", "r");
  while (!feof(fd)) {
    fgets(line, sizeof(line), fd);
    printf("%s", line);
    if (line[0] == 'M') {
      sscanf(line, "%s %d", dummy, &steps);
      posx += xincr * steps;
      posy += yincr * steps;
    } else if (line[0] == 'T') {
      txincr = xincr;
      tyincr = yincr;
      if (line[5] == 'r') {
        if (yincr) {
          xincr = yincr;
          yincr = 0;
        } else if (xincr) {
          yincr = 0 - xincr;
          xincr = 0;
        }
      }
      if (line[5] == 'l') {
        if (yincr) {
          xincr = 0 - yincr;
          yincr = 0;
        } else if (xincr) {
          yincr = xincr;
          xincr = 0;
        }
      }
    }
  }
  printf("%d,%d\n", posx, posy);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
lea    0xe69(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11c5 <main+0x75>
jmp    12ed <main+0x19d>
lea    -0x20(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    $0x14,%esi
call   1040 <fgets@plt>
lea    -0x20(%rbp),%rsi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x20(%rbp),%eax
cmp    $0x4d,%eax
jne    122d <main+0xdd>
lea    -0x20(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe16(%rip),%rsi
lea    -0x3c(%rbp),%rcx
call   1060 <sscanf@plt>
mov    -0x2c(%rbp),%eax
imul   -0x3c(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%eax
imul   -0x3c(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    12e8 <main+0x198>
movsbl -0x20(%rbp),%eax
cmp    $0x54,%eax
jne    12e3 <main+0x193>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x38(%rbp)
movsbl -0x1b(%rbp),%eax
cmp    $0x72,%eax
jne    1292 <main+0x142>
cmpl   $0x0,-0x30(%rbp)
je     126f <main+0x11f>
mov    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
jmp    128d <main+0x13d>
cmpl   $0x0,-0x2c(%rbp)
je     1288 <main+0x138>
xor    %eax,%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
jmp    128d <main+0x13d>
jmp    1292 <main+0x142>
movsbl -0x1b(%rbp),%eax
cmp    $0x6c,%eax
jne    12de <main+0x18e>
cmpl   $0x0,-0x30(%rbp)
je     12bd <main+0x16d>
xor    %eax,%eax
sub    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
jmp    12d9 <main+0x189>
cmpl   $0x0,-0x2c(%rbp)
je     12d4 <main+0x184>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
jmp    12d9 <main+0x189>
jmp    12de <main+0x18e>
jmp    12e3 <main+0x193>
jmp    12e8 <main+0x198>
jmp    11a7 <main+0x57>
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xd27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movl   $0x0,0xc(%rsp)
lea    0xe93(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <feof@plt>
xor    %r14d,%r14d
mov    $0x0,%r15d
test   %eax,%eax
je     11b6 <main+0x66>
lea    0xe89(%rip),%rdi
mov    %r15d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r12d
lea    0x10(%rsp),%rbp
xor    %r15d,%r15d
xor    %r13d,%r13d
xor    %r14d,%r14d
jmp    11ec <main+0x9c>
neg    %r12d
mov    %r13d,%eax
mov    $0x0,%ecx
cmovb  %ecx,%eax
mov    %r12d,%r13d
mov    %eax,%r12d
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    1191 <main+0x41>
mov    %rbp,%rdi
mov    $0x14,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
lea    0xe15(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl 0x10(%rsp),%eax
cmp    $0x54,%al
je     1250 <main+0x100>
cmp    $0x4d,%al
jne    11e0 <main+0x90>
mov    %rbp,%rdi
lea    0xdf7(%rip),%rsi
lea    0x30(%rsp),%rdx
lea    0xc(%rsp),%rcx
call   1060 <sscanf@plt>
mov    0xc(%rsp),%eax
mov    %eax,%ecx
imul   %r13d,%ecx
add    %ecx,%r15d
imul   %r12d,%eax
add    %eax,%r14d
jmp    11e0 <main+0x90>
nopl   0x0(%rax)
movzbl 0x15(%rsp),%eax
cmp    $0x6c,%al
je     11cc <main+0x7c>
cmp    $0x72,%al
jne    11e0 <main+0x90>
neg    %r13d
test   %r12d,%r12d
mov    %r13d,%eax
mov    $0x0,%ecx
cmovne %ecx,%eax
jmp    11da <main+0x8a>

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

LLVM IR (-O2):
@.str = [22 x i8] c"coordinates_input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [6 x i8] c"%s %d\00"
@.str.4 = [7 x i8] c"%d,%d\0A\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = alloca i32
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @feof(i32* %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %44
10: ; preds = %0
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 5
br label %12
12: ; preds = %10, %37
%13 = phi i32 [ 0, %10 ], [ %41, %37 ]
%14 = phi i32 [ 1, %10 ], [ %40, %37 ]
%15 = phi i32 [ 0, %10 ], [ %39, %37 ]
%16 = phi i32 [ 0, %10 ], [ %38, %37 ]
%17 = call i32 @fgets(i8* %4, i32 20, i32* %7)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%19 = load i8, i8* %4
switch i8 %19, label %37 [
i8 77, label %20
i8 84, label %27
]
20: ; preds = %12
%21 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %6, i32* %2)
%22 = load i32, i32* %2
%23 = mul nsw i32 %22, %15
%24 = add nsw i32 %23, %13
%25 = mul nsw i32 %22, %14
%26 = add nsw i32 %25, %16
br label %37
27: ; preds = %12
%28 = load i8, i8* %11
switch i8 %28, label %37 [
i8 114, label %29
i8 108, label %33
]
29: ; preds = %27
%30 = icmp eq i32 %14, 0
%31 = sub nsw i32 0, %15
%32 = select i1 %30, i32 %31, i32 0
br label %37
33: ; preds = %27
%34 = icmp eq i32 %14, 0
%35 = sub nsw i32 0, %14
%36 = select i1 %34, i32 %15, i32 0
br label %37
37: ; preds = %33, %29, %27, %12, %20
%38 = phi i32 [ %26, %20 ], [ %16, %12 ], [ %16, %27 ], [ %16, %29 ], [ %16, %33 ]
%39 = phi i32 [ %15, %20 ], [ %15, %12 ], [ %15, %27 ], [ %14, %29 ], [ %35, %33 ]
%40 = phi i32 [ %14, %20 ], [ %14, %12 ], [ %14, %27 ], [ %32, %29 ], [ %36, %33 ]
%41 = phi i32 [ %24, %20 ], [ %13, %12 ], [ %13, %27 ], [ %13, %29 ], [ %13, %33 ]
%42 = call i32 @feof(i32* %7)
%43 = icmp eq i32 %42, 0
br i1 %43, label %12, label %44
44: ; preds = %37, %0
%45 = phi i32 [ 0, %0 ], [ %38, %37 ]
%46 = phi i32 [ 0, %0 ], [ %41, %37 ]
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %46, i32 %45)
ret i32 0
}