#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 */
char **argv_append(char **, char *);
char **argv_create(char *, char *);
int /*<<< orphan*/ argv_destroy(char **);
int argv_length(char **);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  char **av;
  av = argv_create("foo bar baz", "");
  assert(argv_length(av) == 3);
  av = argv_append(av, "bonk");
  assert(argv_length(av) == 4);
  assert(strcmp(av[0], "foo") == 0);
  assert(strcmp(av[1], "bar") == 0);
  assert(strcmp(av[2], "baz") == 0);
  assert(strcmp(av[3], "bonk") == 0);
  assert(av[4] == NULL);
  argv_destroy(av);
  av = argv_create("a,b:c d", ",:");
  assert(argv_length(av) == 4);
  assert(strcmp(av[0], "a") == 0);
  assert(strcmp(av[1], "b") == 0);
  assert(strcmp(av[2], "c") == 0);
  assert(strcmp(av[3], "d") == 0);
  assert(av[4] == NULL);
  argv_destroy(av);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe73(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1030 <argv_create@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <argv_length@plt>
cmp    $0x3,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1060 <argv_append@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <argv_length@plt>
cmp    $0x4,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe20(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdff(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdcd(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xdac(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x20(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1040 <argv_destroy@plt>
lea    0xd7d(%rip),%rdi
lea    0xd7e(%rip),%rsi
call   1030 <argv_create@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <argv_length@plt>
cmp    $0x4,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xd51(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd2e(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd0b(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xcdd(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x20(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1040 <argv_destroy@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe85(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1030 <argv_create@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <argv_length@plt>
xor    %edi,%edi
cmp    $0x3,%eax
sete   %dil
call   1080 <assert@plt>
lea    0xe65(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <argv_append@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <argv_length@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1080 <assert@plt>
mov    (%rbx),%rdi
lea    0xe3c(%rip),%rsi
call   1070 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
mov    0x8(%rbx),%rdi
lea    0xe22(%rip),%rsi
call   1070 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
mov    0x10(%rbx),%rdi
lea    0xdf7(%rip),%rsi
call   1070 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
mov    0x18(%rbx),%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,0x20(%rbx)
sete   %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
call   1040 <argv_destroy@plt>
lea    0xdbc(%rip),%rdi
lea    0xdbd(%rip),%rsi
call   1030 <argv_create@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <argv_length@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1080 <assert@plt>
mov    (%rbx),%rdi
lea    0xd98(%rip),%rsi
call   1070 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
mov    0x8(%rbx),%rdi
lea    0xd7c(%rip),%rsi
call   1070 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
mov    0x10(%rbx),%rdi
lea    0xd60(%rip),%rsi
call   1070 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
mov    0x18(%rbx),%rdi
lea    0xd39(%rip),%rsi
call   1070 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,0x20(%rbx)
sete   %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
call   1040 <argv_destroy@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"foo bar baz\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [5 x i8] c"bonk\00"
@.str.3 = [4 x i8] c"foo\00"
@.str.4 = [4 x i8] c"bar\00"
@.str.5 = [4 x i8] c"baz\00"
@.str.6 = [8 x i8] c"a,b:c d\00"
@.str.7 = [3 x i8] c",:\00"
@.str.8 = [2 x i8] c"a\00"
@.str.9 = [2 x i8] c"b\00"
@.str.10 = [2 x i8] c"c\00"
@.str.11 = [2 x i8] c"d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i8** @argv_create(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i8** %7, i8*** %6
%8 = load i8**, i8*** %6
%9 = call i32 @argv_length(i8** %8)
%10 = icmp eq i32 %9, 3
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i8**, i8*** %6
%14 = call i8** @argv_append(i8** %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8** %14, i8*** %6
%15 = load i8**, i8*** %6
%16 = call i32 @argv_length(i8** %15)
%17 = icmp eq i32 %16, 4
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i8**, i8*** %6
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i8**, i8*** %6
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load i8**, i8*** %6
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = load i8**, i8*** %6
%42 = getelementptr inbounds i8*, i8** %41, i64 3
%43 = load i8*, i8** %42
%44 = call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = load i8**, i8*** %6
%49 = getelementptr inbounds i8*, i8** %48, i64 4
%50 = load i8*, i8** %49
%51 = icmp eq i8* %50, null
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
%54 = load i8**, i8*** %6
%55 = call i32 @argv_destroy(i8** %54)
%56 = call i8** @argv_create(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i8** %56, i8*** %6
%57 = load i8**, i8*** %6
%58 = call i32 @argv_length(i8** %57)
%59 = icmp eq i32 %58, 4
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
%62 = load i8**, i8*** %6
%63 = getelementptr inbounds i8*, i8** %62, i64 0
%64 = load i8*, i8** %63
%65 = call i64 @strcmp(i8* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%66 = icmp eq i64 %65, 0
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
%69 = load i8**, i8*** %6
%70 = getelementptr inbounds i8*, i8** %69, i64 1
%71 = load i8*, i8** %70
%72 = call i64 @strcmp(i8* %71, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%73 = icmp eq i64 %72, 0
%74 = zext i1 %73 to i32
%75 = call i32 @assert(i32 %74)
%76 = load i8**, i8*** %6
%77 = getelementptr inbounds i8*, i8** %76, i64 2
%78 = load i8*, i8** %77
%79 = call i64 @strcmp(i8* %78, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%80 = icmp eq i64 %79, 0
%81 = zext i1 %80 to i32
%82 = call i32 @assert(i32 %81)
%83 = load i8**, i8*** %6
%84 = getelementptr inbounds i8*, i8** %83, i64 3
%85 = load i8*, i8** %84
%86 = call i64 @strcmp(i8* %85, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%87 = icmp eq i64 %86, 0
%88 = zext i1 %87 to i32
%89 = call i32 @assert(i32 %88)
%90 = load i8**, i8*** %6
%91 = getelementptr inbounds i8*, i8** %90, i64 4
%92 = load i8*, i8** %91
%93 = icmp eq i8* %92, null
%94 = zext i1 %93 to i32
%95 = call i32 @assert(i32 %94)
%96 = load i8**, i8*** %6
%97 = call i32 @argv_destroy(i8** %96)
%98 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [12 x i8] c"foo bar baz\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [5 x i8] c"bonk\00"
@.str.3 = [4 x i8] c"foo\00"
@.str.4 = [4 x i8] c"bar\00"
@.str.5 = [4 x i8] c"baz\00"
@.str.6 = [8 x i8] c"a,b:c d\00"
@.str.7 = [3 x i8] c",:\00"
@.str.8 = [2 x i8] c"a\00"
@.str.9 = [2 x i8] c"b\00"
@.str.10 = [2 x i8] c"c\00"
@.str.11 = [2 x i8] c"d\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i8** @argv_create(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @argv_length(i8** %3)
%5 = icmp eq i32 %4, 3
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i8** @argv_append(i8** %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @argv_length(i8** %8)
%10 = icmp eq i32 %9, 4
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = load i8*, i8** %8
%14 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = getelementptr inbounds i8*, i8** %8, i64 1
%19 = load i8*, i8** %18
%20 = tail call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
%24 = getelementptr inbounds i8*, i8** %8, i64 2
%25 = load i8*, i8** %24
%26 = tail call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
%28 = zext i1 %27 to i32
%29 = tail call i32 @assert(i32 %28)
%30 = getelementptr inbounds i8*, i8** %8, i64 3
%31 = load i8*, i8** %30
%32 = tail call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
%34 = zext i1 %33 to i32
%35 = tail call i32 @assert(i32 %34)
%36 = getelementptr inbounds i8*, i8** %8, i64 4
%37 = load i8*, i8** %36
%38 = icmp eq i8* %37, null
%39 = zext i1 %38 to i32
%40 = tail call i32 @assert(i32 %39)
%41 = tail call i32 @argv_destroy(i8** %8)
%42 = tail call i8** @argv_create(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%43 = tail call i32 @argv_length(i8** %42)
%44 = icmp eq i32 %43, 4
%45 = zext i1 %44 to i32
%46 = tail call i32 @assert(i32 %45)
%47 = load i8*, i8** %42
%48 = tail call i64 @strcmp(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
%50 = zext i1 %49 to i32
%51 = tail call i32 @assert(i32 %50)
%52 = getelementptr inbounds i8*, i8** %42, i64 1
%53 = load i8*, i8** %52
%54 = tail call i64 @strcmp(i8* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
%56 = zext i1 %55 to i32
%57 = tail call i32 @assert(i32 %56)
%58 = getelementptr inbounds i8*, i8** %42, i64 2
%59 = load i8*, i8** %58
%60 = tail call i64 @strcmp(i8* %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
%62 = zext i1 %61 to i32
%63 = tail call i32 @assert(i32 %62)
%64 = getelementptr inbounds i8*, i8** %42, i64 3
%65 = load i8*, i8** %64
%66 = tail call i64 @strcmp(i8* %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%67 = icmp eq i64 %66, 0
%68 = zext i1 %67 to i32
%69 = tail call i32 @assert(i32 %68)
%70 = getelementptr inbounds i8*, i8** %42, i64 4
%71 = load i8*, i8** %70
%72 = icmp eq i8* %71, null
%73 = zext i1 %72 to i32
%74 = tail call i32 @assert(i32 %73)
%75 = tail call i32 @argv_destroy(i8** %42)
%76 = tail call i32 @exit(i32 0)
unreachable
}