#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*/ paint_fill(size_t, size_t, char **, size_t, size_t, char);
int /*<<< orphan*/ print_screen(size_t, size_t, char **);
int /*<<< orphan*/ printf(char *);
int scanf(char *, ...);
int main(void) {
  printf("Enter screen size (X x Y), an each cell's color.\n");
  size_t x, y;
  scanf("%zu%zu", &x, &y);
  char screen[x][y];
  size_t i;
  for (i = 0; i < x; i++) {
    size_t j;
    for (j = 0; j < y; j++) {
      scanf(" %c", &screen[i][j]);
    }
  }
  printf("Now enter your queries. The query format is: X Y C, "
         "where X and Y indicate the target cell, and C the new color.\n");
  size_t px, py;
  char new_color;
  while (scanf("%zu%zu %c", &px, &py, &new_color) == 3) {
    printf("Before:\n");
    print_screen(x, y, screen);
    printf("After:\n");
    paint_fill(x, y, screen, px, py, new_color);
    print_screen(x, y, screen);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
lea    0xed0(%rip),%rdi
xor    %eax,%eax
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <scanf@plt>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x20(%rbp)
mov    %rcx,%rsi
imul   %rax,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x60(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x28(%rbp)
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    121d <main+0xdd>
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1207 <main+0xc7>
mov    -0x60(%rbp),%rsi
mov    -0x68(%rbp),%rax
imul   -0x38(%rbp),%rax
add    %rax,%rsi
add    -0x40(%rbp),%rsi
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    11c6 <main+0x86>
jmp    120c <main+0xcc>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11b0 <main+0x70>
lea    0xe15(%rip),%rdi
call   1040 <printf@plt>
lea    0xe7b(%rip),%rdi
lea    -0x48(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x51(%rbp),%rcx
mov    $0x0,%al
call   1060 <scanf@plt>
cmp    $0x3,%eax
jne    12a9 <main+0x169>
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
mov    -0x60(%rbp),%rdx
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <print_screen@plt>
lea    0xe4e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x60(%rbp),%rdx
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x48(%rbp),%rcx
mov    -0x50(%rbp),%r8
movsbl -0x51(%rbp),%r9d
call   1030 <paint_fill@plt>
mov    -0x60(%rbp),%rdx
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <print_screen@plt>
jmp    1229 <main+0xe9>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9c(%rip),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x38(%rbp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %rsp,-0x58(%rbp)
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%rax
mov    %rcx,-0x60(%rbp)
imul   %rcx,%rax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    -0x40(%rbp),%rax
test   %rax,%rax
je     1201 <main+0xc1>
mov    -0x38(%rbp),%rcx
lea    0xe61(%rip),%r15
mov    %r13,%rbx
xor    %r12d,%r12d
jmp    11cf <main+0x8f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ecx,%ecx
add    $0x1,%r12
add    -0x60(%rbp),%rbx
cmp    %rax,%r12
jae    1201 <main+0xc1>
test   %rcx,%rcx
je     11c0 <main+0x80>
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
lea    (%rbx,%r14,1),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%r14
mov    -0x38(%rbp),%rcx
cmp    %rcx,%r14
jb     11e0 <main+0xa0>
mov    -0x40(%rbp),%rax
jmp    11c2 <main+0x82>
lea    0xe3a(%rip),%rdi
call   1030 <puts@plt>
lea    0xdf3(%rip),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x48(%rbp),%rdx
lea    -0x29(%rbp),%rcx
xor    %eax,%eax
call   1060 <scanf@plt>
cmp    $0x3,%eax
jne    12bd <main+0x17d>
lea    0xdd0(%rip),%r12
lea    -0x50(%rbp),%rbx
lea    -0x48(%rbp),%r14
lea    -0x29(%rbp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %r13,%rdx
call   1050 <print_screen@plt>
lea    0xe48(%rip),%rdi
call   1030 <puts@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%r8
movsbl -0x29(%rbp),%r9d
mov    %r13,%rdx
call   1040 <paint_fill@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %r13,%rdx
call   1050 <print_screen@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1060 <scanf@plt>
cmp    $0x3,%eax
je     1250 <main+0x110>
mov    -0x58(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"Enter screen size (X x Y), an each cell's color.\0A\00"
@.str.1 = [7 x i8] c"%zu%zu\00"
@.str.2 = [4 x i8] c" %c\00"
@.str.3 = [114 x i8] c"Now enter your queries. The query format is: X Y C, where X and Y indicate the target cell, and C the new color.\0A\00"
@.str.4 = [10 x i8] c"%zu%zu %c\00"
@.str.5 = [9 x i8] c"Before:\0A\00"
@.str.6 = [8 x i8] c"After:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8
store i32 0, i32* %1
%12 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64* %2, i64* %3)
%14 = load i64, i64* %2
%15 = load i64, i64* %3
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %4
%17 = mul nuw i64 %14, %15
%18 = alloca i8, i64 %17
store i64 %14, i64* %5
store i64 %15, i64* %6
store i64 0, i64* %7
br label %19
19: ; preds = %39, %0
%20 = load i64, i64* %7
%21 = load i64, i64* %2
%22 = icmp ult i64 %20, %21
br i1 %22, label %23, label %42
23: ; preds = %19
store i64 0, i64* %8
br label %24
24: ; preds = %35, %23
%25 = load i64, i64* %8
%26 = load i64, i64* %3
%27 = icmp ult i64 %25, %26
br i1 %27, label %28, label %38
28: ; preds = %24
%29 = load i64, i64* %7
%30 = mul nsw i64 %29, %15
%31 = getelementptr inbounds i8, i8* %18, i64 %30
%32 = load i64, i64* %8
%33 = getelementptr inbounds i8, i8* %31, i64 %32
%34 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %28
%36 = load i64, i64* %8
%37 = add i64 %36, 1
store i64 %37, i64* %8
br label %24
38: ; preds = %24
br label %39
39: ; preds = %38
%40 = load i64, i64* %7
%41 = add i64 %40, 1
store i64 %41, i64* %7
br label %19
42: ; preds = %19
%43 = call i32 @printf(i8* getelementptr inbounds ([114 x i8], [114 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %47, %42
%45 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i64* %9, i64* %10, i8* %11)
%46 = icmp eq i32 %45, 3
br i1 %46, label %47, label %65
47: ; preds = %44
%48 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%49 = load i64, i64* %2
%50 = load i64, i64* %3
%51 = bitcast i8* %18 to i8**
%52 = call i32 @print_screen(i64 %49, i64 %50, i8** %51)
%53 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%54 = load i64, i64* %2
%55 = load i64, i64* %3
%56 = bitcast i8* %18 to i8**
%57 = load i64, i64* %9
%58 = load i64, i64* %10
%59 = load i8, i8* %11
%60 = call i32 @paint_fill(i64 %54, i64 %55, i8** %56, i64 %57, i64 %58, i8 signext %59)
%61 = load i64, i64* %2
%62 = load i64, i64* %3
%63 = bitcast i8* %18 to i8**
%64 = call i32 @print_screen(i64 %61, i64 %62, i8** %63)
br label %44
65: ; preds = %44
store i32 0, i32* %1
%66 = load i8*, i8** %4
%67 = load i32, i32* %1
ret i32 %67
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"%zu%zu\00"
@.str.2 = [4 x i8] c" %c\00"
@.str.4 = [10 x i8] c"%zu%zu %c\00"
@str = [49 x i8] c"Enter screen size (X x Y), an each cell's color.\00"
@str.7 = [113 x i8] c"Now enter your queries. The query format is: X Y C, where X and Y indicate the target cell, and C the new color.\00"
@str.8 = [8 x i8] c"Before:\00"
@str.9 = [7 x i8] c"After:\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%7 = bitcast i64* %1 to i8*
%8 = bitcast i64* %2 to i8*
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64* %1, i64* %2)
%10 = load i64, i64* %1
%11 = load i64, i64* %2
%12 = call i8* @llvm.stacksave()
%13 = mul nuw i64 %11, %10
%14 = alloca i8, i64 %13
%15 = load i64, i64* %1
%16 = icmp eq i64 %15, 0
br i1 %16, label %41, label %17
17: ; preds = %0
%18 = load i64, i64* %2
br label %19
19: ; preds = %17, %36
%20 = phi i64 [ %37, %36 ], [ %15, %17 ]
%21 = phi i64 [ %38, %36 ], [ %18, %17 ]
%22 = phi i64 [ %39, %36 ], [ 0, %17 ]
%23 = icmp eq i64 %21, 0
br i1 %23, label %36, label %24
24: ; preds = %19
%25 = mul nsw i64 %22, %11
%26 = getelementptr inbounds i8, i8* %14, i64 %25
br label %27
27: ; preds = %24, %27
%28 = phi i64 [ 0, %24 ], [ %31, %27 ]
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = add nuw i64 %28, 1
%32 = load i64, i64* %2
%33 = icmp ult i64 %31, %32
br i1 %33, label %27, label %34
34: ; preds = %27
%35 = load i64, i64* %1
br label %36
36: ; preds = %34, %19
%37 = phi i64 [ %35, %34 ], [ %20, %19 ]
%38 = phi i64 [ %32, %34 ], [ 0, %19 ]
%39 = add nuw i64 %22, 1
%40 = icmp ult i64 %39, %37
br i1 %40, label %19, label %41
41: ; preds = %36, %0
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([113 x i8], [113 x i8]* @str.7, i64 0, i64 0))
%43 = bitcast i64* %3 to i8*
%44 = bitcast i64* %4 to i8*
%45 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i64* %3, i64* %4, i8* %5)
%46 = icmp eq i32 %45, 3
br i1 %46, label %47, label %66
47: ; preds = %41
%48 = bitcast i8* %14 to i8**
br label %49
49: ; preds = %47, %49
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.8, i64 0, i64 0))
%51 = load i64, i64* %1
%52 = load i64, i64* %2
%53 = call i32 @print_screen(i64 %51, i64 %52, i8** %48)
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.9, i64 0, i64 0))
%55 = load i64, i64* %1
%56 = load i64, i64* %2
%57 = load i64, i64* %3
%58 = load i64, i64* %4
%59 = load i8, i8* %5
%60 = call i32 @paint_fill(i64 %55, i64 %56, i8** %48, i64 %57, i64 %58, i8 signext %59)
%61 = load i64, i64* %1
%62 = load i64, i64* %2
%63 = call i32 @print_screen(i64 %61, i64 %62, i8** %48)
%64 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i64* %3, i64* %4, i8* %5)
%65 = icmp eq i32 %64, 3
br i1 %65, label %49, label %66
66: ; preds = %49, %41
ret i32 0
}