#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 dump_canvas(char *canvas, int width, int height) {
  int i, j;
  printf("width=%d height=%d\n", width, height);
  for (i = 0; i < width; i++) {
    for (j = 0; j < height; j++) {
      printf("%d ", canvas[j * width + i]);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<dump_canvas>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a9 <dump_canvas+0x99>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    118d <dump_canvas+0x7d>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
imul   -0xc(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1150 <dump_canvas+0x40>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113d <dump_canvas+0x2d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_canvas>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xec6(%rip),%rdi
mov    %edx,0xc(%rsp)
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    11a9 <dump_canvas+0x89>
mov    %ebp,%ebx
mov    0xc(%rsp),%eax
mov    %rax,0x10(%rsp)
lea    0xeb9(%rip),%rbp
xor    %r13d,%r13d
jmp    1177 <dump_canvas+0x57>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r13
add    $0x1,%r14
cmp    %rbx,%r13
je     11a9 <dump_canvas+0x89>
cmpl   $0x0,0xc(%rsp)
jle    1160 <dump_canvas+0x40>
mov    0x10(%rsp),%r12
mov    %r14,%r15
cs nopw 0x0(%rax,%rax,1)
movsbl (%r15),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    %rbx,%r15
add    $0xffffffffffffffff,%r12
jne    1190 <dump_canvas+0x70>
jmp    1160 <dump_canvas+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"width=%d height=%d\0A\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @dump_canvas(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
store i32 0, i32* %7
br label %12
12: ; preds = %38, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %5
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %41
16: ; preds = %12
store i32 0, i32* %8
br label %17
17: ; preds = %33, %16
%18 = load i32, i32* %8
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %36
21: ; preds = %17
%22 = load i8*, i8** %4
%23 = load i32, i32* %8
%24 = load i32, i32* %5
%25 = mul nsw i32 %23, %24
%26 = load i32, i32* %7
%27 = add nsw i32 %25, %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %22, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %21
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %17
36: ; preds = %17
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %12
41: ; preds = %12
ret void
}

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