#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*/ finish_path(long, long, int, int);
long randm(int);
void connect_room(long ax, long ay, long dx, long dy) {
  long mx, my;
  if (dx < 0) {
    my = ay * 20 + 1 + randm(20 - 3 - 2);
    mx = ax * 20 - 1;
    finish_path(mx, my, -1, 0);
    mx = ax * 20 - 3 + 1;
    finish_path(mx, my, +1, 0);
  } else if (dx > 0) {
    my = ay * 20 + 1 + randm(20 - 3 - 2);
    mx = ax * 20 + 20 - 1;
    finish_path(mx, my, -1, 0);
    mx = ax * 20 + 20 - 3 + 1;
    finish_path(mx, my, +1, 0);
  } else if (dy < 0) {
    mx = ax * 20 + 1 + randm(20 - 3 - 2);
    my = ay * 20 - 1;
    finish_path(mx, my, 0, -1);
    my = ay * 20 - 3 + 1;
    finish_path(mx, my, 0, +1);
  } else if (dy > 0) {
    mx = ax * 20 + 1 + randm(20 - 3 - 2);
    my = ay * 20 + 20 - 1;
    finish_path(mx, my, 0, -1);
    my = ay * 20 + 20 - 3 + 1;
    finish_path(mx, my, 0, +1);
  }
}


