#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, _k = 0;
  unsigned char _val;
  char _str[8];
  for (_i = 0; _i < rows; _i++) {
    for (_j = 0; _j < cols; _j++) {
      _val = image[_k++];
      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)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ed <disp_image+0xcd>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11d1 <disp_image+0xb1>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
lea    -0x25(%rbp),%rdi
lea    0xe7e(%rip),%rsi
movzbl -0x1d(%rbp),%edx
call   1040 <sprintf@plt>
cmpl   $0x0,-0x18(%rbp)
jne    11ac <disp_image+0x8c>
lea    -0x25(%rbp),%rsi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11be <disp_image+0x9e>
lea    -0x25(%rbp),%rsi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c3 <disp_image+0xa3>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1153 <disp_image+0x33>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1140 <disp_image+0x20>
lea    0xe14(%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    $0x28,%rsp
mov    %esi,0x10(%rsp)
test   %esi,%esi
jle    120c <disp_image+0xdc>
mov    %edx,%r13d
mov    %rdi,%r14
lea    -0x1(%r13),%eax
mov    %eax,0xc(%rsp)
lea    0xea1(%rip),%r12
lea    0x20(%rsp),%rbx
xor    %ebp,%ebp
xor    %r15d,%r15d
mov    %r13,0x18(%rsp)
jmp    1192 <disp_image+0x62>
mov    %r12,%rbp
mov    0x18(%rsp),%r13
mov    %rbp,%r12
mov    0x14(%rsp),%ebp
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
cmp    0x10(%rsp),%ebp
je     120c <disp_image+0xdc>
test   %r13d,%r13d
jle    117f <disp_image+0x4f>
movslq %r15d,%r15
movzbl (%r14,%r15,1),%edx
add    $0x1,%r15
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <sprintf@plt>
lea    0xe50(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%r13d
mov    %ebp,0x14(%rsp)
je     1170 <disp_image+0x40>
mov    0xc(%rsp),%r13d
mov    %r12,%rbp
lea    0xe2c(%rip),%r12
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%r15,1),%edx
add    $0x1,%r15
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <sprintf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%r13d
jne    11e0 <disp_image+0xb0>
jmp    1173 <disp_image+0x43>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x28,%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 i32
%10 = alloca i8
%11 = alloca [8 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %9
store i32 0, i32* %7
br label %12
12: ; preds = %45, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %5
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %48
16: ; preds = %12
store i32 0, i32* %8
br label %17
17: ; preds = %40, %16
%18 = load i32, i32* %8
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %43
21: ; preds = %17
%22 = load i8*, i8** %4
%23 = load i32, i32* %9
%24 = add nsw i32 %23, 1
store i32 %24, i32* %9
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = load i8, i8* %26
store i8 %27, i8* %10
%28 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%29 = load i8, i8* %10
%30 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 zeroext %29)
%31 = load i32, i32* %8
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %21
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %34)
br label %39
36: ; preds = %21
%37 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %36, %33
br label %40
40: ; preds = %39
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %17
43: ; preds = %17
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %45
45: ; preds = %43
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %12
48: ; preds = %12
%49 = 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 %38
7: ; preds = %3
%8 = icmp sgt i32 %2, 0
%9 = icmp eq i32 %2, 1
br label %10
10: ; preds = %7, %33
%11 = phi i32 [ 0, %7 ], [ %36, %33 ]
%12 = phi i32 [ 0, %7 ], [ %34, %33 ]
br i1 %8, label %13, label %33
13: ; preds = %10
%14 = sext i32 %12 to i64
%15 = add nsw i64 %14, 1
%16 = getelementptr inbounds i8, i8* %0, i64 %14
%17 = load i8, i8* %16
%18 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 zeroext %17)
%19 = 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 %9, label %30, label %20
20: ; preds = %13, %20
%21 = phi i64 [ %23, %20 ], [ %15, %13 ]
%22 = phi i32 [ %28, %20 ], [ 1, %13 ]
%23 = add nsw i64 %21, 1
%24 = getelementptr inbounds i8, i8* %0, i64 %21
%25 = load i8, i8* %24
%26 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 zeroext %25)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%28 = add nuw nsw i32 %22, 1
%29 = icmp eq i32 %28, %2
br i1 %29, label %30, label %20
30: ; preds = %20, %13
%31 = phi i64 [ %15, %13 ], [ %23, %20 ]
%32 = trunc i64 %31 to i32
br label %33
33: ; preds = %30, %10
%34 = phi i32 [ %12, %10 ], [ %32, %30 ]
%35 = call i32 @putchar(i32 10)
%36 = add nuw nsw i32 %11, 1
%37 = icmp eq i32 %36, %1
br i1 %37, label %38, label %10
38: ; preds = %33, %3
%39 = call i32 @putchar(i32 10)
ret void
}