#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ prnlog(char *);
int snprintf(char *, size_t, char *, ...);
int strlen(char *);
void printarr(char *name, uint8_t *arr, int len) {
  int cx;
  size_t outsize = 40 + strlen(name) + len * 5;
  char *output = malloc(outsize);
  memset(output, 0, outsize);
  int i;
  cx = snprintf(output, outsize, "uint8_t %s[] = {", name);
  for (i = 0; i < len; i++) {
    cx += snprintf(output + cx, outsize - cx, "0x%02x,", *(arr + i));
  }
  cx += snprintf(output + cx, outsize - cx, "};");
  prnlog(output);
  free(output);
}


x86 assembly (clang, -O0):
<printarr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x28,%eax
imul   $0x5,-0x14(%rbp),%ecx
add    %ecx,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rcx
lea    0xe46(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    121a <printarr+0xba>
mov    -0x28(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
movslq -0x18(%rbp),%rax
sub    %rax,%rsi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xe12(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11cb <printarr+0x6b>
mov    -0x28(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
movslq -0x18(%rbp),%rax
sub    %rax,%rsi
lea    0xde2(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <prnlog@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printarr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r13d
mov    %rsi,%r15
mov    %rdi,%rbx
call   1050 <strlen@plt>
lea    0x0(%r13,%r13,4),%ecx
add    %ecx,%eax
add    $0x28,%eax
movslq %eax,%r12
mov    %r12,%rdi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1070 <memset@plt>
lea    0xe5b(%rip),%rdx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %eax,%ebx
test   %r13d,%r13d
jle    11fa <printarr+0x9a>
mov    %r13d,%ebp
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %ebx,%rbx
lea    (%r14,%rbx,1),%rdi
mov    %r12,%rsi
sub    %rbx,%rsi
mov    (%r15,%r13,4),%ecx
lea    0xe29(%rip),%rdx
xor    %eax,%eax
call   1060 <snprintf@plt>
add    %eax,%ebx
add    $0x1,%r13
cmp    %r13,%rbp
jne    11d0 <printarr+0x70>
movslq %ebx,%rax
mov    %r14,%rdi
add    %rax,%rdi
sub    %rax,%r12
lea    0xe0c(%rip),%rdx
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %r14,%rdi
call   1040 <prnlog@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"uint8_t %s[] = {\00"
@.str.1 = [8 x i8] c"0x%02x,\00"
@.str.2 = [3 x i8] c"};\00"
define void @printarr(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 40, %12
%14 = load i32, i32* %6
%15 = mul nsw i32 %14, 5
%16 = add nsw i32 %13, %15
%17 = sext i32 %16 to i64
store i64 %17, i64* %8
%18 = load i64, i64* %8
%19 = call i8* @malloc(i64 %18)
store i8* %19, i8** %9
%20 = load i8*, i8** %9
%21 = load i64, i64* %8
%22 = call i32 @memset(i8* %20, i32 0, i64 %21)
%23 = load i8*, i8** %9
%24 = load i64, i64* %8
%25 = load i8*, i8** %4
%26 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %23, i64 %24, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %25)
store i32 %26, i32* %7
store i32 0, i32* %10
br label %27
27: ; preds = %48, %3
%28 = load i32, i32* %10
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %51
31: ; preds = %27
%32 = load i8*, i8** %9
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i64, i64* %8
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = sub i64 %36, %38
%40 = load i32*, i32** %5
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = load i32, i32* %43
%45 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %35, i64 %39, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %7
%47 = add nsw i32 %46, %45
store i32 %47, i32* %7
br label %48
48: ; preds = %31
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 1
store i32 %50, i32* %10
br label %27
51: ; preds = %27
%52 = load i8*, i8** %9
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = load i64, i64* %8
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = sub i64 %56, %58
%60 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %55, i64 %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%61 = load i32, i32* %7
%62 = add nsw i32 %61, %60
store i32 %62, i32* %7
%63 = load i8*, i8** %9
%64 = call i32 @prnlog(i8* %63)
%65 = load i8*, i8** %9
%66 = call i32 @free(i8* %65)
ret void
}

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