#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 *malloc(int);
int /*<<< orphan*/ operacao_dist(int *, int *, int, int);
int *dist(int pacman[3]) {
  int linha, coluna, *dir, posicao_pacman;
  posicao_pacman = pacman[3];
  dir = malloc(sizeof(int) * 2);
  if (posicao_pacman == 1)
    operacao_dist(pacman, dir, 0, 2);
  if (posicao_pacman == 2)
    operacao_dist(pacman, dir, 0, -2);
  if (posicao_pacman == 3)
    operacao_dist(pacman, dir, -2, 0);
  if (posicao_pacman == 4)
    operacao_dist(pacman, dir, 2, 0);
  return dir;
}


x86 assembly (clang, -O0):
<dist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x8,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    1162 <dist+0x42>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
mov    $0x2,%ecx
call   1040 <operacao_dist@plt>
cmpl   $0x2,-0x1c(%rbp)
jne    1180 <dist+0x60>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
mov    $0xfffffffe,%ecx
call   1040 <operacao_dist@plt>
cmpl   $0x3,-0x1c(%rbp)
jne    119e <dist+0x7e>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xfffffffe,%edx
xor    %ecx,%ecx
call   1040 <operacao_dist@plt>
cmpl   $0x4,-0x1c(%rbp)
jne    11bc <dist+0x9c>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1040 <operacao_dist@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dist>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    0xc(%rdi),%ebx
mov    $0x8,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
add    $0xffffffff,%ebx
cmp    $0x3,%ebx
ja     118d <dist+0x6d>
lea    0xeb9(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    $0x2,%ecx
jmp    1188 <dist+0x68>
mov    %r15,%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    $0xfffffffe,%ecx
jmp    1188 <dist+0x68>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0xfffffffe,%edx
jmp    1186 <dist+0x66>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1040 <operacao_dist@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @dist(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32* %0, i32** %2
%7 = load i32*, i32** %2
%8 = getelementptr inbounds i32, i32* %7, i64 3
%9 = load i32, i32* %8
store i32 %9, i32* %6
%10 = call i32* @malloc(i32 8)
store i32* %10, i32** %5
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = load i32*, i32** %2
%15 = load i32*, i32** %5
%16 = call i32 @operacao_dist(i32* %14, i32* %15, i32 0, i32 2)
br label %17
17: ; preds = %13, %1
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32*, i32** %2
%22 = load i32*, i32** %5
%23 = call i32 @operacao_dist(i32* %21, i32* %22, i32 0, i32 -2)
br label %24
24: ; preds = %20, %17
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, 3
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32*, i32** %2
%29 = load i32*, i32** %5
%30 = call i32 @operacao_dist(i32* %28, i32* %29, i32 -2, i32 0)
br label %31
31: ; preds = %27, %24
%32 = load i32, i32* %6
%33 = icmp eq i32 %32, 4
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i32*, i32** %2
%36 = load i32*, i32** %5
%37 = call i32 @operacao_dist(i32* %35, i32* %36, i32 2, i32 0)
br label %38
38: ; preds = %34, %31
%39 = load i32*, i32** %5
ret i32* %39
}

LLVM IR (-O2):
define i32* @dist(i32* %0) {
%2 = getelementptr inbounds i32, i32* %0, i64 3
%3 = load i32, i32* %2
%4 = tail call i32* @malloc(i32 8)
switch i32 %3, label %13 [
i32 1, label %5
i32 2, label %7
i32 3, label %9
i32 4, label %11
]
5: ; preds = %1
%6 = tail call i32 @operacao_dist(i32* %0, i32* %4, i32 0, i32 2)
br label %13
7: ; preds = %1
%8 = tail call i32 @operacao_dist(i32* %0, i32* %4, i32 0, i32 -2)
br label %13
9: ; preds = %1
%10 = tail call i32 @operacao_dist(i32* %0, i32* %4, i32 -2, i32 0)
br label %13
11: ; preds = %1
%12 = tail call i32 @operacao_dist(i32* %0, i32* %4, i32 2, i32 0)
br label %13
13: ; preds = %9, %7, %5, %1, %11
ret i32* %4
}