#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*/ free(char **);
int /*<<< orphan*/ str_printf(char *, int *, char *, ...);
int /*<<< orphan*/ write_string(char *, int *, char *);
void write_array(char *out, int *written, void *p_array) {
  unsigned i;
  char **array;
  array = p_array;
  str_printf(out, written, "[");
  for (i = 0; array[i]; ++i)
    ;
  if (i <= 3) {
    if (*array) {
      write_string(out, written, *array);
      for (i = 1; array[i]; ++i) {
        str_printf(out, written, ", ");
        write_string(out, written, array[i]);
      }
    }
  } else
    str_printf(out, written, "/* %d vars */", i);
  str_printf(out, written, "]");
  free(array);
}


x86 assembly (clang, -O0):
<write_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xea5(%rip),%rdx
mov    $0x0,%al
call   1050 <str_printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
cmpq   $0x0,(%rax,%rcx,8)
je     118e <write_array+0x5e>
jmp    1180 <write_array+0x50>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1169 <write_array+0x39>
cmpl   $0x3,-0x1c(%rbp)
ja     1219 <write_array+0xe9>
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
je     1214 <write_array+0xe4>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%rdx
call   1040 <write_string@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
cmpq   $0x0,(%rax,%rcx,8)
je     120f <write_array+0xdf>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe20(%rip),%rdx
mov    $0x0,%al
call   1050 <str_printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,8),%rdx
call   1040 <write_string@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c1 <write_array+0x91>
jmp    1214 <write_array+0xe4>
jmp    1232 <write_array+0x102>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
lea    0xdda(%rip),%rdx
mov    $0x0,%al
call   1050 <str_printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xdd2(%rip),%rdx
mov    $0x0,%al
call   1050 <str_printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xeb5(%rip),%rdx
xor    %eax,%eax
call   1050 <str_printf@plt>
mov    $0xffffffff,%ecx
nopw   0x0(%rax,%rax,1)
add    $0x1,%ecx
cmpq   $0x0,0x0(%r13,%rcx,8)
jne    1160 <write_array+0x30>
cmp    $0x3,%ecx
ja     11d8 <write_array+0xa8>
mov    0x0(%r13),%rdx
test   %rdx,%rdx
je     11ec <write_array+0xbc>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <write_string@plt>
cmpq   $0x0,0x8(%r13)
je     11ec <write_array+0xbc>
lea    0x8(%r13),%rbx
mov    $0x2,%ebp
lea    0xe67(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <str_printf@plt>
mov    (%rbx),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <write_string@plt>
mov    %ebp,%eax
lea    0x0(,%rax,8),%rbx
add    %r13,%rbx
add    $0x1,%ebp
cmpq   $0x0,0x0(%r13,%rax,8)
jne    11a0 <write_array+0x70>
jmp    11ec <write_array+0xbc>
lea    0xe26(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <str_printf@plt>
lea    0xe20(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <str_printf@plt>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"[\00"
@.str.1 = [3 x i8] c", \00"
@.str.2 = [14 x i8] c"/* %d vars */\00"
@.str.3 = [2 x i8] c"]\00"
define void @write_array(i8* %0, i32* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8**
store i8* %0, i8** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = bitcast i8* %9 to i8**
store i8** %10, i8*** %8
%11 = load i8*, i8** %4
%12 = load i32*, i32** %5
%13 = call i32 (i8*, i32*, i8*, ...) @str_printf(i8* %11, i32* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %14
14: ; preds = %22, %3
%15 = load i8**, i8*** %8
%16 = load i32, i32* %7
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %25
21: ; preds = %14
br label %22
22: ; preds = %21
%23 = load i32, i32* %7
%24 = add i32 %23, 1
store i32 %24, i32* %7
br label %14
25: ; preds = %14
%26 = load i32, i32* %7
%27 = icmp ule i32 %26, 3
br i1 %27, label %28, label %62
28: ; preds = %25
%29 = load i8**, i8*** %8
%30 = load i8*, i8** %29
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %61
32: ; preds = %28
%33 = load i8*, i8** %4
%34 = load i32*, i32** %5
%35 = load i8**, i8*** %8
%36 = load i8*, i8** %35
%37 = call i32 @write_string(i8* %33, i32* %34, i8* %36)
store i32 1, i32* %7
br label %38
38: ; preds = %57, %32
%39 = load i8**, i8*** %8
%40 = load i32, i32* %7
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
%43 = load i8*, i8** %42
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %60
45: ; preds = %38
%46 = load i8*, i8** %4
%47 = load i32*, i32** %5
%48 = call i32 (i8*, i32*, i8*, ...) @str_printf(i8* %46, i32* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%49 = load i8*, i8** %4
%50 = load i32*, i32** %5
%51 = load i8**, i8*** %8
%52 = load i32, i32* %7
%53 = zext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = call i32 @write_string(i8* %49, i32* %50, i8* %55)
br label %57
57: ; preds = %45
%58 = load i32, i32* %7
%59 = add i32 %58, 1
store i32 %59, i32* %7
br label %38
60: ; preds = %38
br label %61
61: ; preds = %60, %28
br label %67
62: ; preds = %25
%63 = load i8*, i8** %4
%64 = load i32*, i32** %5
%65 = load i32, i32* %7
%66 = call i32 (i8*, i32*, i8*, ...) @str_printf(i8* %63, i32* %64, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %62, %61
%68 = load i8*, i8** %4
%69 = load i32*, i32** %5
%70 = call i32 (i8*, i32*, i8*, ...) @str_printf(i8* %68, i32* %69, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%71 = load i8**, i8*** %8
%72 = call i32 @free(i8** %71)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"[\00"
@.str.1 = [3 x i8] c", \00"
@.str.2 = [14 x i8] c"/* %d vars */\00"
@.str.3 = [2 x i8] c"]\00"
define void @write_array(i8* %0, i32* %1, i8* nocapture %2) {
%4 = bitcast i8* %2 to i8**
%5 = tail call i32 (i8*, i32*, i8*, ...) @str_printf(i8* %0, i32* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %6, %3
%7 = phi i32 [ 0, %3 ], [ %12, %6 ]
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds i8*, i8** %4, i64 %8
%10 = load i8*, i8** %9
%11 = icmp eq i8* %10, null
%12 = add i32 %7, 1
br i1 %11, label %13, label %6
13: ; preds = %6
%14 = icmp ult i32 %7, 4
br i1 %14, label %15, label %35
15: ; preds = %13
%16 = load i8*, i8** %4
%17 = icmp eq i8* %16, null
br i1 %17, label %37, label %18
18: ; preds = %15
%19 = tail call i32 @write_string(i8* %0, i32* %1, i8* %16)
%20 = getelementptr inbounds i8, i8* %2, i64 8
%21 = bitcast i8* %20 to i8**
%22 = load i8*, i8** %21
%23 = icmp eq i8* %22, null
br i1 %23, label %37, label %24
24: ; preds = %18, %24
%25 = phi i8** [ %32, %24 ], [ %21, %18 ]
%26 = phi i32 [ %30, %24 ], [ 1, %18 ]
%27 = tail call i32 (i8*, i32*, i8*, ...) @str_printf(i8* %0, i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%28 = load i8*, i8** %25
%29 = tail call i32 @write_string(i8* %0, i32* %1, i8* %28)
%30 = add i32 %26, 1
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %4, i64 %31
%33 = load i8*, i8** %32
%34 = icmp eq i8* %33, null
br i1 %34, label %37, label %24
35: ; preds = %13
%36 = tail call i32 (i8*, i32*, i8*, ...) @str_printf(i8* %0, i32* %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %7)
br label %37
37: ; preds = %24, %18, %15, %35
%38 = tail call i32 (i8*, i32*, i8*, ...) @str_printf(i8* %0, i32* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%39 = tail call i32 @free(i8** %4)
ret void
}