x86 assembly (clang, -O0):
<connect_room>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11b3 <connect_room+0x93>
imul   $0x14,-0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    $0xf,%edi
call   1030 <randm@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
imul   $0x14,-0x8(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1040 <finish_path@plt>
imul   $0x14,-0x8(%rbp),%rax
sub    $0x3,%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <finish_path@plt>
jmp    133e <connect_room+0x21e>
cmpq   $0x0,-0x18(%rbp)
jle    1236 <connect_room+0x116>
imul   $0x14,-0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    $0xf,%edi
call   1030 <randm@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
imul   $0x14,-0x8(%rbp),%rax
add    $0x14,%rax
sub    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1040 <finish_path@plt>
imul   $0x14,-0x8(%rbp),%rax
add    $0x14,%rax
sub    $0x3,%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <finish_path@plt>
jmp    1339 <connect_room+0x219>
cmpq   $0x0,-0x20(%rbp)
jge    12b1 <connect_room+0x191>
imul   $0x14,-0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    $0xf,%edi
call   1030 <randm@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
imul   $0x14,-0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
xor    %edx,%edx
mov    $0xffffffff,%ecx
call   1040 <finish_path@plt>
imul   $0x14,-0x10(%rbp),%rax
sub    $0x3,%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
xor    %edx,%edx
mov    $0x1,%ecx
call   1040 <finish_path@plt>
jmp    1334 <connect_room+0x214>
cmpq   $0x0,-0x20(%rbp)
jle    132f <connect_room+0x20f>
imul   $0x14,-0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    $0xf,%edi
call   1030 <randm@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
imul   $0x14,-0x10(%rbp),%rax
add    $0x14,%rax
sub    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
xor    %edx,%edx
mov    $0xffffffff,%ecx
call   1040 <finish_path@plt>
imul   $0x14,-0x10(%rbp),%rax
add    $0x14,%rax
sub    $0x3,%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
xor    %edx,%edx
mov    $0x1,%ecx
call   1040 <finish_path@plt>
jmp    1334 <connect_room+0x214>
jmp    1339 <connect_room+0x219>
jmp    133e <connect_room+0x21e>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connect_room>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdx,%rdx
js     1170 <connect_room+0x50>
je     11bf <connect_room+0x9f>
lea    (%r14,%r14,4),%r14
mov    $0xf,%edi
call   1030 <randm@plt>
lea    (%rax,%r14,4),%r14
add    $0x1,%r14
shl    $0x2,%rbx
lea    (%rbx,%rbx,4),%rdi
add    $0x13,%rdi
mov    %r14,%rsi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1040 <finish_path@plt>
lea    (%rbx,%rbx,4),%rdi
add    $0x12,%rdi
jmp    11a9 <connect_room+0x89>
lea    (%r14,%r14,4),%r14
mov    $0xf,%edi
call   1030 <randm@plt>
lea    (%rax,%r14,4),%r14
add    $0x1,%r14
shl    $0x2,%rbx
lea    (%rbx,%rbx,4),%rdi
add    $0xffffffffffffffff,%rdi
mov    %r14,%rsi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1040 <finish_path@plt>
lea    (%rbx,%rbx,4),%rdi
add    $0xfffffffffffffffe,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <finish_path@plt>
test   %rcx,%rcx
js     1205 <connect_room+0xe5>
je     124d <connect_room+0x12d>
lea    (%rbx,%rbx,4),%rbx
mov    $0xf,%edi
call   1030 <randm@plt>
lea    (%rax,%rbx,4),%rbx
add    $0x1,%rbx
shl    $0x2,%r14
lea    (%r14,%r14,4),%rsi
add    $0x13,%rsi
mov    %rbx,%rdi
xor    %edx,%edx
mov    $0xffffffff,%ecx
call   1040 <finish_path@plt>
lea    (%r14,%r14,4),%rsi
add    $0x12,%rsi
jmp    123e <connect_room+0x11e>
lea    (%rbx,%rbx,4),%rbx
mov    $0xf,%edi
call   1030 <randm@plt>
lea    (%rax,%rbx,4),%rbx
add    $0x1,%rbx
shl    $0x2,%r14
lea    (%r14,%r14,4),%rsi
add    $0xffffffffffffffff,%rsi
mov    %rbx,%rdi
xor    %edx,%edx
mov    $0xffffffff,%ecx
call   1040 <finish_path@plt>
lea    (%r14,%r14,4),%rsi
add    $0xfffffffffffffffe,%rsi
mov    %rbx,%rdi
xor    %edx,%edx
mov    $0x1,%ecx
jmp    11b3 <connect_room+0x93>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @connect_room(i64 %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i64 %0, i64* %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%11 = load i64, i64* %7
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %32
13: ; preds = %4
%14 = load i64, i64* %6
%15 = mul nsw i64 %14, 20
%16 = add nsw i64 %15, 1
%17 = call i64 @randm(i32 15)
%18 = add nsw i64 %16, %17
store i64 %18, i64* %10
%19 = load i64, i64* %5
%20 = mul nsw i64 %19, 20
%21 = sub nsw i64 %20, 1
store i64 %21, i64* %9
%22 = load i64, i64* %9
%23 = load i64, i64* %10
%24 = call i32 @finish_path(i64 %22, i64 %23, i32 -1, i32 0)
%25 = load i64, i64* %5
%26 = mul nsw i64 %25, 20
%27 = sub nsw i64 %26, 3
%28 = add nsw i64 %27, 1
store i64 %28, i64* %9
%29 = load i64, i64* %9
%30 = load i64, i64* %10
%31 = call i32 @finish_path(i64 %29, i64 %30, i32 1, i32 0)
br label %105
32: ; preds = %4
%33 = load i64, i64* %7
%34 = icmp sgt i64 %33, 0
br i1 %34, label %35, label %56
35: ; preds = %32
%36 = load i64, i64* %6
%37 = mul nsw i64 %36, 20
%38 = add nsw i64 %37, 1
%39 = call i64 @randm(i32 15)
%40 = add nsw i64 %38, %39
store i64 %40, i64* %10
%41 = load i64, i64* %5
%42 = mul nsw i64 %41, 20
%43 = add nsw i64 %42, 20
%44 = sub nsw i64 %43, 1
store i64 %44, i64* %9
%45 = load i64, i64* %9
%46 = load i64, i64* %10
%47 = call i32 @finish_path(i64 %45, i64 %46, i32 -1, i32 0)
%48 = load i64, i64* %5
%49 = mul nsw i64 %48, 20
%50 = add nsw i64 %49, 20
%51 = sub nsw i64 %50, 3
%52 = add nsw i64 %51, 1
store i64 %52, i64* %9
%53 = load i64, i64* %9
%54 = load i64, i64* %10
%55 = call i32 @finish_path(i64 %53, i64 %54, i32 1, i32 0)
br label %104
56: ; preds = %32
%57 = load i64, i64* %8
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %78
59: ; preds = %56
%60 = load i64, i64* %5
%61 = mul nsw i64 %60, 20
%62 = add nsw i64 %61, 1
%63 = call i64 @randm(i32 15)
%64 = add nsw i64 %62, %63
store i64 %64, i64* %9
%65 = load i64, i64* %6
%66 = mul nsw i64 %65, 20
%67 = sub nsw i64 %66, 1
store i64 %67, i64* %10
%68 = load i64, i64* %9
%69 = load i64, i64* %10
%70 = call i32 @finish_path(i64 %68, i64 %69, i32 0, i32 -1)
%71 = load i64, i64* %6
%72 = mul nsw i64 %71, 20
%73 = sub nsw i64 %72, 3
%74 = add nsw i64 %73, 1
store i64 %74, i64* %10
%75 = load i64, i64* %9
%76 = load i64, i64* %10
%77 = call i32 @finish_path(i64 %75, i64 %76, i32 0, i32 1)
br label %103
78: ; preds = %56
%79 = load i64, i64* %8
%80 = icmp sgt i64 %79, 0
br i1 %80, label %81, label %102
81: ; preds = %78
%82 = load i64, i64* %5
%83 = mul nsw i64 %82, 20
%84 = add nsw i64 %83, 1
%85 = call i64 @randm(i32 15)
%86 = add nsw i64 %84, %85
store i64 %86, i64* %9
%87 = load i64, i64* %6
%88 = mul nsw i64 %87, 20
%89 = add nsw i64 %88, 20
%90 = sub nsw i64 %89, 1
store i64 %90, i64* %10
%91 = load i64, i64* %9
%92 = load i64, i64* %10
%93 = call i32 @finish_path(i64 %91, i64 %92, i32 0, i32 -1)
%94 = load i64, i64* %6
%95 = mul nsw i64 %94, 20
%96 = add nsw i64 %95, 20
%97 = sub nsw i64 %96, 3
%98 = add nsw i64 %97, 1
store i64 %98, i64* %10
%99 = load i64, i64* %9
%100 = load i64, i64* %10
%101 = call i32 @finish_path(i64 %99, i64 %100, i32 0, i32 1)
br label %102
102: ; preds = %81, %78
br label %103
103: ; preds = %102, %59
br label %104
104: ; preds = %103, %35
br label %105
105: ; preds = %104, %13
ret void
}

LLVM IR (-O2):
define void @connect_room(i64 %0, i64 %1, i64 %2, i64 %3) {
%5 = icmp slt i64 %2, 0
br i1 %5, label %6, label %16
6: ; preds = %4
%7 = mul nsw i64 %1, 20
%8 = or i64 %7, 1
%9 = tail call i64 @randm(i32 15)
%10 = add nsw i64 %8, %9
%11 = mul nsw i64 %0, 20
%12 = add nsw i64 %11, -1
%13 = tail call i32 @finish_path(i64 %12, i64 %10, i32 -1, i32 0)
%14 = add nsw i64 %11, -2
%15 = tail call i32 @finish_path(i64 %14, i64 %10, i32 1, i32 0)
br label %52
16: ; preds = %4
%17 = icmp eq i64 %2, 0
br i1 %17, label %28, label %18
18: ; preds = %16
%19 = mul nsw i64 %1, 20
%20 = or i64 %19, 1
%21 = tail call i64 @randm(i32 15)
%22 = add nsw i64 %20, %21
%23 = mul nsw i64 %0, 20
%24 = add nsw i64 %23, 19
%25 = tail call i32 @finish_path(i64 %24, i64 %22, i32 -1, i32 0)
%26 = add nsw i64 %23, 18
%27 = tail call i32 @finish_path(i64 %26, i64 %22, i32 1, i32 0)
br label %52
28: ; preds = %16
%29 = icmp slt i64 %3, 0
br i1 %29, label %30, label %40
30: ; preds = %28
%31 = mul nsw i64 %0, 20
%32 = or i64 %31, 1
%33 = tail call i64 @randm(i32 15)
%34 = add nsw i64 %32, %33
%35 = mul nsw i64 %1, 20
%36 = add nsw i64 %35, -1
%37 = tail call i32 @finish_path(i64 %34, i64 %36, i32 0, i32 -1)
%38 = add nsw i64 %35, -2
%39 = tail call i32 @finish_path(i64 %34, i64 %38, i32 0, i32 1)
br label %52
40: ; preds = %28
%41 = icmp eq i64 %3, 0
br i1 %41, label %52, label %42
42: ; preds = %40
%43 = mul nsw i64 %0, 20
%44 = or i64 %43, 1
%45 = tail call i64 @randm(i32 15)
%46 = add nsw i64 %44, %45
%47 = mul nsw i64 %1, 20
%48 = add nsw i64 %47, 19
%49 = tail call i32 @finish_path(i64 %46, i64 %48, i32 0, i32 -1)
%50 = add nsw i64 %47, 18
%51 = tail call i32 @finish_path(i64 %46, i64 %50, i32 0, i32 1)
br label %52
52: ; preds = %18, %40, %42, %30, %6
ret void
}