#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*/ printf(char *, ...);
void print_sandpile(int rows, int cols, int sandpile[][cols]) {
  char symbols[] = " .*#456789000000000000000000";
  for (int i = 0; i < rows; i++) {
    printf("%c%c", symbols[sandpile[i][0]], symbols[sandpile[i][0]]);
    for (int j = 1; j < cols; j++) {
      printf("%c%c", symbols[sandpile[i][j]], symbols[sandpile[i][j]]);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<print_sandpile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x40(%rbp)
mov    0xed0(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xecd(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec8(%rip),%eax
mov    %eax,-0x18(%rbp)
mov    0xec3(%rip),%al
mov    %al,-0x14(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    123a <print_sandpile+0x12a>
mov    -0x40(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
imul   %rdx,%rcx
movslq (%rax,%rcx,4),%rax
movsbl -0x30(%rbp,%rax,1),%esi
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
imul   %rdx,%rcx
movslq (%rax,%rcx,4),%rax
movsbl -0x30(%rbp,%rax,1),%edx
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    121e <print_sandpile+0x10e>
mov    -0x40(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
imul   %rdx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x38(%rbp),%rcx
movslq (%rax,%rcx,4),%rax
movsbl -0x30(%rbp,%rax,1),%esi
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
imul   %rdx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x38(%rbp),%rcx
movslq (%rax,%rcx,4),%rax
movsbl -0x30(%rbp,%rax,1),%edx
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11b2 <print_sandpile+0xa2>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1163 <print_sandpile+0x53>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_sandpile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,0x10(%rsp)
mov    %esi,0xc(%rsp)
test   %edi,%edi
jle    11e0 <print_sandpile+0xc0>
mov    0xc(%rsp),%ebp
mov    %edi,%eax
mov    %rax,0x20(%rsp)
lea    0x0(,%rbp,4),%rax
mov    %rax,0x18(%rsp)
lea    0xea2(%rip),%r14
lea    0xeb8(%rip),%rbx
mov    0x10(%rsp),%r15
xor    %r12d,%r12d
jmp    118a <print_sandpile+0x6a>
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r12
add    0x18(%rsp),%r15
cmp    0x20(%rsp),%r12
je     11e0 <print_sandpile+0xc0>
mov    %r12,%rax
imul   %rbp,%rax
mov    0x10(%rsp),%rcx
movslq (%rcx,%rax,4),%rax
movsbl (%rax,%r14,1),%edx
mov    %rbx,%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x2,0xc(%rsp)
jl     1170 <print_sandpile+0x50>
mov    $0x1,%r13d
nopl   0x0(%rax,%rax,1)
movslq (%r15,%r13,4),%rax
movsbl (%rax,%r14,1),%edx
mov    %rbx,%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r13
cmp    %r13,%rbp
jne    11c0 <print_sandpile+0xa0>
jmp    1170 <print_sandpile+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.print_sandpile.symbols = [29 x i8] c" .*\00"
@.str = [5 x i8] c"%c%c\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @print_sandpile(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca [29 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%10 = load i32, i32* %5
%11 = zext i32 %10 to i64
%12 = bitcast [29 x i8]* %7 to i8*
store i32 0, i32* %8
br label %13
13: ; preds = %78, %3
%14 = load i32, i32* %8
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %81
17: ; preds = %13
%18 = load i32*, i32** %6
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = mul nsw i64 %20, %11
%22 = getelementptr inbounds i32, i32* %18, i64 %21
%23 = getelementptr inbounds i32, i32* %22, i64 0
%24 = load i32, i32* %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [29 x i8], [29 x i8]* %7, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = load i32*, i32** %6
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = mul nsw i64 %31, %11
%33 = getelementptr inbounds i32, i32* %29, i64 %32
%34 = getelementptr inbounds i32, i32* %33, i64 0
%35 = load i32, i32* %34
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [29 x i8], [29 x i8]* %7, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %28, i32 %39)
store i32 1, i32* %9
br label %41
41: ; preds = %73, %17
%42 = load i32, i32* %9
%43 = load i32, i32* %5
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %76
45: ; preds = %41
%46 = load i32*, i32** %6
%47 = load i32, i32* %8
%48 = sext i32 %47 to i64
%49 = mul nsw i64 %48, %11
%50 = getelementptr inbounds i32, i32* %46, i64 %49
%51 = load i32, i32* %9
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %50, i64 %52
%54 = load i32, i32* %53
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [29 x i8], [29 x i8]* %7, i64 0, i64 %55
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = load i32*, i32** %6
%60 = load i32, i32* %8
%61 = sext i32 %60 to i64
%62 = mul nsw i64 %61, %11
%63 = getelementptr inbounds i32, i32* %59, i64 %62
%64 = load i32, i32* %9
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %63, i64 %65
%67 = load i32, i32* %66
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [29 x i8], [29 x i8]* %7, i64 0, i64 %68
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %58, i32 %71)
br label %73
73: ; preds = %45
%74 = load i32, i32* %9
%75 = add nsw i32 %74, 1
store i32 %75, i32* %9
br label %41
76: ; preds = %41
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %78
78: ; preds = %76
%79 = load i32, i32* %8
%80 = add nsw i32 %79, 1
store i32 %80, i32* %8
br label %13
81: ; preds = %13
ret void
}

LLVM IR (-O2):
@__const.print_sandpile.symbols = [29 x i8] c" .*\00"
@.str = [5 x i8] c"%c%c\00"
define void @print_sandpile(i32 %0, i32 %1, i32* nocapture %2) {
%4 = zext i32 %1 to i64
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = icmp sgt i32 %1, 1
%8 = zext i32 %0 to i64
br label %10
9: ; preds = %20, %3
ret void
10: ; preds = %6, %20
%11 = phi i64 [ 0, %6 ], [ %22, %20 ]
%12 = mul nuw nsw i64 %11, %4
%13 = getelementptr inbounds i32, i32* %2, i64 %12
%14 = load i32, i32* %13
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [29 x i8], [29 x i8]* @__const.print_sandpile.symbols, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %18)
br i1 %7, label %24, label %20
20: ; preds = %24, %10
%21 = tail call i32 @putchar(i32 10)
%22 = add nuw nsw i64 %11, 1
%23 = icmp eq i64 %22, %8
br i1 %23, label %9, label %10
24: ; preds = %10, %24
%25 = phi i64 [ %33, %24 ], [ 1, %10 ]
%26 = getelementptr inbounds i32, i32* %13, i64 %25
%27 = load i32, i32* %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [29 x i8], [29 x i8]* @__const.print_sandpile.symbols, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %31, i32 %31)
%33 = add nuw nsw i64 %25, 1
%34 = icmp eq i64 %33, %4
br i1 %34, label %20, label %24
}