#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 */
scalar_t__ abs(float);
int maze_width(char *);
float maze_cost(void *context, void *first, void *second) {
  char *maze = context;
  char *f = first;
  char *s = second;
  int sx, sy, fx, fy;
  float d, dx, dy;
  int fp = f - maze;
  int sp = s - maze;
  sx = sp % maze_width(maze);
  sy = sp / maze_width(maze);
  fx = fp % maze_width(maze);
  fy = fp / maze_width(maze);
  dx = (float)sx - fx;
  dy = (float)sy - fy;
  d = (float)(abs(dx) + abs(dy));
  return d;
}


x86 assembly (clang, -O0):
<maze_cost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x50(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <maze_width@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0x34(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <maze_width@plt>
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x38(%rbp)
mov    -0x50(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <maze_width@plt>
mov    %eax,%ecx
mov    -0x68(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0x3c(%rbp)
mov    -0x50(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <maze_width@plt>
mov    %eax,%ecx
mov    -0x64(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x40(%rbp)
cvtsi2ssl -0x34(%rbp),%xmm0
cvtsi2ssl -0x3c(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x48(%rbp)
cvtsi2ssl -0x38(%rbp),%xmm0
cvtsi2ssl -0x40(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x4c(%rbp)
movss  -0x48(%rbp),%xmm0
call   1030 <abs@plt>
mov    %rax,-0x60(%rbp)
movss  -0x4c(%rbp),%xmm0
call   1030 <abs@plt>
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
add    %rcx,%rax
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x44(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maze_cost>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
sub    %ebx,%r14d
sub    %ebx,%r15d
call   1040 <maze_width@plt>
mov    %eax,%ecx
mov    %r15d,%eax
cltd
idiv   %ecx
mov    %edx,%r12d
mov    %rbx,%rdi
call   1040 <maze_width@plt>
mov    %eax,%ecx
mov    %r15d,%eax
cltd
idiv   %ecx
mov    %eax,%r15d
mov    %rbx,%rdi
call   1040 <maze_width@plt>
mov    %eax,%ecx
mov    %r14d,%eax
cltd
idiv   %ecx
mov    %edx,%ebp
mov    %rbx,%rdi
call   1040 <maze_width@plt>
mov    %eax,%ecx
mov    %r14d,%eax
cltd
cvtsi2ss %r12d,%xmm0
idiv   %ecx
cvtsi2ss %ebp,%xmm1
subss  %xmm1,%xmm0
cvtsi2ss %r15d,%xmm2
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
subss  %xmm1,%xmm2
movss  %xmm2,0xc(%rsp)
call   1030 <abs@plt>
mov    %rax,%rbx
movss  0xc(%rsp),%xmm0
call   1030 <abs@plt>
add    %rbx,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define float @maze_cost(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca float
%15 = alloca float
%16 = alloca float
%17 = alloca i32
%18 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%19 = load i8*, i8** %4
store i8* %19, i8** %7
%20 = load i8*, i8** %5
store i8* %20, i8** %8
%21 = load i8*, i8** %6
store i8* %21, i8** %9
%22 = load i8*, i8** %8
%23 = load i8*, i8** %7
%24 = ptrtoint i8* %22 to i64
%25 = ptrtoint i8* %23 to i64
%26 = sub i64 %24, %25
%27 = trunc i64 %26 to i32
store i32 %27, i32* %17
%28 = load i8*, i8** %9
%29 = load i8*, i8** %7
%30 = ptrtoint i8* %28 to i64
%31 = ptrtoint i8* %29 to i64
%32 = sub i64 %30, %31
%33 = trunc i64 %32 to i32
store i32 %33, i32* %18
%34 = load i32, i32* %18
%35 = load i8*, i8** %7
%36 = call i32 @maze_width(i8* %35)
%37 = srem i32 %34, %36
store i32 %37, i32* %10
%38 = load i32, i32* %18
%39 = load i8*, i8** %7
%40 = call i32 @maze_width(i8* %39)
%41 = sdiv i32 %38, %40
store i32 %41, i32* %11
%42 = load i32, i32* %17
%43 = load i8*, i8** %7
%44 = call i32 @maze_width(i8* %43)
%45 = srem i32 %42, %44
store i32 %45, i32* %12
%46 = load i32, i32* %17
%47 = load i8*, i8** %7
%48 = call i32 @maze_width(i8* %47)
%49 = sdiv i32 %46, %48
store i32 %49, i32* %13
%50 = load i32, i32* %10
%51 = sitofp i32 %50 to float
%52 = load i32, i32* %12
%53 = sitofp i32 %52 to float
%54 = fsub float %51, %53
store float %54, float* %15
%55 = load i32, i32* %11
%56 = sitofp i32 %55 to float
%57 = load i32, i32* %13
%58 = sitofp i32 %57 to float
%59 = fsub float %56, %58
store float %59, float* %16
%60 = load float, float* %15
%61 = call i64 @abs(float %60)
%62 = load float, float* %16
%63 = call i64 @abs(float %62)
%64 = add nsw i64 %61, %63
%65 = sitofp i64 %64 to float
store float %65, float* %14
%66 = load float, float* %14
ret float %66
}

LLVM IR (-O2):
define float @maze_cost(i8* %0, i8* %1, i8* %2) {
%4 = ptrtoint i8* %1 to i64
%5 = ptrtoint i8* %0 to i64
%6 = sub i64 %4, %5
%7 = trunc i64 %6 to i32
%8 = ptrtoint i8* %2 to i64
%9 = sub i64 %8, %5
%10 = trunc i64 %9 to i32
%11 = tail call i32 @maze_width(i8* %0)
%12 = srem i32 %10, %11
%13 = tail call i32 @maze_width(i8* %0)
%14 = sdiv i32 %10, %13
%15 = tail call i32 @maze_width(i8* %0)
%16 = srem i32 %7, %15
%17 = tail call i32 @maze_width(i8* %0)
%18 = sdiv i32 %7, %17
%19 = sitofp i32 %12 to float
%20 = sitofp i32 %16 to float
%21 = fsub float %19, %20
%22 = sitofp i32 %14 to float
%23 = sitofp i32 %18 to float
%24 = fsub float %22, %23
%25 = tail call i64 @abs(float %21)
%26 = tail call i64 @abs(float %24)
%27 = add nsw i64 %26, %25
%28 = sitofp i64 %27 to float
ret float %28
}