#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 /*<<< orphan*/ find_nearest_treasure(int, int, int *, int *);
int /*<<< orphan*/ printf(char *, ...);
void do_next_step(int cur_x, int cur_y, int *command) {
  int res = 0;
  int target_x, target_y;
  find_nearest_treasure(cur_x, cur_y, &target_x, &target_y);
  printf("My coords: %d %d. Target: %d %d\n", cur_x, cur_y, target_x, target_y);
  if (cur_x > target_x) {
    printf("Move LEFT\n");
    res = 1;
  } else if (cur_x < target_x) {
    printf("Move RIGHT\n");
    res = 3;
  } else if (cur_y > target_y) {
    printf("Move DOWN\n");
    res = 4;
  } else if (cur_y < target_y) {
    printf("Move UP\n");
    res = 2;
  }
  *command = res;
}


x86 assembly (clang, -O0):
<do_next_step>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
call   1040 <find_nearest_treasure@plt>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    118d <do_next_step+0x6d>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x14(%rbp)
jmp    1209 <do_next_step+0xe9>
mov    -0x4(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11b3 <do_next_step+0x93>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x3,-0x14(%rbp)
jmp    1204 <do_next_step+0xe4>
mov    -0x8(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    11d9 <do_next_step+0xb9>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x4,-0x14(%rbp)
jmp    11ff <do_next_step+0xdf>
mov    -0x8(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11fa <do_next_step+0xda>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x14(%rbp)
jmp    11ff <do_next_step+0xdf>
jmp    1204 <do_next_step+0xe4>
jmp    1209 <do_next_step+0xe9>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_next_step>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %edi,%ebx
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1050 <find_nearest_treasure@plt>
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
lea    0xea2(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %ebx,0xc(%rsp)
jge    117d <do_next_step+0x4d>
mov    $0x1,%ebx
lea    0xec3(%rip),%rdi
jmp    11b5 <do_next_step+0x85>
jle    118d <do_next_step+0x5d>
mov    $0x3,%ebx
lea    0xea8(%rip),%rdi
jmp    11b5 <do_next_step+0x85>
mov    0x8(%rsp),%eax
cmp    %ebp,%eax
jge    11a3 <do_next_step+0x73>
mov    $0x4,%ebx
lea    0xe88(%rip),%rdi
jmp    11b5 <do_next_step+0x85>
xor    %ebx,%ebx
cmp    %ebp,%eax
jle    11ba <do_next_step+0x8a>
mov    $0x2,%ebx
lea    0xe6c(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"My coords: %d %d. Target: %d %d\0A\00"
@.str.1 = [11 x i8] c"Move LEFT\0A\00"
@.str.2 = [12 x i8] c"Move RIGHT\0A\00"
@.str.3 = [11 x i8] c"Move DOWN\0A\00"
@.str.4 = [9 x i8] c"Move UP\0A\00"
define void @do_next_step(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %7
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = call i32 @find_nearest_treasure(i32 %10, i32 %11, i32* %8, i32* %9)
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = load i32, i32* %8
%16 = load i32, i32* %9
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14, i32 %15, i32 %16)
%18 = load i32, i32* %4
%19 = load i32, i32* %8
%20 = icmp sgt i32 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %7
br label %44
23: ; preds = %3
%24 = load i32, i32* %4
%25 = load i32, i32* %8
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i32 3, i32* %7
br label %43
29: ; preds = %23
%30 = load i32, i32* %5
%31 = load i32, i32* %9
%32 = icmp sgt i32 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
store i32 4, i32* %7
br label %42
35: ; preds = %29
%36 = load i32, i32* %5
%37 = load i32, i32* %9
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %7
br label %41
41: ; preds = %39, %35
br label %42
42: ; preds = %41, %33
br label %43
43: ; preds = %42, %27
br label %44
44: ; preds = %43, %21
%45 = load i32, i32* %7
%46 = load i32*, i32** %6
store i32 %45, i32* %46
ret void
}

LLVM IR (-O2):
@.str = [33 x i8] c"My coords: %d %d. Target: %d %d\0A\00"
@str = [8 x i8] c"Move UP\00"
@str.5 = [10 x i8] c"Move DOWN\00"
@str.6 = [11 x i8] c"Move RIGHT\00"
@str.7 = [10 x i8] c"Move LEFT\00"
define void @do_next_step(i32 %0, i32 %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
%7 = bitcast i32* %5 to i8*
%8 = call i32 @find_nearest_treasure(i32 %0, i32 %1, i32* %4, i32* %5)
%9 = load i32, i32* %4
%10 = load i32, i32* %5
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1, i32 %9, i32 %10)
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, %0
br i1 %13, label %21, label %14
14: ; preds = %3
%15 = icmp sgt i32 %12, %0
br i1 %15, label %21, label %16
16: ; preds = %14
%17 = load i32, i32* %5
%18 = icmp slt i32 %17, %1
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = icmp sgt i32 %17, %1
br i1 %20, label %21, label %25
21: ; preds = %19, %16, %14, %3
%22 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @str.7, i64 0, i64 0), %3 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @str.6, i64 0, i64 0), %14 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @str.5, i64 0, i64 0), %16 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0), %19 ]
%23 = phi i32 [ 1, %3 ], [ 3, %14 ], [ 4, %16 ], [ 2, %19 ]
%24 = call i32 @puts(i8* dereferenceable(1) %22)
br label %25
25: ; preds = %21, %19
%26 = phi i32 [ 0, %19 ], [ %23, %21 ]
store i32 %26, i32* %2
ret void
}