#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 */
struct str_list {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ str_list_clear_fn(struct str_list *, int /*<<< orphan*/ *);
struct str_list *str_list_create();
int /*<<< orphan*/ str_list_destroy(struct str_list *);
char **str_list_export(struct str_list *);
int /*<<< orphan*/ str_list_insert(struct str_list *, char *);
void test_export() {
  int i = 0;
  char **export;
  struct str_list *l = str_list_create();
  export = str_list_export(l);
  assert(export && *export == NULL);
  free(export);
  str_list_insert(l, "a");
  str_list_insert(l, "b");
  str_list_insert(l, "c");
  export = str_list_export(l);
  for (i = 0; export[i]; i++)
    ;
  assert(i == 3);
  free(export);
  str_list_clear_fn(l, NULL);
  str_list_destroy(l);
}


x86 assembly (clang, -O0):
<test_export>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <str_list_create@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <str_list_export@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x19(%rbp)
je     11b5 <test_export+0x45>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
lea    0xe2a(%rip),%rsi
call   1050 <str_list_insert@plt>
mov    -0x18(%rbp),%rdi
lea    0xe1c(%rip),%rsi
call   1050 <str_list_insert@plt>
mov    -0x18(%rbp),%rdi
lea    0xe0e(%rip),%rsi
call   1050 <str_list_insert@plt>
mov    -0x18(%rbp),%rdi
call   1060 <str_list_export@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1235 <test_export+0xc5>
jmp    1227 <test_export+0xb7>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    120f <test_export+0x9f>
cmpl   $0x3,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <str_list_clear_fn@plt>
mov    -0x18(%rbp),%rdi
call   1090 <str_list_destroy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_export>:
push   %rbp
push   %r14
push   %rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <str_list_create@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <str_list_export@plt>
mov    %rax,%rbx
test   %rax,%rax
je     119a <test_export+0x2a>
xor    %ebp,%ebp
cmpq   $0x0,(%rbx)
sete   %bpl
mov    %ebp,%edi
call   1070 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe50(%rip),%rsi
mov    %r14,%rdi
call   1050 <str_list_insert@plt>
lea    0xe43(%rip),%rsi
mov    %r14,%rdi
call   1050 <str_list_insert@plt>
lea    0xe36(%rip),%rsi
mov    %r14,%rdi
call   1050 <str_list_insert@plt>
mov    %r14,%rdi
call   1060 <str_list_export@plt>
mov    %rax,%rbp
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpq   $0x0,0x0(%rbp,%rax,8)
lea    0x1(%rax),%rax
jne    11f0 <test_export+0x80>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1070 <assert@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <str_list_clear_fn@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1090 <str_list_destroy@plt>

LLVM IR (-O0):
%struct.str_list = type { i32 }
@.str = [2 x i8] c"a\00"
@.str.1 = [2 x i8] c"b\00"
@.str.2 = [2 x i8] c"c\00"
define void @test_export() {
%1 = alloca i32
%2 = alloca i8**
%3 = alloca %struct.str_list*
store i32 0, i32* %1
%4 = call %struct.str_list* (...) @str_list_create()
store %struct.str_list* %4, %struct.str_list** %3
%5 = load %struct.str_list*, %struct.str_list** %3
%6 = call i8** @str_list_export(%struct.str_list* %5)
store i8** %6, i8*** %2
%7 = load i8**, i8*** %2
%8 = icmp ne i8** %7, null
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i8**, i8*** %2
%11 = load i8*, i8** %10
%12 = icmp eq i8* %11, null
br label %13
13: ; preds = %9, %0
%14 = phi i1 [ false, %0 ], [ %12, %9 ]
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i8**, i8*** %2
%18 = call i32 @free(i8** %17)
%19 = load %struct.str_list*, %struct.str_list** %3
%20 = call i32 @str_list_insert(%struct.str_list* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = load %struct.str_list*, %struct.str_list** %3
%22 = call i32 @str_list_insert(%struct.str_list* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = load %struct.str_list*, %struct.str_list** %3
%24 = call i32 @str_list_insert(%struct.str_list* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = load %struct.str_list*, %struct.str_list** %3
%26 = call i8** @str_list_export(%struct.str_list* %25)
store i8** %26, i8*** %2
store i32 0, i32* %1
br label %27
27: ; preds = %35, %13
%28 = load i8**, i8*** %2
%29 = load i32, i32* %1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %38
34: ; preds = %27
br label %35
35: ; preds = %34
%36 = load i32, i32* %1
%37 = add nsw i32 %36, 1
store i32 %37, i32* %1
br label %27
38: ; preds = %27
%39 = load i32, i32* %1
%40 = icmp eq i32 %39, 3
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = load i8**, i8*** %2
%44 = call i32 @free(i8** %43)
%45 = load %struct.str_list*, %struct.str_list** %3
%46 = call i32 @str_list_clear_fn(%struct.str_list* %45, i32* null)
%47 = load %struct.str_list*, %struct.str_list** %3
%48 = call i32 @str_list_destroy(%struct.str_list* %47)
ret void
}

LLVM IR (-O2):
%struct.str_list = type { i32 }
@.str = [2 x i8] c"a\00"
@.str.1 = [2 x i8] c"b\00"
@.str.2 = [2 x i8] c"c\00"
define void @test_export() {
%1 = tail call %struct.str_list* (...) @str_list_create()
%2 = tail call i8** @str_list_export(%struct.str_list* %1)
%3 = icmp eq i8** %2, null
br i1 %3, label %8, label %4
4: ; preds = %0
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
%7 = zext i1 %6 to i32
br label %8
8: ; preds = %4, %0
%9 = phi i32 [ 0, %0 ], [ %7, %4 ]
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i32 @free(i8** %2)
%12 = tail call i32 @str_list_insert(%struct.str_list* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @str_list_insert(%struct.str_list* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @str_list_insert(%struct.str_list* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i8** @str_list_export(%struct.str_list* %1)
br label %16
16: ; preds = %16, %8
%17 = phi i64 [ %21, %16 ], [ 0, %8 ]
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
%21 = add nuw i64 %17, 1
br i1 %20, label %22, label %16
22: ; preds = %16
%23 = trunc i64 %17 to i32
%24 = icmp eq i32 %23, 3
%25 = zext i1 %24 to i32
%26 = tail call i32 @assert(i32 %25)
%27 = tail call i32 @free(i8** %15)
%28 = tail call i32 @str_list_clear_fn(%struct.str_list* %1, i32* null)
%29 = tail call i32 @str_list_destroy(%struct.str_list* %1)
ret void
}