#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 */
void paint_fill_aux(size_t x, size_t y, char screen[x][y], size_t curr_x,
                    size_t curr_y, char original_color, char new_color) {
  if (screen[curr_x][curr_y] != original_color) {
    return;
  }
  screen[curr_x][curr_y] = new_color;
  if (curr_x > 0) {
    paint_fill_aux(x, y, screen, curr_x - 1, curr_y, original_color, new_color);
  }
  if (curr_x < x - 1) {
    paint_fill_aux(x, y, screen, curr_x + 1, curr_y, original_color, new_color);
  }
  if (curr_y > 0) {
    paint_fill_aux(x, y, screen, curr_x, curr_y - 1, original_color, new_color);
  }
  if (curr_y < y - 1) {
    paint_fill_aux(x, y, screen, curr_x, curr_y + 1, original_color, new_color);
  }
}


x86 assembly (clang, -O0):
<paint_fill_aux>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %r9b,%al
mov    0x10(%rbp),%r9b
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %al,-0x29(%rbp)
mov    -0x10(%rbp),%rcx
mov    %rcx,-0x38(%rbp)
mov    -0x18(%rbp),%rax
imul   -0x20(%rbp),%rcx
add    %rcx,%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x29(%rbp),%ecx
cmp    %ecx,%eax
je     1163 <paint_fill_aux+0x53>
jmp    1269 <paint_fill_aux+0x159>
mov    -0x38(%rbp),%rcx
mov    0x10(%rbp),%dl
mov    -0x18(%rbp),%rax
imul   -0x20(%rbp),%rcx
add    %rcx,%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
cmpq   $0x0,-0x20(%rbp)
jbe    11b3 <paint_fill_aux+0xa3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
mov    -0x28(%rbp),%r8
mov    -0x29(%rbp),%al
movsbl %al,%r9d
movsbl 0x10(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <paint_fill_aux@plt>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    11f3 <paint_fill_aux+0xe3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
add    $0x1,%rcx
mov    -0x28(%rbp),%r8
mov    -0x29(%rbp),%al
movsbl %al,%r9d
movsbl 0x10(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <paint_fill_aux@plt>
cmpq   $0x0,-0x28(%rbp)
jbe    1229 <paint_fill_aux+0x119>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
sub    $0x1,%r8
mov    -0x29(%rbp),%al
movsbl %al,%r9d
movsbl 0x10(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <paint_fill_aux@plt>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    1269 <paint_fill_aux+0x159>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
add    $0x1,%r8
mov    -0x29(%rbp),%al
movsbl %al,%r9d
movsbl 0x10(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <paint_fill_aux@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<paint_fill_aux>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rcx,%rbx
mov    %rdi,0x18(%rsp)
mov    %rcx,%rax
imul   %rsi,%rax
mov    %rdx,%rcx
mov    %rdx,0x20(%rsp)
lea    (%rdx,%rax,1),%rcx
mov    %r9d,0x14(%rsp)
cmp    %r9b,(%r8,%rcx,1)
jne    123d <paint_fill_aux+0x12d>
mov    %r8,%rbp
mov    %rsi,%r12
lea    -0x1(%rbx),%rcx
mov    %rcx,0x30(%rsp)
mov    0x18(%rsp),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x40(%rsp)
lea    0x1(%rbx),%rcx
mov    %rcx,0x28(%rsp)
lea    -0x1(%rsi),%rcx
mov    %rcx,0x38(%rsp)
mov    0x20(%rsp),%rcx
lea    (%rax,%rcx,1),%r13
add    $0x1,%r13
movsbl 0x80(%rsp),%r15d
movsbl 0x14(%rsp),%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x80(%rsp),%eax
mov    %al,-0x1(%r13,%rbp,1)
test   %rbx,%rbx
je     11d3 <paint_fill_aux+0xc3>
mov    %r15d,(%rsp)
mov    0x18(%rsp),%rdi
mov    %r12,%rsi
mov    0x20(%rsp),%rdx
mov    0x30(%rsp),%rcx
mov    %rbp,%r8
mov    %r14d,%r9d
call   1030 <paint_fill_aux@plt>
cmp    %rbx,0x40(%rsp)
jbe    11fb <paint_fill_aux+0xeb>
mov    %r15d,(%rsp)
mov    0x18(%rsp),%rdi
mov    %r12,%rsi
mov    0x20(%rsp),%rdx
mov    0x28(%rsp),%rcx
mov    %rbp,%r8
mov    %r14d,%r9d
call   1030 <paint_fill_aux@plt>
test   %rbp,%rbp
je     1220 <paint_fill_aux+0x110>
lea    -0x1(%rbp),%r8
mov    %r15d,(%rsp)
mov    0x18(%rsp),%rdi
mov    %r12,%rsi
mov    0x20(%rsp),%rdx
mov    %rbx,%rcx
mov    %r14d,%r9d
call   1030 <paint_fill_aux@plt>
cmp    %rbp,0x38(%rsp)
jbe    123d <paint_fill_aux+0x12d>
lea    0x1(%rbp),%rax
mov    0x14(%rsp),%ecx
cmp    %cl,0x0(%r13,%rbp,1)
mov    %rax,%rbp
je     11a0 <paint_fill_aux+0x90>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @paint_fill_aux(i64 %0, i64 %1, i8* %2, i64 %3, i64 %4, i8 signext %5, i8 signext %6) {
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i8
%14 = alloca i8
store i64 %0, i64* %8
store i64 %1, i64* %9
store i8* %2, i8** %10
store i64 %3, i64* %11
store i64 %4, i64* %12
store i8 %5, i8* %13
store i8 %6, i8* %14
%15 = load i64, i64* %8
%16 = load i64, i64* %9
%17 = load i8*, i8** %10
%18 = load i64, i64* %11
%19 = mul nsw i64 %18, %16
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i64, i64* %12
%22 = getelementptr inbounds i8, i8* %20, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = load i8, i8* %13
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %24, %26
br i1 %27, label %28, label %29
28: ; preds = %7
br label %88
29: ; preds = %7
%30 = load i8, i8* %14
%31 = load i8*, i8** %10
%32 = load i64, i64* %11
%33 = mul nsw i64 %32, %16
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i64, i64* %12
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8 %30, i8* %36
%37 = load i64, i64* %11
%38 = icmp ugt i64 %37, 0
br i1 %38, label %39, label %48
39: ; preds = %29
%40 = load i64, i64* %8
%41 = load i64, i64* %9
%42 = load i8*, i8** %10
%43 = load i64, i64* %11
%44 = sub i64 %43, 1
%45 = load i64, i64* %12
%46 = load i8, i8* %13
%47 = load i8, i8* %14
br label %48
48: ; preds = %39, %29
%49 = load i64, i64* %11
%50 = load i64, i64* %8
%51 = sub i64 %50, 1
%52 = icmp ult i64 %49, %51
br i1 %52, label %53, label %62
53: ; preds = %48
%54 = load i64, i64* %8
%55 = load i64, i64* %9
%56 = load i8*, i8** %10
%57 = load i64, i64* %11
%58 = add i64 %57, 1
%59 = load i64, i64* %12
%60 = load i8, i8* %13
%61 = load i8, i8* %14
br label %62
62: ; preds = %53, %48
%63 = load i64, i64* %12
%64 = icmp ugt i64 %63, 0
br i1 %64, label %65, label %74
65: ; preds = %62
%66 = load i64, i64* %8
%67 = load i64, i64* %9
%68 = load i8*, i8** %10
%69 = load i64, i64* %11
%70 = load i64, i64* %12
%71 = sub i64 %70, 1
%72 = load i8, i8* %13
%73 = load i8, i8* %14
br label %74
74: ; preds = %65, %62
%75 = load i64, i64* %12
%76 = load i64, i64* %9
%77 = sub i64 %76, 1
%78 = icmp ult i64 %75, %77
br i1 %78, label %79, label %88
79: ; preds = %74
%80 = load i64, i64* %8
%81 = load i64, i64* %9
%82 = load i8*, i8** %10
%83 = load i64, i64* %11
%84 = load i64, i64* %12
%85 = add i64 %84, 1
%86 = load i8, i8* %13
%87 = load i8, i8* %14
br label %88
88: ; preds = %28, %79, %74
ret void
}

LLVM IR (-O2):
define void @paint_fill_aux(i64 %0, i64 %1, i8* %2, i64 %3, i64 %4, i8 signext %5, i8 signext %6) {
%8 = mul nsw i64 %3, %1
%9 = getelementptr inbounds i8, i8* %2, i64 %8
%10 = getelementptr inbounds i8, i8* %9, i64 %4
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, %5
br i1 %12, label %13, label %37
13: ; preds = %7
%14 = icmp eq i64 %3, 0
%15 = add i64 %3, -1
%16 = add i64 %0, -1
%17 = icmp ugt i64 %16, %3
%18 = add nuw i64 %3, 1
%19 = add i64 %1, -1
br label %24
20: ; preds = %34
%21 = getelementptr inbounds i8, i8* %9, i64 %36
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, %5
br i1 %23, label %24, label %37
24: ; preds = %13, %20
%25 = phi i8* [ %10, %13 ], [ %21, %20 ]
%26 = phi i64 [ %4, %13 ], [ %36, %20 ]
store i8 %6, i8* %25
br i1 %14, label %28, label %27
27: ; preds = %24
tail call void @paint_fill_aux(i64 %0, i64 %1, i8* %2, i64 %15, i64 %26, i8 signext %5, i8 signext %6)
br label %28
28: ; preds = %27, %24
br i1 %17, label %29, label %30
29: ; preds = %28
tail call void @paint_fill_aux(i64 %0, i64 %1, i8* %2, i64 %18, i64 %26, i8 signext %5, i8 signext %6)
br label %30
30: ; preds = %29, %28
%31 = icmp eq i64 %26, 0
br i1 %31, label %34, label %32
32: ; preds = %30
%33 = add i64 %26, -1
tail call void @paint_fill_aux(i64 %0, i64 %1, i8* %2, i64 %3, i64 %33, i8 signext %5, i8 signext %6)
br label %34
34: ; preds = %32, %30
%35 = icmp ugt i64 %19, %26
%36 = add nuw i64 %26, 1
br i1 %35, label %20, label %37
37: ; preds = %34, %20, %7
ret void
}