#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 /*<<< orphan*/ int8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ write_int8_array(int /*<<< orphan*/ const *, int);
void write_int8_2d_array(const void *arg, int len, int len2) {
  const int8_t *data = arg;
  int i;
  printf("    {\n");
  for (i = 0; i < len; i++) {
    write_int8_array(data + i * len2, len2);
    printf(i == len - 1 ? "    }\n" : "    }, {\n");
  }
}


x86 assembly (clang, -O0):
<write_int8_2d_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xebf(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a5 <write_int8_2d_array+0x85>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%eax
imul   -0x10(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%esi
call   1040 <write_int8_array@plt>
mov    -0x1c(%rbp),%ecx
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
lea    0xe89(%rip),%rdi
lea    0xe7b(%rip),%rax
cmp    %edx,%ecx
cmove  %rax,%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114d <write_int8_2d_array+0x2d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_int8_2d_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xec6(%rip),%rdi
call   1030 <puts@plt>
test   %r14d,%r14d
jle    11a1 <write_int8_2d_array+0x71>
lea    -0x1(%r14),%r12d
movslq %r15d,%r13
mov    %r14d,%r14d
shl    $0x2,%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %r15d,%esi
call   1050 <write_int8_array@plt>
cmp    %rbp,%r12
lea    0xe82(%rip),%rdi
lea    0xe74(%rip),%rax
cmove  %rax,%rdi
call   1040 <printf@plt>
add    $0x1,%rbp
add    %r13,%rbx
cmp    %rbp,%r14
jne    1170 <write_int8_2d_array+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c" {\0A\00"
@.str.1 = [7 x i8] c" }\0A\00"
@.str.2 = [10 x i8] c" }, {\0A\00"
define void @write_int8_2d_array(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = bitcast i8* %9 to i32*
store i32* %10, i32** %7
%11 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %8
br label %12
12: ; preds = %32, %3
%13 = load i32, i32* %8
%14 = load i32, i32* %5
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %35
16: ; preds = %12
%17 = load i32*, i32** %7
%18 = load i32, i32* %8
%19 = load i32, i32* %6
%20 = mul nsw i32 %18, %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %17, i64 %21
%23 = load i32, i32* %6
%24 = call i32 @write_int8_array(i32* %22, i32 %23)
%25 = load i32, i32* %8
%26 = load i32, i32* %5
%27 = sub nsw i32 %26, 1
%28 = icmp eq i32 %25, %27
%29 = zext i1 %28 to i64
%30 = select i1 %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0)
%31 = call i32 @printf(i8* %30)
br label %32
32: ; preds = %16
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %8
br label %12
35: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c" }\0A\00"
@.str.2 = [10 x i8] c" }, {\0A\00"
@str = [6 x i8] c" {\00"
define void @write_int8_2d_array(i8* %0, i32 %1, i32 %2) {
%4 = bitcast i8* %0 to i32*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %22
7: ; preds = %3
%8 = add nsw i32 %1, -1
%9 = sext i32 %2 to i64
%10 = zext i32 %8 to i64
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %7, %12
%13 = phi i64 [ 0, %7 ], [ %20, %12 ]
%14 = mul nsw i64 %13, %9
%15 = getelementptr inbounds i32, i32* %4, i64 %14
%16 = tail call i32 @write_int8_array(i32* %15, i32 %2)
%17 = icmp eq i64 %13, %10
%18 = select i1 %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0)
%19 = tail call i32 @printf(i8* dereferenceable(1) %18)
%20 = add nuw nsw i64 %13, 1
%21 = icmp eq i64 %20, %11
br i1 %21, label %22, label %12
22: ; preds = %12, %3
ret void
}