#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 abs(int);
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ move(char, int /*<<< orphan*/, int *);
int /*<<< orphan*/ printf(char *, ...);
char rotate(char, char);
int main() {
  char data[8];
  int cords[2] = {0, 0};
  FILE *fp = fopen("input", "r");
  char dir = 'N';
  if (fp == NULL) {
    printf("could not open input file\n");
    return -1;
  }
  while (fscanf(fp, "%s", data) != EOF) {
    dir = rotate(dir, data[0]);
    move(dir, atoi(data + 1), cords);
  }
  printf("Final distance is %i blocks away. (at block %i, %i)\n",
         abs(cords[0]) + abs(cords[1]), cords[0], cords[1]);
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x14(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
lea    0xe4a(%rip),%rdi
lea    0xe49(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
movb   $0x4e,-0x21(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ef <main+0x5f>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128f <main+0xff>
jmp    11f4 <main+0x64>
mov    -0x20(%rbp),%rdi
lea    -0xc(%rbp),%rdx
lea    0xe20(%rip),%rsi
call   1070 <fscanf@plt>
mov    0x2dd9(%rip),%rcx
cmp    (%rcx),%rax
je     1253 <main+0xc3>
mov    -0x21(%rbp),%al
movsbl %al,%edi
movsbl -0xc(%rbp),%esi
call   1080 <rotate@plt>
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
mov    %al,-0x22(%rbp)
lea    -0xc(%rbp),%rdi
add    $0x1,%rdi
call   10a0 <atoi@plt>
mov    %eax,%esi
mov    -0x22(%rbp),%al
lea    -0x14(%rbp),%rdx
movsbl %al,%edi
call   10b0 <move@plt>
jmp    11f4 <main+0x64>
mov    -0x14(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <abs@plt>
mov    -0x28(%rbp),%esi
add    %eax,%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@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
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
lea    0xe62(%rip),%rdi
lea    0xe61(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     126e <main+0xee>
mov    %rax,%rbx
lea    0xe4b(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
mov    0x2e17(%rip),%r15
xor    %ebp,%ebp
mov    $0x0,%ecx
mov    $0x0,%edx
cmp    (%r15),%rax
je     1246 <main+0xc6>
mov    $0x4e,%r14b
lea    0x8(%rsp),%r12
lea    0xe17(%rip),%r13
lea    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
movsbl 0x10(%rsp),%esi
movsbl %r14b,%edi
call   1070 <rotate@plt>
mov    %eax,%r14d
lea    0x11(%rsp),%rdi
call   1090 <atoi@plt>
movsbl %r14b,%edi
mov    %eax,%esi
mov    %r12,%rdx
call   10a0 <move@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1060 <fscanf@plt>
cmp    (%r15),%rax
jne    1200 <main+0x80>
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
xor    %ebp,%ebp
mov    %edx,%eax
neg    %eax
cmovs  %edx,%eax
mov    %ecx,%esi
neg    %esi
cmovs  %ecx,%esi
add    %eax,%esi
lea    0xdae(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    127f <main+0xff>
lea    0xdcb(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"input\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"could not open input file\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.4 = [53 x i8] c"Final distance is %i blocks away. (at block %i, %i)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [8 x i8]
%3 = alloca [2 x i32]
%4 = alloca i32*
%5 = alloca i8
store i32 0, i32* %1
%6 = bitcast [2 x i32]* %3 to i8*
%7 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %4
store i8 78, i8* %5
%8 = load i32*, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %45
12: ; preds = %0
br label %13
13: ; preds = %19, %12
%14 = load i32*, i32** %4
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%16 = call i64 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = load i64, i64* @EOF
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %30
19: ; preds = %13
%20 = load i8, i8* %5
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%22 = load i8, i8* %21
%23 = call signext i8 @rotate(i8 signext %20, i8 signext %22)
store i8 %23, i8* %5
%24 = load i8, i8* %5
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = call i32 @atoi(i8* %26)
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%29 = call i32 @move(i8 signext %24, i32 %27, i32* %28)
br label %13
30: ; preds = %13
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%32 = load i32, i32* %31
%33 = call i32 @abs(i32 %32)
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%35 = load i32, i32* %34
%36 = call i32 @abs(i32 %35)
%37 = add nsw i32 %33, %36
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%39 = load i32, i32* %38
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %37, i32 %39, i32 %41)
%43 = load i32*, i32** %4
%44 = call i32 @fclose(i32* %43)
store i32 0, i32* %1
br label %45
45: ; preds = %30, %10
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@.str = [6 x i8] c"input\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.4 = [53 x i8] c"Final distance is %i blocks away. (at block %i, %i)\0A\00"
@str = [26 x i8] c"could not open input file\00"
define i32 @main() {
%1 = alloca [8 x i8]
%2 = alloca i64
%3 = bitcast i64* %2 to [2 x i32]*
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%5 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %15, label %8
8: ; preds = %0
%9 = call i64 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%10 = load i64, i64* @EOF
%11 = icmp eq i64 %9, %10
br i1 %11, label %30, label %12
12: ; preds = %8
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 1
%14 = bitcast i64* %2 to i32*
br label %17
15: ; preds = %0
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %38
17: ; preds = %12, %17
%18 = phi i8 [ 78, %12 ], [ %20, %17 ]
%19 = load i8, i8* %4
%20 = call signext i8 @rotate(i8 signext %18, i8 signext %19)
%21 = call i32 @atoi(i8* %13)
%22 = call i32 @move(i8 signext %20, i32 %21, i32* %14)
%23 = call i64 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%24 = load i64, i64* @EOF
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %17
26: ; preds = %17
%27 = load i32, i32* %14
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%29 = load i32, i32* %28
br label %30
30: ; preds = %8, %26
%31 = phi i32 [ %29, %26 ], [ 0, %8 ]
%32 = phi i32 [ %27, %26 ], [ 0, %8 ]
%33 = call i32 @llvm.abs.i32(i32 %32, i1 true)
%34 = call i32 @llvm.abs.i32(i32 %31, i1 true)
%35 = add nuw nsw i32 %34, %33
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %35, i32 %32, i32 %31)
%37 = call i32 @fclose(i32* %6)
br label %38
38: ; preds = %30, %15
%39 = phi i32 [ -1, %15 ], [ 0, %30 ]
ret i32 %39
}