#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 */
struct maze {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ maze_build_cell_walls(struct maze *, int, int, int, int, int,
                                         int);
int maze_choose_next_cell(struct maze *, int, int, int, int, int *, int *);
int /*<<< orphan*/ maze_find_any_next_cell(struct maze *, int, int, int *,
                                           int *);
void maze_construct_segment(struct maze *mp, int row1, int col1, int row2,
                            int col2) {
  int prevrow = row1;
  int prevcol = col1;
  int currow = row2;
  int curcol = col2;
  int nextrow;
  int nextcol;
  if (prevrow == currow && prevcol == curcol) {
    if (!maze_find_any_next_cell(mp, currow, curcol, &nextrow, &nextcol))
      return;
    maze_build_cell_walls(mp, prevrow, prevcol, currow, curcol, nextrow,
                          nextcol);
    prevrow = currow;
    prevcol = curcol;
    currow = nextrow;
    curcol = nextcol;
  }
  for (;;) {
    switch (maze_choose_next_cell(mp, prevrow, prevcol, currow, curcol,
                                  &nextrow, &nextcol)) {
    case 0:
      maze_build_cell_walls(mp, prevrow, prevcol, currow, curcol, nextrow,
                            nextcol);
      prevrow = currow;
      prevcol = curcol;
      currow = nextrow;
      curcol = nextcol;
      break;
    case 2:
      maze_build_cell_walls(mp, prevrow, prevcol, currow, curcol, prevrow,
                            prevcol);
    case 1:
      return;
    }
  }
}


x86 assembly (clang, -O0):
<maze_construct_segment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    11d6 <maze_construct_segment+0xa6>
mov    -0x20(%rbp),%eax
cmp    -0x28(%rbp),%eax
jne    11d6 <maze_construct_segment+0xa6>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    -0x2c(%rbp),%rcx
lea    -0x30(%rbp),%r8
call   1030 <maze_find_any_next_cell@plt>
cmp    $0x0,%eax
jne    119e <maze_construct_segment+0x6e>
jmp    129a <maze_construct_segment+0x16a>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x30(%rbp),%eax
mov    %eax,(%rsp)
call   1040 <maze_build_cell_walls@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    11db <maze_construct_segment+0xab>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    %rsp,%rax
lea    -0x30(%rbp),%r9
mov    %r9,(%rax)
lea    -0x2c(%rbp),%r9
call   1050 <maze_choose_next_cell@plt>
mov    %eax,%ecx
mov    %ecx,-0x34(%rbp)
test   %eax,%eax
je     1233 <maze_construct_segment+0x103>
jmp    1211 <maze_construct_segment+0xe1>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
je     1290 <maze_construct_segment+0x160>
jmp    1222 <maze_construct_segment+0xf2>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
je     1270 <maze_construct_segment+0x140>
jmp    1295 <maze_construct_segment+0x165>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x30(%rbp),%eax
mov    %eax,(%rsp)
call   1040 <maze_build_cell_walls@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1295 <maze_construct_segment+0x165>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    -0x20(%rbp),%eax
mov    %eax,(%rsp)
call   1040 <maze_build_cell_walls@plt>
jmp    129a <maze_construct_segment+0x16a>
jmp    11db <maze_construct_segment+0xab>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maze_construct_segment>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%ebx
mov    %ecx,%ebp
mov    %edx,%r12d
mov    %esi,%r15d
mov    %rdi,%r14
cmp    %ecx,%esi
jne    119d <maze_construct_segment+0x6d>
cmp    %ebx,%r12d
jne    119d <maze_construct_segment+0x6d>
lea    0x14(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
call   1030 <maze_find_any_next_cell@plt>
test   %eax,%eax
je     1226 <maze_construct_segment+0xf6>
mov    0x14(%rsp),%r9d
mov    0x10(%rsp),%eax
mov    %eax,(%rsp)
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %r15d,%ecx
mov    %r12d,%r8d
call   1040 <maze_build_cell_walls@plt>
mov    0x14(%rsp),%ebp
mov    0x10(%rsp),%ebx
lea    0x14(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x10(%rsp),%rax
mov    %rax,(%rsp)
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %ebp,%ecx
mov    %ebx,%r8d
mov    %r13,%r9
call   1050 <maze_choose_next_cell@plt>
cmp    $0x2,%eax
je     120c <maze_construct_segment+0xdc>
cmp    $0x1,%eax
je     1226 <maze_construct_segment+0xf6>
test   %eax,%eax
jne    11b0 <maze_construct_segment+0x80>
mov    0x14(%rsp),%r9d
mov    0x10(%rsp),%eax
mov    %eax,(%rsp)
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %ebp,%ecx
mov    %ebx,%r8d
call   1040 <maze_build_cell_walls@plt>
mov    %ebp,%r15d
mov    0x14(%rsp),%ebp
mov    %ebx,%r12d
mov    0x10(%rsp),%ebx
jmp    11b0 <maze_construct_segment+0x80>
mov    %r12d,(%rsp)
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %ebp,%ecx
mov    %ebx,%r8d
mov    %r15d,%r9d
call   1040 <maze_build_cell_walls@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.maze = type { i32 }
define void @maze_construct_segment(%struct.maze* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca %struct.maze*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store %struct.maze* %0, %struct.maze** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%17 = load i32, i32* %7
store i32 %17, i32* %11
%18 = load i32, i32* %8
store i32 %18, i32* %12
%19 = load i32, i32* %9
store i32 %19, i32* %13
%20 = load i32, i32* %10
store i32 %20, i32* %14
%21 = load i32, i32* %11
%22 = load i32, i32* %13
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %48
24: ; preds = %5
%25 = load i32, i32* %12
%26 = load i32, i32* %14
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %48
28: ; preds = %24
%29 = load %struct.maze*, %struct.maze** %6
%30 = load i32, i32* %13
%31 = load i32, i32* %14
%32 = call i32 @maze_find_any_next_cell(%struct.maze* %29, i32 %30, i32 %31, i32* %15, i32* %16)
%33 = icmp ne i32 %32, 0
br i1 %33, label %35, label %34
34: ; preds = %28
br label %80
35: ; preds = %28
%36 = load %struct.maze*, %struct.maze** %6
%37 = load i32, i32* %11
%38 = load i32, i32* %12
%39 = load i32, i32* %13
%40 = load i32, i32* %14
%41 = load i32, i32* %15
%42 = load i32, i32* %16
%43 = call i32 @maze_build_cell_walls(%struct.maze* %36, i32 %37, i32 %38, i32 %39, i32 %40, i32 %41, i32 %42)
%44 = load i32, i32* %13
store i32 %44, i32* %11
%45 = load i32, i32* %14
store i32 %45, i32* %12
%46 = load i32, i32* %15
store i32 %46, i32* %13
%47 = load i32, i32* %16
store i32 %47, i32* %14
br label %48
48: ; preds = %35, %24, %5
br label %49
49: ; preds = %79, %48
%50 = load %struct.maze*, %struct.maze** %6
%51 = load i32, i32* %11
%52 = load i32, i32* %12
%53 = load i32, i32* %13
%54 = load i32, i32* %14
%55 = call i32 @maze_choose_next_cell(%struct.maze* %50, i32 %51, i32 %52, i32 %53, i32 %54, i32* %15, i32* %16)
switch i32 %55, label %79 [
i32 0, label %56
i32 2, label %69
i32 1, label %78
]
56: ; preds = %49
%57 = load %struct.maze*, %struct.maze** %6
%58 = load i32, i32* %11
%59 = load i32, i32* %12
%60 = load i32, i32* %13
%61 = load i32, i32* %14
%62 = load i32, i32* %15
%63 = load i32, i32* %16
%64 = call i32 @maze_build_cell_walls(%struct.maze* %57, i32 %58, i32 %59, i32 %60, i32 %61, i32 %62, i32 %63)
%65 = load i32, i32* %13
store i32 %65, i32* %11
%66 = load i32, i32* %14
store i32 %66, i32* %12
%67 = load i32, i32* %15
store i32 %67, i32* %13
%68 = load i32, i32* %16
store i32 %68, i32* %14
br label %79
69: ; preds = %49
%70 = load %struct.maze*, %struct.maze** %6
%71 = load i32, i32* %11
%72 = load i32, i32* %12
%73 = load i32, i32* %13
%74 = load i32, i32* %14
%75 = load i32, i32* %11
%76 = load i32, i32* %12
%77 = call i32 @maze_build_cell_walls(%struct.maze* %70, i32 %71, i32 %72, i32 %73, i32 %74, i32 %75, i32 %76)
br label %78
78: ; preds = %49, %69
br label %80
79: ; preds = %49, %56
br label %49
80: ; preds = %78, %34
ret void
}

LLVM IR (-O2):
%struct.maze = type { i32 }
define void @maze_construct_segment(%struct.maze* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %6 to i8*
%9 = bitcast i32* %7 to i8*
%10 = icmp eq i32 %1, %3
%11 = icmp eq i32 %2, %4
%12 = and i1 %10, %11
br i1 %12, label %13, label %22
13: ; preds = %5
%14 = call i32 @maze_find_any_next_cell(%struct.maze* %0, i32 %1, i32 %2, i32* %6, i32* %7)
%15 = icmp eq i32 %14, 0
br i1 %15, label %40, label %16
16: ; preds = %13
%17 = load i32, i32* %6
%18 = load i32, i32* %7
%19 = call i32 @maze_build_cell_walls(%struct.maze* %0, i32 %1, i32 %2, i32 %1, i32 %2, i32 %17, i32 %18)
%20 = load i32, i32* %6
%21 = load i32, i32* %7
br label %22
22: ; preds = %16, %5
%23 = phi i32 [ %3, %5 ], [ %20, %16 ]
%24 = phi i32 [ %4, %5 ], [ %21, %16 ]
br label %25
25: ; preds = %22, %32
%26 = phi i32 [ %1, %22 ], [ %28, %32 ]
%27 = phi i32 [ %2, %22 ], [ %29, %32 ]
%28 = phi i32 [ %23, %22 ], [ %36, %32 ]
%29 = phi i32 [ %24, %22 ], [ %37, %32 ]
br label %30
30: ; preds = %25, %30
%31 = call i32 @maze_choose_next_cell(%struct.maze* %0, i32 %26, i32 %27, i32 %28, i32 %29, i32* %6, i32* %7)
switch i32 %31, label %30 [
i32 0, label %32
i32 2, label %38
i32 1, label %40
]
32: ; preds = %30
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = call i32 @maze_build_cell_walls(%struct.maze* %0, i32 %26, i32 %27, i32 %28, i32 %29, i32 %33, i32 %34)
%36 = load i32, i32* %6
%37 = load i32, i32* %7
br label %25
38: ; preds = %30
%39 = call i32 @maze_build_cell_walls(%struct.maze* %0, i32 %26, i32 %27, i32 %28, i32 %29, i32 %26, i32 %27)
br label %40
40: ; preds = %30, %38, %13
ret void
}