#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*/ putchar(char);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char const *);
char *strrchr(char const *, char);
void print_array(const char *name, unsigned char *data, int bytes,
                 unsigned int width, unsigned int height) {
  char buffer[128];
  char *ptr;
  int i, j;
  ptr = strrchr(name, '/');
  if (ptr)
    name = ptr;
  while (*name == '.')
    ++name;
  strcpy(buffer, name);
  ptr = strchr(buffer, '.');
  if (ptr)
    *ptr = '\0';
  printf("/* SIZE %ux%u */\n", width, height);
  printf("static const unsigned char %s[ %d ] =\n{\n", buffer, bytes);
  for (j = 0, i = 0; i < bytes; ++i, ++data) {
    if (*data > 077) {
      printf("0x%X", *data);
      j += 4;
    } else if (*data > 007) {
      printf("0%d%d", ((*data) >> 3 & 007), (*data) & 007);
      j += 3;
    } else {
      printf("%d", *data);
      j += 1;
    }
    if ((i + 1) < bytes) {
      putchar(',');
      ++j;
    }
    if ((j + 5) >= 80) {
      j = 0;
      putchar('\n');
    }
  }
  printf("\n};\n");
}


x86 assembly (clang, -O0):
<print_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
je     119b <print_array+0x4b>
mov    -0xa8(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a0 <print_array+0x50>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11c1 <print_array+0x71>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11a0 <print_array+0x50>
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0xa0(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
je     1201 <print_array+0xb1>
mov    -0xa8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xa0(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0xb0(%rbp)
movl   $0x0,-0xac(%rbp)
mov    -0xac(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1371 <print_array+0x221>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x3f,%eax
jle    1289 <print_array+0x139>
mov    -0x10(%rbp),%rax
movzbl (%rax),%esi
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xb0(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0xb0(%rbp)
jmp    12fb <print_array+0x1ab>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x7,%eax
jle    12d2 <print_array+0x182>
mov    -0x10(%rbp),%rax
movzbl (%rax),%esi
sar    $0x3,%esi
and    $0x7,%esi
mov    -0x10(%rbp),%rax
movzbl (%rax),%edx
and    $0x7,%edx
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xb0(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0xb0(%rbp)
jmp    12f6 <print_array+0x1a6>
mov    -0x10(%rbp),%rax
movzbl (%rax),%esi
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xb0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb0(%rbp)
jmp    12fb <print_array+0x1ab>
mov    -0xac(%rbp),%eax
add    $0x1,%eax
cmp    -0x14(%rbp),%eax
jge    1326 <print_array+0x1d6>
mov    $0x2c,%edi
call   1030 <putchar@plt>
mov    -0xb0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb0(%rbp)
mov    -0xb0(%rbp),%eax
add    $0x5,%eax
cmp    $0x50,%eax
jl     134c <print_array+0x1fc>
movl   $0x0,-0xb0(%rbp)
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1351 <print_array+0x201>
mov    -0xac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xac(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1241 <print_array+0xf1>
lea    0xcce(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %r8d,%r15d
mov    %ecx,%r12d
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%rbp
mov    $0x2f,%esi
call   1080 <strrchr@plt>
test   %rax,%rax
cmove  %rbp,%rax
add    $0xffffffffffffffff,%rax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x2e,0x1(%rax)
lea    0x1(%rax),%rax
je     11a0 <print_array+0x40>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
mov    $0x2e,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11cd <print_array+0x6d>
movb   $0x0,(%rax)
lea    0xe2c(%rip),%rdi
mov    %r12d,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe2a(%rip),%rdi
mov    %rsp,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1070 <printf@plt>
test   %ebx,%ebx
jle    12bb <print_array+0x15b>
mov    %ebx,%ebp
lea    0xe36(%rip),%r15
xor    %r12d,%r12d
xor    %r13d,%r13d
jmp    121d <print_array+0xbd>
nopl   (%rax)
add    $0x1,%r12
cmp    %r12d,%ebp
je     12bb <print_array+0x15b>
movzbl (%r14,%r12,1),%edx
cmp    $0x40,%edx
jb     1240 <print_array+0xe0>
mov    %r15,%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x4,%eax
jmp    1285 <print_array+0x125>
nopw   0x0(%rax,%rax,1)
cmp    $0x8,%dl
jb     1270 <print_array+0x110>
mov    %edx,%esi
shr    $0x3,%esi
and    $0x7,%esi
and    $0x7,%edx
lea    0xde9(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x3,%eax
jmp    1285 <print_array+0x125>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xdcc(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%eax
add    %eax,%r13d
lea    0x1(%r12),%eax
cmp    %ebx,%eax
jge    129f <print_array+0x13f>
mov    $0x2c,%edi
call   1030 <putchar@plt>
add    $0x1,%r13d
cmp    $0x4b,%r13d
jl     1210 <print_array+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %r13d,%r13d
jmp    1210 <print_array+0xb0>
lea    0xd84(%rip),%rdi
call   1050 <puts@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"/* SIZE %ux%u */\0A\00"
@.str.1 = [41 x i8] c"static const unsigned char %s[ %d ] =\0A{\0A\00"
@.str.2 = [5 x i8] c"0x%X\00"
@.str.3 = [6 x i8] c"0%d%d\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [5 x i8] c"\0A};\0A\00"
define void @print_array(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [128 x i8]
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%15 = load i8*, i8** %6
%16 = call i8* @strrchr(i8* %15, i8 signext 47)
store i8* %16, i8** %12
%17 = load i8*, i8** %12
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %5
%20 = load i8*, i8** %12
store i8* %20, i8** %6
br label %21
21: ; preds = %19, %5
br label %22
22: ; preds = %27, %21
%23 = load i8*, i8** %6
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 46
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i8*, i8** %6
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %6
br label %22
30: ; preds = %22
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%32 = load i8*, i8** %6
%33 = call i32 @strcpy(i8* %31, i8* %32)
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%35 = call i8* @strchr(i8* %34, i8 signext 46)
store i8* %35, i8** %12
%36 = load i8*, i8** %12
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %40
38: ; preds = %30
%39 = load i8*, i8** %12
store i8 0, i8* %39
br label %40
40: ; preds = %38, %30
%41 = load i32, i32* %9
%42 = load i32, i32* %10
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %41, i32 %42)
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%45 = load i32, i32* %8
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %44, i32 %45)
store i32 0, i32* %14
store i32 0, i32* %13
br label %47
47: ; preds = %105, %40
%48 = load i32, i32* %13
%49 = load i32, i32* %8
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %110
51: ; preds = %47
%52 = load i8*, i8** %7
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = icmp sgt i32 %54, 63
br i1 %55, label %56, label %63
56: ; preds = %51
%57 = load i8*, i8** %7
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %59)
%61 = load i32, i32* %14
%62 = add nsw i32 %61, 4
store i32 %62, i32* %14
br label %89
63: ; preds = %51
%64 = load i8*, i8** %7
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = icmp sgt i32 %66, 7
br i1 %67, label %68, label %81
68: ; preds = %63
%69 = load i8*, i8** %7
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = ashr i32 %71, 3
%73 = and i32 %72, 7
%74 = load i8*, i8** %7
%75 = load i8, i8* %74
%76 = zext i8 %75 to i32
%77 = and i32 %76, 7
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %73, i32 %77)
%79 = load i32, i32* %14
%80 = add nsw i32 %79, 3
store i32 %80, i32* %14
br label %88
81: ; preds = %63
%82 = load i8*, i8** %7
%83 = load i8, i8* %82
%84 = zext i8 %83 to i32
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %84)
%86 = load i32, i32* %14
%87 = add nsw i32 %86, 1
store i32 %87, i32* %14
br label %88
88: ; preds = %81, %68
br label %89
89: ; preds = %88, %56
%90 = load i32, i32* %13
%91 = add nsw i32 %90, 1
%92 = load i32, i32* %8
%93 = icmp slt i32 %91, %92
br i1 %93, label %94, label %98
94: ; preds = %89
%95 = call i32 @putchar(i8 signext 44)
%96 = load i32, i32* %14
%97 = add nsw i32 %96, 1
store i32 %97, i32* %14
br label %98
98: ; preds = %94, %89
%99 = load i32, i32* %14
%100 = add nsw i32 %99, 5
%101 = icmp sge i32 %100, 80
br i1 %101, label %102, label %104
102: ; preds = %98
store i32 0, i32* %14
%103 = call i32 @putchar(i8 signext 10)
br label %104
104: ; preds = %102, %98
br label %105
105: ; preds = %104
%106 = load i32, i32* %13
%107 = add nsw i32 %106, 1
store i32 %107, i32* %13
%108 = load i8*, i8** %7
%109 = getelementptr inbounds i8, i8* %108, i32 1
store i8* %109, i8** %7
br label %47
110: ; preds = %47
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"/* SIZE %ux%u */\0A\00"
@.str.1 = [41 x i8] c"static const unsigned char %s[ %d ] =\0A{\0A\00"
@.str.2 = [5 x i8] c"0x%X\00"
@.str.3 = [6 x i8] c"0%d%d\00"
@.str.4 = [3 x i8] c"%d\00"
@str = [4 x i8] c"\0A};\00"
define void @print_array(i8* %0, i8* nocapture %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca [128 x i8]
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%8 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%9 = icmp eq i8* %8, null
%10 = select i1 %9, i8* %0, i8* %8
br label %11
11: ; preds = %11, %5
%12 = phi i8* [ %10, %5 ], [ %15, %11 ]
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 46
%15 = getelementptr inbounds i8, i8* %12, i64 1
br i1 %14, label %11, label %16
16: ; preds = %11
%17 = call i32 @strcpy(i8* %7, i8* %12)
%18 = call i8* @strchr(i8* %7, i8 signext 46)
%19 = icmp eq i8* %18, null
br i1 %19, label %21, label %20
20: ; preds = %16
store i8 0, i8* %18
br label %21
21: ; preds = %20, %16
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %4)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %7, i32 %2)
%24 = icmp sgt i32 %2, 0
br i1 %24, label %25, label %60
25: ; preds = %21, %56
%26 = phi i32 [ %57, %56 ], [ 0, %21 ]
%27 = phi i32 [ %46, %56 ], [ 0, %21 ]
%28 = phi i8* [ %58, %56 ], [ %1, %21 ]
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = icmp ugt i8 %29, 63
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %43
34: ; preds = %25
%35 = icmp ugt i8 %29, 7
br i1 %35, label %36, label %41
36: ; preds = %34
%37 = lshr i32 %30, 3
%38 = and i32 %37, 7
%39 = and i32 %30, 7
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %38, i32 %39)
br label %43
41: ; preds = %34
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %30)
br label %43
43: ; preds = %36, %41, %32
%44 = phi i32 [ 3, %36 ], [ 1, %41 ], [ 4, %32 ]
%45 = add nsw i32 %26, %44
%46 = add nuw nsw i32 %27, 1
%47 = icmp slt i32 %46, %2
br i1 %47, label %48, label %51
48: ; preds = %43
%49 = call i32 @putchar(i8 signext 44)
%50 = add nsw i32 %45, 1
br label %51
51: ; preds = %48, %43
%52 = phi i32 [ %50, %48 ], [ %45, %43 ]
%53 = icmp sgt i32 %52, 74
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 @putchar(i8 signext 10)
br label %56
56: ; preds = %51, %54
%57 = phi i32 [ 0, %54 ], [ %52, %51 ]
%58 = getelementptr inbounds i8, i8* %28, i64 1
%59 = icmp eq i32 %46, %2
br i1 %59, label %60, label %25
60: ; preds = %56, %21
%61 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
ret void
}