#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 *, ...);
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++];
      if (_val != 0) {
        sprintf(_str, "%3d", _val);
      } else {
        sprintf(_str, "   ");
      }
      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    1213 <disp_image+0xf3>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11f7 <disp_image+0xd7>
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)
movzbl -0x1d(%rbp),%eax
cmp    $0x0,%eax
je     119f <disp_image+0x7f>
lea    -0x25(%rbp),%rdi
movzbl -0x1d(%rbp),%edx
lea    0xe6d(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    11b1 <disp_image+0x91>
lea    -0x25(%rbp),%rdi
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
cmpl   $0x0,-0x18(%rbp)
jne    11d2 <disp_image+0xb2>
lea    -0x25(%rbp),%rsi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e4 <disp_image+0xc4>
lea    -0x25(%rbp),%rsi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e9 <disp_image+0xc9>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1153 <disp_image+0x33>
lea    0xe0e(%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    0xdf2(%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    $0x18,%rsp
mov    %esi,0x4(%rsp)
test   %esi,%esi
jle    1230 <disp_image+0x100>
mov    %edx,%r15d
mov    %rdi,%rbp
lea    -0x1(%r15),%eax
mov    %eax,(%rsp)
lea    0x8(%rsp),%rbx
lea    0xea1(%rip),%r13
xor    %r14d,%r14d
xor    %r12d,%r12d
mov    %r15,0x10(%rsp)
jmp    118e <disp_image+0x5e>
mov    0x10(%rsp),%r15
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r14d
cmp    0x4(%rsp),%r14d
je     1230 <disp_image+0x100>
test   %r15d,%r15d
jle    1175 <disp_image+0x45>
movslq %r12d,%r12
movzbl 0x0(%rbp,%r12,1),%edx
test   %edx,%edx
je     11c0 <disp_image+0x90>
mov    %rbx,%rdi
lea    0xe56(%rip),%rsi
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    11c8 <disp_image+0x98>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movl   $0x202020,0x8(%rsp)
add    $0x1,%r12
lea    0xe32(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%r15d
je     1170 <disp_image+0x40>
mov    (%rsp),%r15d
jmp    1213 <disp_image+0xe3>
nopl   0x0(%rax)
movl   $0x202020,0x8(%rsp)
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r12
add    $0xffffffff,%r15d
je     1170 <disp_image+0x40>
movzbl 0x0(%rbp,%r12,1),%edx
test   %edx,%edx
je     11f0 <disp_image+0xc0>
mov    %rbx,%rdi
lea    0xdd9(%rip),%rsi
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    11f8 <disp_image+0xc8>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x18,%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 = [4 x i8] c" \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [4 x i8] c" %s\00"
@.str.4 = [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 = %54, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %5
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %57
16: ; preds = %12
store i32 0, i32* %8
br label %17
17: ; preds = %49, %16
%18 = load i32, i32* %8
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %52
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 = load i8, i8* %10
%29 = zext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %21
%32 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%33 = load i8, i8* %10
%34 = zext i8 %33 to i32
%35 = call i32 (i8*, i8*, ...) @sprintf(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %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*, i8*, ...) @sprintf(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %36, %31
%40 = load i32, i32* %8
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %43)
br label %48
45: ; preds = %39
%46 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %45, %42
br label %49
49: ; preds = %48
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
br label %17
52: ; preds = %17
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %54
54: ; preds = %52
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %12
57: ; preds = %12
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%3d\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [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 %49
7: ; preds = %3
%8 = icmp sgt i32 %2, 0
%9 = bitcast [8 x i8]* %4 to i32*
%10 = icmp eq i32 %2, 1
br label %11
11: ; preds = %7, %44
%12 = phi i32 [ 0, %7 ], [ %47, %44 ]
%13 = phi i32 [ 0, %7 ], [ %45, %44 ]
br i1 %8, label %14, label %44
14: ; preds = %11
%15 = sext i32 %13 to i64
%16 = add nsw i64 %15, 1
%17 = getelementptr inbounds i8, i8* %0, i64 %15
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %14
%21 = zext i8 %18 to i32
%22 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %24
23: ; preds = %14
store i32 2105376, i32* %9
br label %24
24: ; preds = %23, %20
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
br i1 %10, label %41, label %26
26: ; preds = %24, %37
%27 = phi i64 [ %29, %37 ], [ %16, %24 ]
%28 = phi i32 [ %39, %37 ], [ 1, %24 ]
%29 = add nsw i64 %27, 1
%30 = getelementptr inbounds i8, i8* %0, i64 %27
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %26
%34 = zext i8 %31 to i32
%35 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %34)
br label %37
36: ; preds = %26
store i32 2105376, i32* %9
br label %37
37: ; preds = %36, %33
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%39 = add nuw nsw i32 %28, 1
%40 = icmp eq i32 %39, %2
br i1 %40, label %41, label %26
41: ; preds = %37, %24
%42 = phi i64 [ %16, %24 ], [ %29, %37 ]
%43 = trunc i64 %42 to i32
br label %44
44: ; preds = %41, %11
%45 = phi i32 [ %13, %11 ], [ %43, %41 ]
%46 = call i32 @putchar(i32 10)
%47 = add nuw nsw i32 %12, 1
%48 = icmp eq i32 %47, %1
br i1 %48, label %49, label %11
49: ; preds = %44, %3
%50 = call i32 @putchar(i32 10)
ret void
}