#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 abs(int);
int /*<<< orphan*/ printf(char *, int);
int strlen(char *);
void main() {
  char plan[] =
      "R3, L5, R2, L1, L2, R5, L2, R2, L2, L2, L1, R2, L2, R4, R4, R1, L2, L3, "
      "R3, L1, R2, L2, L4, R4, R5, L3, R3, L3, L3, R4, R5, L3, R3, L5, L1, L2, "
      "R2, L1, R3, R1, L1, R187, L1, R2, R47, L5, L1, L2, R4, R3, L3, R3, R4, "
      "R1, R3, L1, L4, L1, R2, L1, R4, R5, L1, R77, L5, L4, R3, L2, R4, R5, "
      "R5, L2, L2, R2, R5, L2, R194, R5, L2, R4, L5, L4, L2, R5, L3, L2, L5, "
      "R5, R2, L3, R3, R1, L4, R2, L1, R5, L1, R5, L1, L1, R3, L1, R5, R2, R5, "
      "R5, L4, L5, L5, L5, R3, L2, L5, L4, R3, R1, R1, R4, L2, L4, R5, R5, R4, "
      "L2, L2, R5, R5, L5, L2, R4, R4, L4, R1, L3, R1, L1, L1, L1, L4, R5, R4, "
      "L4, L4, R5, R3, L2, L2, R3, R1, R4, L3, R1, L4, R3, L3, L2, R2, R2, R2, "
      "L1, L4, R3, R2, R2, L3, R2, L3, L2, R4, L2, R3, L4, R5, R4, R1, R5, R3";
  int azimuth = 0;
  int distances[4] = {0, 0, 0, 0};
  int i = 0;
  do {
    if (plan[i] != 'L' && plan[i] != 'R' && plan[i] != '\0') {
      i++;
      continue;
    }
    if (plan[i] == 'R') {
      azimuth += 1;
    } else {
      azimuth += 3;
    }
    azimuth = azimuth % 4;
    i++;
    int distance = 0;
    while (plan[i] >= '0' && plan[i] <= '9') {
      distance = distance * 10 + plan[i] - '0';
      i++;
    }
    distances[azimuth] += distance;
  } while (i < strlen(plan));
  printf("%d",
         abs(distances[0] - distances[2]) + abs(distances[1] - distances[3]));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x310,%rsp
lea    -0x2d0(%rbp),%rdi
lea    0xe97(%rip),%rsi
mov    $0x2c9,%edx
call   1070 <memcpy@plt>
movl   $0x0,-0x2d4(%rbp)
lea    -0x2f0(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
movl   $0x0,-0x2f4(%rbp)
movslq -0x2f4(%rbp),%rax
movsbl -0x2d0(%rbp,%rax,1),%eax
ff
cmp    $0x4c,%eax
je     11f6 <main+0xa6>
movslq -0x2f4(%rbp),%rax
movsbl -0x2d0(%rbp,%rax,1),%eax
ff
cmp    $0x52,%eax
je     11f6 <main+0xa6>
movslq -0x2f4(%rbp),%rax
movsbl -0x2d0(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     11f6 <main+0xa6>
mov    -0x2f4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2f4(%rbp)
jmp    12fc <main+0x1ac>
movslq -0x2f4(%rbp),%rax
movsbl -0x2d0(%rbp,%rax,1),%eax
ff
cmp    $0x52,%eax
jne    1222 <main+0xd2>
mov    -0x2d4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2d4(%rbp)
jmp    1231 <main+0xe1>
mov    -0x2d4(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x2d4(%rbp)
mov    -0x2d4(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x2d4(%rbp)
mov    -0x2f4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2f4(%rbp)
movl   $0x0,-0x2f8(%rbp)
movslq -0x2f4(%rbp),%rax
movsbl -0x2d0(%rbp,%rax,1),%ecx
ff
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x2f9(%rbp)
jl     1299 <main+0x149>
movslq -0x2f4(%rbp),%rax
movsbl -0x2d0(%rbp,%rax,1),%eax
ff
cmp    $0x39,%eax
setle  %al
mov    %al,-0x2f9(%rbp)
mov    -0x2f9(%rbp),%al
test   $0x1,%al
jne    12ac <main+0x15c>
jmp    12e1 <main+0x191>
imul   $0xa,-0x2f8(%rbp),%eax
movslq -0x2f4(%rbp),%rcx
movsbl -0x2d0(%rbp,%rcx,1),%ecx
ff
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0x2f8(%rbp)
mov    -0x2f4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2f4(%rbp)
jmp    125e <main+0x10e>
mov    -0x2f8(%rbp),%ecx
movslq -0x2d4(%rbp),%rax
add    -0x2f0(%rbp,%rax,4),%ecx
mov    %ecx,-0x2f0(%rbp,%rax,4)
mov    -0x2f4(%rbp),%eax
mov    %eax,-0x300(%rbp)
lea    -0x2d0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x300(%rbp),%eax
cmp    %ecx,%eax
jl     119a <main+0x4a>
mov    -0x2f0(%rbp),%edi
sub    -0x2e8(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x304(%rbp)
mov    -0x2ec(%rbp),%edi
sub    -0x2e4(%rbp),%edi
call   1030 <abs@plt>
mov    -0x304(%rbp),%esi
add    %eax,%esi
lea    0xf6e(%rip),%rdi
call   1050 <printf@plt>
add    $0x310,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2e8,%rsp
lea    0xebb(%rip),%rsi
lea    0x10(%rsp),%r15
mov    $0x2c9,%edx
mov    %r15,%rdi
call   1050 <memcpy@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
xor    %r12d,%r12d
mov    $0x52,%al
lea    0x11(%rsp),%r14
xor    %ebx,%ebx
test   %al,%al
je     1178 <main+0x48>
xchg   %ax,%ax
cmp    $0x4c,%al
je     1178 <main+0x48>
cmp    $0x52,%al
jne    11f0 <main+0xc0>
xor    %ecx,%ecx
cmp    $0x52,%al
setne  %cl
lea    (%r12,%rcx,2),%eax
add    $0x4,%eax
lea    (%r12,%rcx,2),%ecx
add    $0x1,%ecx
test   %ecx,%ecx
cmovns %ecx,%eax
and    $0xfffffffc,%eax
mov    %ecx,%r12d
sub    %eax,%r12d
movslq %ebx,%rbx
mov    0x11(%rsp,%rbx,1),%cl
add    $0x1,%rbx
lea    -0x30(%rcx),%edx
xor    %eax,%eax
cmp    $0x9,%dl
ja     11df <main+0xaf>
mov    %rbx,%rdx
add    %r14,%rdx
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
movzbl %cl,%ecx
lea    (%rax,%rax,4),%eax
lea    (%rcx,%rax,2),%eax
add    $0xffffffd0,%eax
movzbl (%rdx),%ecx
lea    -0x30(%rcx),%esi
add    $0x1,%ebx
add    $0x1,%rdx
cmp    $0xa,%sil
jb     11c0 <main+0x90>
mov    %r12d,%ecx
add    %eax,(%rsp,%rcx,4)
jmp    11f3 <main+0xc3>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
mov    %r15,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebx
jge    1213 <main+0xe3>
movslq %ebx,%rax
mov    0x10(%rsp,%rax,1),%al
test   %al,%al
jne    1170 <main+0x40>
jmp    1178 <main+0x48>
movq   (%rsp),%xmm0
movq   0x8(%rsp),%xmm1
psubd  %xmm1,%xmm0
movdqa %xmm0,%xmm1
psrad  $0x1f,%xmm1
paddd  %xmm1,%xmm0
pxor   %xmm1,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%esi
lea    0x1082(%rip),%rdi
call   1040 <printf@plt>
add    $0x2e8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.plan = [713 x i8] c"R3, L5, R2, L1, L2, R5, L2, R2, L2, L2, L1, R2, L2, R4, R4, R1, L2, L3, R3, L1, R2, L2, L4, R4, R5, L3, R3, L3, L3, R4, R5, L3, R3, L5, L1, L2, R2, L1, R3, R1, L1, R187, L1, R2, R47, L5, L1, L2, R4, R3, L3, R3, R4, R1, R3, L1, L4, L1, R2, L1, R4, R5, L1, R77, L5, L4, R3, L2, R4, R5, R5, L2, L2, R2, R5, L2, R194, R5, L2, R4, L5, L4, L2, R5, L3, L2, L5, R5, R2, L3, R3, R1, L4, R2, L1, R5, L1, R5, L1, L1, R3, L1, R5, R2, R5, R5, L4, L5, L5, L5, R3, L2, L5, L4, R3, R1, R1, R4, L2, L4, R5, R5, R4, L2, L2, R5, R5, L5, L2, R4, R4, L4, R1, L3, R1, L1, L1, L1, L4, R5, R4, L4, L4, R5, R3, L2, L2, R3, R1, R4, L3, R1, L4, R3, L3, L2, R2, R2, R2, L1, L4, R3, R2, R2, L3, R2, L3, L2, R4, L2, R3, L4, R5, R4, R1, R5, R3\00"
@.str = [3 x i8] c"%d\00"
define void @main() {
%1 = alloca [713 x i8]
%2 = alloca i32
%3 = alloca [4 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = bitcast [713 x i8]* %1 to i8*
store i32 0, i32* %2
%7 = bitcast [4 x i32]* %3 to i8*
store i32 0, i32* %4
br label %8
8: ; preds = %85, %0
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [713 x i8], [713 x i8]* %1, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 76
br i1 %14, label %15, label %32
15: ; preds = %8
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [713 x i8], [713 x i8]* %1, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 82
br i1 %21, label %22, label %32
22: ; preds = %15
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [713 x i8], [713 x i8]* %1, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %85
32: ; preds = %22, %15, %8
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [713 x i8], [713 x i8]* %1, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 82
br i1 %38, label %39, label %42
39: ; preds = %32
%40 = load i32, i32* %2
%41 = add nsw i32 %40, 1
store i32 %41, i32* %2
br label %45
42: ; preds = %32
%43 = load i32, i32* %2
%44 = add nsw i32 %43, 3
store i32 %44, i32* %2
br label %45
45: ; preds = %42, %39
%46 = load i32, i32* %2
%47 = srem i32 %46, 4
store i32 %47, i32* %2
%48 = load i32, i32* %4
%49 = add nsw i32 %48, 1
store i32 %49, i32* %4
store i32 0, i32* %5
br label %50
50: ; preds = %66, %45
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [713 x i8], [713 x i8]* %1, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp sge i32 %55, 48
br i1 %56, label %57, label %64
57: ; preds = %50
%58 = load i32, i32* %4
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [713 x i8], [713 x i8]* %1, i64 0, i64 %59
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp sle i32 %62, 57
br label %64
64: ; preds = %57, %50
%65 = phi i1 [ false, %50 ], [ %63, %57 ]
br i1 %65, label %66, label %78
66: ; preds = %64
%67 = load i32, i32* %5
%68 = mul nsw i32 %67, 10
%69 = load i32, i32* %4
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [713 x i8], [713 x i8]* %1, i64 0, i64 %70
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = add nsw i32 %68, %73
%75 = sub nsw i32 %74, 48
store i32 %75, i32* %5
%76 = load i32, i32* %4
%77 = add nsw i32 %76, 1
store i32 %77, i32* %4
br label %50
78: ; preds = %64
%79 = load i32, i32* %5
%80 = load i32, i32* %2
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %81
%83 = load i32, i32* %82
%84 = add nsw i32 %83, %79
store i32 %84, i32* %82
br label %85
85: ; preds = %78, %29
%86 = load i32, i32* %4
%87 = getelementptr inbounds [713 x i8], [713 x i8]* %1, i64 0, i64 0
%88 = call i32 @strlen(i8* %87)
%89 = icmp slt i32 %86, %88
br i1 %89, label %8, label %90
90: ; preds = %85
%91 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%92 = load i32, i32* %91
%93 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%94 = load i32, i32* %93
%95 = sub nsw i32 %92, %94
%96 = call i32 @abs(i32 %95)
%97 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%98 = load i32, i32* %97
%99 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%100 = load i32, i32* %99
%101 = sub nsw i32 %98, %100
%102 = call i32 @abs(i32 %101)
%103 = add nsw i32 %96, %102
%104 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %103)
ret void
}

LLVM IR (-O2):
@__const.main.plan = [713 x i8] c"R3, L5, R2, L1, L2, R5, L2, R2, L2, L2, L1, R2, L2, R4, R4, R1, L2, L3, R3, L1, R2, L2, L4, R4, R5, L3, R3, L3, L3, R4, R5, L3, R3, L5, L1, L2, R2, L1, R3, R1, L1, R187, L1, R2, R47, L5, L1, L2, R4, R3, L3, R3, R4, R1, R3, L1, L4, L1, R2, L1, R4, R5, L1, R77, L5, L4, R3, L2, R4, R5, R5, L2, L2, R2, R5, L2, R194, R5, L2, R4, L5, L4, L2, R5, L3, L2, L5, R5, R2, L3, R3, R1, L4, R2, L1, R5, L1, R5, L1, L1, R3, L1, R5, R2, R5, R5, L4, L5, L5, L5, R3, L2, L5, L4, R3, R1, R1, R4, L2, L4, R5, R5, R4, L2, L2, R5, R5, L5, L2, R4, R4, L4, R1, L3, R1, L1, L1, L1, L4, R5, R4, L4, L4, R5, R3, L2, L2, R3, R1, R4, L3, R1, L4, R3, L3, L2, R2, R2, R2, L1, L4, R3, R2, R2, L3, R2, L3, L2, R4, L2, R3, L4, R5, R4, R1, R5, R3\00"
@.str = [3 x i8] c"%d\00"
define void @main() {
%1 = alloca [713 x i8]
%2 = alloca [4 x i32]
%3 = getelementptr inbounds [713 x i8], [713 x i8]* %1, i64 0, i64 0
%4 = bitcast [4 x i32]* %2 to i8*
br label %5
5: ; preds = %49, %0
%6 = phi i8 [ 82, %0 ], [ %52, %49 ]
%7 = phi i32 [ 0, %0 ], [ %45, %49 ]
%8 = phi i32 [ 0, %0 ], [ %46, %49 ]
switch i8 %6, label %9 [
i8 76, label %11
i8 82, label %11
i8 0, label %11
]
9: ; preds = %5
%10 = add nsw i32 %8, 1
br label %44
11: ; preds = %5, %5, %5
%12 = icmp eq i8 %6, 82
%13 = select i1 %12, i32 1, i32 3
%14 = add nsw i32 %13, %7
%15 = srem i32 %14, 4
%16 = add nsw i32 %8, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [713 x i8], [713 x i8]* %1, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = add i8 %19, -48
%21 = icmp ult i8 %20, 10
br i1 %21, label %22, label %37
22: ; preds = %11, %22
%23 = phi i64 [ %30, %22 ], [ %17, %11 ]
%24 = phi i8 [ %32, %22 ], [ %19, %11 ]
%25 = phi i32 [ %29, %22 ], [ 0, %11 ]
%26 = zext i8 %24 to i32
%27 = mul nsw i32 %25, 10
%28 = add i32 %27, -48
%29 = add i32 %28, %26
%30 = add i64 %23, 1
%31 = getelementptr inbounds [713 x i8], [713 x i8]* %1, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = add i8 %32, -48
%34 = icmp ult i8 %33, 10
br i1 %34, label %22, label %35
35: ; preds = %22
%36 = trunc i64 %30 to i32
br label %37
37: ; preds = %35, %11
%38 = phi i32 [ 0, %11 ], [ %29, %35 ]
%39 = phi i32 [ %16, %11 ], [ %36, %35 ]
%40 = zext i32 %15 to i64
%41 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = add nsw i32 %42, %38
store i32 %43, i32* %41
br label %44
44: ; preds = %37, %9
%45 = phi i32 [ %7, %9 ], [ %15, %37 ]
%46 = phi i32 [ %10, %9 ], [ %39, %37 ]
%47 = call i32 @strlen(i8* %3)
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %53
49: ; preds = %44
%50 = sext i32 %46 to i64
%51 = getelementptr inbounds [713 x i8], [713 x i8]* %1, i64 0, i64 %50
%52 = load i8, i8* %51
br label %5
53: ; preds = %44
%54 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%55 = bitcast [4 x i32]* %2 to <2 x i32>*
%56 = load <2 x i32>, <2 x i32>* %55
%57 = bitcast i32* %54 to <2 x i32>*
%58 = load <2 x i32>, <2 x i32>* %57
%59 = sub nsw <2 x i32> %56, %58
%60 = call <2 x i32> @llvm.abs.v2i32(<2 x i32> %59, i1 true)
%61 = shufflevector <2 x i32> %60, <2 x i32> poison, <2 x i32> <i32 1, i32 undef>
%62 = add nuw nsw <2 x i32> %61, %60
%63 = extractelement <2 x i32> %62, i64 0
%64 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %63)
ret void
}