#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 *, ...);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
void disp_image(unsigned char *image, int rows, int cols) {
  int _i, _j;
  unsigned char _val;
  char _str[8];
  for (_i = rows - 1; _i >= 0; _i--) {
    for (_j = 0; _j < cols; _j++) {
      _val = image[(_i * cols) + _j];
      sprintf(_str, "%3d", _val);
      if (_j == 0) {
        printf("%s", _str);
      } else {
        printf(" %s", _str);
      }
    }
    printf("\n");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<disp_image>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11e5 <disp_image+0xc5>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11c9 <disp_image+0xa9>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   -0x10(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
lea    -0x21(%rbp),%rdi
lea    0xe86(%rip),%rsi
movzbl -0x19(%rbp),%edx
call   1040 <sprintf@plt>
cmpl   $0x0,-0x18(%rbp)
jne    11a4 <disp_image+0x84>
lea    -0x21(%rbp),%rsi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b6 <disp_image+0x96>
lea    -0x21(%rbp),%rsi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bb <disp_image+0x9b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114c <disp_image+0x2c>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    113b <disp_image+0x1b>
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disp_image>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edx,0x4(%rsp)
mov    %rdi,0x10(%rsp)
test   %esi,%esi
jle    123b <disp_image+0x10b>
mov    %esi,%ecx
movslq 0x4(%rsp),%rax
mov    %eax,%r12d
mov    %rcx,0x8(%rsp)
lea    -0x1(%rcx),%r15
imul   %rax,%r15
add    0x10(%rsp),%r15
mov    %rax,0x18(%rsp)
neg    %rax
mov    %rax,0x20(%rsp)
lea    0xe81(%rip),%rbx
lea    0x30(%rsp),%rbp
lea    0xe79(%rip),%r13
jmp    11ab <disp_image+0x7b>
nopl   (%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    0x20(%rsp),%r15
cmpq   $0x1,0x28(%rsp)
jle    123b <disp_image+0x10b>
mov    0x8(%rsp),%rax
mov    %rax,0x28(%rsp)
add    $0xffffffffffffffff,%rax
mov    %rax,0x8(%rsp)
cmpl   $0x0,0x4(%rsp)
jle    1190 <disp_image+0x60>
mov    0x8(%rsp),%rax
imul   0x18(%rsp),%rax
mov    0x10(%rsp),%rcx
movzbl (%rcx,%rax,1),%edx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <sprintf@plt>
lea    0xe1a(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x1,0x4(%rsp)
je     1190 <disp_image+0x60>
mov    $0x1,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%r15,%r14,1),%edx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <sprintf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r14
cmp    %r14,%r12
jne    1210 <disp_image+0xe0>
jmp    1190 <disp_image+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%3d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [4 x i8] c" %s\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @disp_image(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca [8 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %5
%12 = sub nsw i32 %11, 1
store i32 %12, i32* %7
br label %13
13: ; preds = %48, %3
%14 = load i32, i32* %7
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %51
16: ; preds = %13
store i32 0, i32* %8
br label %17
17: ; preds = %43, %16
%18 = load i32, i32* %8
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %46
21: ; preds = %17
%22 = load i8*, i8** %4
%23 = load i32, i32* %7
%24 = load i32, i32* %6
%25 = mul nsw i32 %23, %24
%26 = load i32, i32* %8
%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
store i8 %30, i8* %9
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%32 = load i8, i8* %9
%33 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 zeroext %32)
%34 = load i32, i32* %8
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %21
%37 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %37)
br label %42
39: ; preds = %21
%40 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %39, %36
br label %43
43: ; preds = %42
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %17
46: ; preds = %17
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %46
%49 = load i32, i32* %7
%50 = add nsw i32 %49, -1
store i32 %50, i32* %7
br label %13
51: ; preds = %13
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

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