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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *normalize_env_assignment(char *);
int /*<<< orphan*/ printf(char *, ...);
char **replace_env_argv(char **, char **);
char **strv_env_clean(char **);
char **strv_env_merge(int, char **, char **);
int /*<<< orphan*/ strv_free(char **);
char **strv_new(char *, char *, char *, char *, char *, int /*<<< orphan*/ *);
char **strv_parse_nulstr(char const *, int);
int main(int argc, char *argv[]) {
  const char *env[] = {"FOO=BAR BAR", "BAR=waldo", NULL};
  const char *line[] = {
      "FOO$FOO", "FOO$FOOFOO", "FOO${FOO}$FOO", "FOO${FOO}", "${FOO}",
      "$FOO",    "$FOO$FOO",   "${FOO}${BAR}",  "${FOO",     NULL};
  char **i, **r, *t, **a, **b;
  const char nulstr[] = "fuck\0fuck2\0fuck3\0\0fuck5\0\0xxx";
  a = strv_parse_nulstr(nulstr, sizeof(nulstr) - 1);
  for ((i) = (a); (i) && *(i); (i)++)
    printf("nulstr--%s\n", *i);
  strv_free(a);
  r = replace_env_argv((char **)line, (char **)env);
  for ((i) = (r); (i) && *(i); (i)++)
    printf("%s\n", *i);
  strv_free(r);
  t = normalize_env_assignment("foo=bar");
  printf("%s\n", t);
  free(t);
  t = normalize_env_assignment("=bar");
  printf("%s\n", t);
  free(t);
  t = normalize_env_assignment("foo=");
  printf("%s\n", t);
  free(t);
  t = normalize_env_assignment("=");
  printf("%s\n", t);
  free(t);
  t = normalize_env_assignment("");
  printf("%s\n", t);
  free(t);
  t = normalize_env_assignment("a=\"waldo\"");
  printf("%s\n", t);
  free(t);
  t = normalize_env_assignment("a=\"waldo");
  printf("%s\n", t);
  free(t);
  t = normalize_env_assignment("a=waldo\"");
  printf("%s\n", t);
  free(t);
  t = normalize_env_assignment("a=\'");
  printf("%s\n", t);
  free(t);
  t = normalize_env_assignment("a=\'\'");
  printf("%s\n", t);
  free(t);
  a = strv_new("FOO=BAR", "WALDO=WALDO", "WALDO=", "PIEP", "SCHLUMPF=SMURF",
               NULL);
  b = strv_new("FOO=KKK", "FOO=", "PIEP=", "SCHLUMPF=SMURFF", "NANANANA=YES",
               NULL);
  r = strv_env_merge(2, a, b);
  strv_free(a);
  strv_free(b);
  for ((i) = (r); (i) && *(i); (i)++)
    printf("%s\n", *i);
  printf("CLEANED UP:\n");
  r = strv_env_clean(r);
  for ((i) = (r); (i) && *(i); (i)++)
    printf("%s\n", *i);
  strv_free(r);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2bf0(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2bed(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2bea(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    -0x80(%rbp),%rdi
lea    0x2beb(%rip),%rsi
mov    $0x50,%edx
call   10a0 <memcpy@plt>
mov    0xf0a(%rip),%rax
mov    %rax,-0xd0(%rbp)
mov    0xf04(%rip),%rax
mov    %rax,-0xc8(%rbp)
mov    0xefe(%rip),%rax
mov    %rax,-0xc0(%rbp)
mov    0xef9(%rip),%eax
mov    %eax,-0xb8(%rbp)
mov    0xef1(%rip),%al
mov    %al,-0xb4(%rbp)
lea    -0xd0(%rbp),%rdi
mov    $0x1c,%esi
call   10b0 <strv_parse_nulstr@plt>
mov    %rax,-0xa0(%rbp)
mov    -0xa0(%rbp),%rax
mov    %rax,-0x88(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x88(%rbp)
mov    %al,-0xd1(%rbp)
je     1281 <main+0xe1>
mov    -0x88(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
mov    %al,-0xd1(%rbp)
mov    -0xd1(%rbp),%al
test   $0x1,%al
jne    1294 <main+0xf4>
jmp    12c3 <main+0x123>
mov    -0x88(%rbp),%rax
mov    (%rax),%rsi
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x88(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x88(%rbp)
jmp    1257 <main+0xb7>
mov    -0xa0(%rbp),%rdi
call   1050 <strv_free@plt>
lea    -0x80(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <replace_env_argv@plt>
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rax
mov    %rax,-0x88(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x88(%rbp)
mov    %al,-0xd2(%rbp)
je     131b <main+0x17b>
mov    -0x88(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
mov    %al,-0xd2(%rbp)
mov    -0xd2(%rbp),%al
test   $0x1,%al
jne    132e <main+0x18e>
jmp    135d <main+0x1bd>
mov    -0x88(%rbp),%rax
mov    (%rax),%rsi
lea    0xd1e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x88(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x88(%rbp)
jmp    12f1 <main+0x151>
mov    -0x90(%rbp),%rdi
call   1050 <strv_free@plt>
lea    0xcf1(%rip),%rdi
call   1090 <normalize_env_assignment@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rsi
lea    0xcd3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x98(%rbp),%rdi
call   1030 <free@plt>
lea    0xcc0(%rip),%rdi
call   1090 <normalize_env_assignment@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rsi
lea    0xc9f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x98(%rbp),%rdi
call   1030 <free@plt>
lea    0xc91(%rip),%rdi
call   1090 <normalize_env_assignment@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rsi
lea    0xc6b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x98(%rbp),%rdi
call   1030 <free@plt>
lea    0xca0(%rip),%rdi
call   1090 <normalize_env_assignment@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rsi
lea    0xc37(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x98(%rbp),%rdi
call   1030 <free@plt>
lea    0xcbe(%rip),%rdi
call   1090 <normalize_env_assignment@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rsi
lea    0xc03(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x98(%rbp),%rdi
call   1030 <free@plt>
lea    0xbfa(%rip),%rdi
call   1090 <normalize_env_assignment@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rsi
lea    0xbcf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x98(%rbp),%rdi
call   1030 <free@plt>
lea    0xbd0(%rip),%rdi
call   1090 <normalize_env_assignment@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rsi
lea    0xb9b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x98(%rbp),%rdi
call   1030 <free@plt>
lea    0xba5(%rip),%rdi
call   1090 <normalize_env_assignment@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rsi
lea    0xb67(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x98(%rbp),%rdi
call   1030 <free@plt>
lea    0xb7a(%rip),%rdi
call   1090 <normalize_env_assignment@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rsi
lea    0xb33(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x98(%rbp),%rdi
call   1030 <free@plt>
lea    0xb4a(%rip),%rdi
call   1090 <normalize_env_assignment@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rsi
lea    0xaff(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x98(%rbp),%rdi
call   1030 <free@plt>
lea    0xb1b(%rip),%rdi
lea    0xb1c(%rip),%rsi
lea    0xb21(%rip),%rdx
lea    0xb21(%rip),%rcx
lea    0xb1f(%rip),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   10c0 <strv_new@plt>
mov    %rax,-0xa0(%rbp)
lea    0xb16(%rip),%rdi
lea    0xb17(%rip),%rsi
lea    0xb15(%rip),%rdx
lea    0xb14(%rip),%rcx
lea    0xb1d(%rip),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   10c0 <strv_new@plt>
mov    %rax,-0xa8(%rbp)
mov    -0xa0(%rbp),%rsi
mov    -0xa8(%rbp),%rdx
mov    $0x2,%edi
call   1070 <strv_env_merge@plt>
mov    %rax,-0x90(%rbp)
mov    -0xa0(%rbp),%rdi
call   1050 <strv_free@plt>
mov    -0xa8(%rbp),%rdi
call   1050 <strv_free@plt>
mov    -0x90(%rbp),%rax
mov    %rax,-0x88(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x88(%rbp)
mov    %al,-0xd3(%rbp)
je     1648 <main+0x4a8>
mov    -0x88(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
mov    %al,-0xd3(%rbp)
mov    -0xd3(%rbp),%al
test   $0x1,%al
jne    165b <main+0x4bb>
jmp    168a <main+0x4ea>
mov    -0x88(%rbp),%rax
mov    (%rax),%rsi
lea    0x9f1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x88(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x88(%rbp)
jmp    161e <main+0x47e>
lea    0xa61(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x90(%rbp),%rdi
call   1080 <strv_env_clean@plt>
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rax
mov    %rax,-0x88(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x88(%rbp)
mov    %al,-0xd4(%rbp)
je     16e3 <main+0x543>
mov    -0x88(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
mov    %al,-0xd4(%rbp)
mov    -0xd4(%rbp),%al
test   $0x1,%al
jne    16f6 <main+0x556>
jmp    1725 <main+0x585>
mov    -0x88(%rbp),%rax
mov    (%rax),%rsi
lea    0x956(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x88(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x88(%rbp)
jmp    16b9 <main+0x519>
mov    -0x90(%rbp),%rdi
call   1050 <strv_free@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x90,%rsp
mov    0x2c0d(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0x2bf1(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0x2c46(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0x2c27(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0x2c0b(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0x2bef(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0x2bd3(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movups 0xf04(%rip),%xmm0
movups %xmm0,0x2d(%rsp)
movaps 0xeeb(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0x20(%rsp),%rdi
mov    $0x1c,%esi
call   10b0 <strv_parse_nulstr@plt>
mov    %rax,%r14
test   %rax,%rax
je     1266 <main+0xc6>
mov    (%r14),%rsi
test   %rsi,%rsi
je     1266 <main+0xc6>
mov    %r14,%rbx
add    $0x8,%rbx
lea    0xe0e(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1250 <main+0xb0>
mov    %r14,%rdi
call   1060 <strv_free@plt>
lea    0x40(%rsp),%rdi
mov    %rsp,%rsi
call   1050 <replace_env_argv@plt>
mov    %rax,%r14
test   %rax,%rax
je     12b1 <main+0x111>
mov    (%r14),%rdi
test   %rdi,%rdi
je     12b1 <main+0x111>
mov    %r14,%rbx
add    $0x8,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1040 <puts@plt>
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    12a0 <main+0x100>
mov    %r14,%rdi
call   1060 <strv_free@plt>
lea    0xda1(%rip),%rdi
call   10a0 <normalize_env_assignment@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xd85(%rip),%rdi
call   10a0 <normalize_env_assignment@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xd6b(%rip),%rdi
call   10a0 <normalize_env_assignment@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xd8f(%rip),%rdi
call   10a0 <normalize_env_assignment@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xd24(%rip),%rdi
call   10a0 <normalize_env_assignment@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xd13(%rip),%rdi
call   10a0 <normalize_env_assignment@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xcfe(%rip),%rdi
call   10a0 <normalize_env_assignment@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xce8(%rip),%rdi
call   10a0 <normalize_env_assignment@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xcd2(%rip),%rdi
call   10a0 <normalize_env_assignment@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xcb7(%rip),%rdi
call   10a0 <normalize_env_assignment@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xc9d(%rip),%rdi
lea    0xc9e(%rip),%rsi
lea    0xca3(%rip),%rdx
lea    0xca3(%rip),%rcx
lea    0xca1(%rip),%r8
xor    %r9d,%r9d
call   10c0 <strv_new@plt>
mov    %rax,%r15
lea    0xc9e(%rip),%rdi
lea    0xc9f(%rip),%rsi
lea    0xc9d(%rip),%rdx
lea    0xc9c(%rip),%rcx
lea    0xca5(%rip),%r8
xor    %r9d,%r9d
call   10c0 <strv_new@plt>
mov    %rax,%rbx
mov    $0x2,%edi
mov    %r15,%rsi
mov    %rax,%rdx
call   1080 <strv_env_merge@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1060 <strv_free@plt>
mov    %rbx,%rdi
call   1060 <strv_free@plt>
test   %r14,%r14
je     14a1 <main+0x301>
mov    (%r14),%rdi
test   %rdi,%rdi
je     14a1 <main+0x301>
mov    %r14,%rbx
add    $0x8,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1040 <puts@plt>
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    1490 <main+0x2f0>
lea    0xc4a(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1090 <strv_env_clean@plt>
mov    %rax,%r14
test   %rax,%rax
je     14e1 <main+0x341>
mov    (%r14),%rdi
test   %rdi,%rdi
je     14e1 <main+0x341>
mov    %r14,%rbx
add    $0x8,%rbx
nopl   0x0(%rax)
call   1040 <puts@plt>
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    14d0 <main+0x330>
mov    %r14,%rdi
call   1060 <strv_free@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"FOO=BAR BAR\00"
@.str.1 = [10 x i8] c"BAR=waldo\00"
@__const.main.env = [3 x i8*] [i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [8 x i8] c"FOO$FOO\00"
@.str.3 = [11 x i8] c"FOO$FOOFOO\00"
@.str.4 = [14 x i8] c"FOO${FOO}$FOO\00"
@.str.5 = [10 x i8] c"FOO${FOO}\00"
@.str.6 = [7 x i8] c"${FOO}\00"
@.str.7 = [5 x i8] c"$FOO\00"
@.str.8 = [9 x i8] c"$FOO$FOO\00"
@.str.9 = [13 x i8] c"${FOO}${BAR}\00"
@.str.10 = [6 x i8] c"${FOO\00"
@__const.main.line = [10 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i32 0, i32 0), i8* null]
@__const.main.nulstr = [29 x i8] c"fuck\00fuck2\00fuck3\00\00fuck5\00\00xxx\00"
@.str.11 = [12 x i8] c"nulstr--%s\0A\00"
@.str.12 = [4 x i8] c"%s\0A\00"
@.str.13 = [8 x i8] c"foo=bar\00"
@.str.14 = [5 x i8] c"=bar\00"
@.str.15 = [5 x i8] c"foo=\00"
@.str.16 = [2 x i8] c"=\00"
@.str.17 = [1 x i8] zeroinitializer
@.str.18 = [10 x i8] c"a=\22waldo\22\00"
@.str.19 = [9 x i8] c"a=\22waldo\00"
@.str.20 = [9 x i8] c"a=waldo\22\00"
@.str.21 = [4 x i8] c"a='\00"
@.str.22 = [5 x i8] c"a=''\00"
@.str.23 = [8 x i8] c"FOO=BAR\00"
@.str.24 = [12 x i8] c"WALDO=WALDO\00"
@.str.25 = [7 x i8] c"WALDO=\00"
@.str.26 = [5 x i8] c"PIEP\00"
@.str.27 = [15 x i8] c"SCHLUMPF=SMURF\00"
@.str.28 = [8 x i8] c"FOO=KKK\00"
@.str.29 = [5 x i8] c"FOO=\00"
@.str.30 = [6 x i8] c"PIEP=\00"
@.str.31 = [16 x i8] c"SCHLUMPF=SMURFF\00"
@.str.32 = [13 x i8] c"NANANANA=YES\00"
@.str.33 = [13 x i8] c"CLEANED UP:\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [3 x i8*]
%7 = alloca [10 x i8*]
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca i8*
%11 = alloca i8**
%12 = alloca i8**
%13 = alloca [29 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = bitcast [3 x i8*]* %6 to i8*
%15 = bitcast [10 x i8*]* %7 to i8*
%16 = bitcast [29 x i8]* %13 to i8*
%17 = getelementptr inbounds [29 x i8], [29 x i8]* %13, i64 0, i64 0
%18 = call i8** @strv_parse_nulstr(i8* %17, i32 28)
store i8** %18, i8*** %11
%19 = load i8**, i8*** %11
store i8** %19, i8*** %8
br label %20
20: ; preds = %33, %2
%21 = load i8**, i8*** %8
%22 = icmp ne i8** %21, null
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i8**, i8*** %8
%25 = load i8*, i8** %24
%26 = icmp ne i8* %25, null
br label %27
27: ; preds = %23, %20
%28 = phi i1 [ false, %20 ], [ %26, %23 ]
br i1 %28, label %29, label %36
29: ; preds = %27
%30 = load i8**, i8*** %8
%31 = load i8*, i8** %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %29
%34 = load i8**, i8*** %8
%35 = getelementptr inbounds i8*, i8** %34, i32 1
store i8** %35, i8*** %8
br label %20
36: ; preds = %27
%37 = load i8**, i8*** %11
%38 = call i32 @strv_free(i8** %37)
%39 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 0
%40 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 0
%41 = call i8** @replace_env_argv(i8** %39, i8** %40)
store i8** %41, i8*** %9
%42 = load i8**, i8*** %9
store i8** %42, i8*** %8
br label %43
43: ; preds = %56, %36
%44 = load i8**, i8*** %8
%45 = icmp ne i8** %44, null
br i1 %45, label %46, label %50
46: ; preds = %43
%47 = load i8**, i8*** %8
%48 = load i8*, i8** %47
%49 = icmp ne i8* %48, null
br label %50
50: ; preds = %46, %43
%51 = phi i1 [ false, %43 ], [ %49, %46 ]
br i1 %51, label %52, label %59
52: ; preds = %50
%53 = load i8**, i8*** %8
%54 = load i8*, i8** %53
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %52
%57 = load i8**, i8*** %8
%58 = getelementptr inbounds i8*, i8** %57, i32 1
store i8** %58, i8*** %8
br label %43
59: ; preds = %50
%60 = load i8**, i8*** %9
%61 = call i32 @strv_free(i8** %60)
%62 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i64 0, i64 0))
store i8* %62, i8** %10
%63 = load i8*, i8** %10
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i8* %63)
%65 = load i8*, i8** %10
%66 = call i32 @free(i8* %65)
%67 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
store i8* %67, i8** %10
%68 = load i8*, i8** %10
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i8* %68)
%70 = load i8*, i8** %10
%71 = call i32 @free(i8* %70)
%72 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0))
store i8* %72, i8** %10
%73 = load i8*, i8** %10
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i8* %73)
%75 = load i8*, i8** %10
%76 = call i32 @free(i8* %75)
%77 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.16, i64 0, i64 0))
store i8* %77, i8** %10
%78 = load i8*, i8** %10
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i8* %78)
%80 = load i8*, i8** %10
%81 = call i32 @free(i8* %80)
%82 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.17, i64 0, i64 0))
store i8* %82, i8** %10
%83 = load i8*, i8** %10
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i8* %83)
%85 = load i8*, i8** %10
%86 = call i32 @free(i8* %85)
%87 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.18, i64 0, i64 0))
store i8* %87, i8** %10
%88 = load i8*, i8** %10
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i8* %88)
%90 = load i8*, i8** %10
%91 = call i32 @free(i8* %90)
%92 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.19, i64 0, i64 0))
store i8* %92, i8** %10
%93 = load i8*, i8** %10
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i8* %93)
%95 = load i8*, i8** %10
%96 = call i32 @free(i8* %95)
%97 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.20, i64 0, i64 0))
store i8* %97, i8** %10
%98 = load i8*, i8** %10
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i8* %98)
%100 = load i8*, i8** %10
%101 = call i32 @free(i8* %100)
%102 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.21, i64 0, i64 0))
store i8* %102, i8** %10
%103 = load i8*, i8** %10
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i8* %103)
%105 = load i8*, i8** %10
%106 = call i32 @free(i8* %105)
%107 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.22, i64 0, i64 0))
store i8* %107, i8** %10
%108 = load i8*, i8** %10
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i8* %108)
%110 = load i8*, i8** %10
%111 = call i32 @free(i8* %110)
%112 = call i8** @strv_new(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.23, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.24, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.25, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.26, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.27, i64 0, i64 0), i32* null)
store i8** %112, i8*** %11
%113 = call i8** @strv_new(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.28, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.29, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.30, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.31, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.32, i64 0, i64 0), i32* null)
store i8** %113, i8*** %12
%114 = load i8**, i8*** %11
%115 = load i8**, i8*** %12
%116 = call i8** @strv_env_merge(i32 2, i8** %114, i8** %115)
store i8** %116, i8*** %9
%117 = load i8**, i8*** %11
%118 = call i32 @strv_free(i8** %117)
%119 = load i8**, i8*** %12
%120 = call i32 @strv_free(i8** %119)
%121 = load i8**, i8*** %9
store i8** %121, i8*** %8
br label %122
122: ; preds = %135, %59
%123 = load i8**, i8*** %8
%124 = icmp ne i8** %123, null
br i1 %124, label %125, label %129
125: ; preds = %122
%126 = load i8**, i8*** %8
%127 = load i8*, i8** %126
%128 = icmp ne i8* %127, null
br label %129
129: ; preds = %125, %122
%130 = phi i1 [ false, %122 ], [ %128, %125 ]
br i1 %130, label %131, label %138
131: ; preds = %129
%132 = load i8**, i8*** %8
%133 = load i8*, i8** %132
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i8* %133)
br label %135
135: ; preds = %131
%136 = load i8**, i8*** %8
%137 = getelementptr inbounds i8*, i8** %136, i32 1
store i8** %137, i8*** %8
br label %122
138: ; preds = %129
%139 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.33, i64 0, i64 0))
%140 = load i8**, i8*** %9
%141 = call i8** @strv_env_clean(i8** %140)
store i8** %141, i8*** %9
%142 = load i8**, i8*** %9
store i8** %142, i8*** %8
br label %143
143: ; preds = %156, %138
%144 = load i8**, i8*** %8
%145 = icmp ne i8** %144, null
br i1 %145, label %146, label %150
146: ; preds = %143
%147 = load i8**, i8*** %8
%148 = load i8*, i8** %147
%149 = icmp ne i8* %148, null
br label %150
150: ; preds = %146, %143
%151 = phi i1 [ false, %143 ], [ %149, %146 ]
br i1 %151, label %152, label %159
152: ; preds = %150
%153 = load i8**, i8*** %8
%154 = load i8*, i8** %153
%155 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i8* %154)
br label %156
156: ; preds = %152
%157 = load i8**, i8*** %8
%158 = getelementptr inbounds i8*, i8** %157, i32 1
store i8** %158, i8*** %8
br label %143
159: ; preds = %150
%160 = load i8**, i8*** %9
%161 = call i32 @strv_free(i8** %160)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"FOO=BAR BAR\00"
@.str.1 = [10 x i8] c"BAR=waldo\00"
@__const.main.env = [3 x i8*] [i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [8 x i8] c"FOO$FOO\00"
@.str.3 = [11 x i8] c"FOO$FOOFOO\00"
@.str.4 = [14 x i8] c"FOO${FOO}$FOO\00"
@.str.5 = [10 x i8] c"FOO${FOO}\00"
@.str.6 = [7 x i8] c"${FOO}\00"
@.str.7 = [5 x i8] c"$FOO\00"
@.str.8 = [9 x i8] c"$FOO$FOO\00"
@.str.9 = [13 x i8] c"${FOO}${BAR}\00"
@.str.10 = [6 x i8] c"${FOO\00"
@__const.main.line = [10 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i32 0, i32 0), i8* null]
@__const.main.nulstr = [29 x i8] c"fuck\00fuck2\00fuck3\00\00fuck5\00\00xxx\00"
@.str.11 = [12 x i8] c"nulstr--%s\0A\00"
@.str.13 = [8 x i8] c"foo=bar\00"
@.str.14 = [5 x i8] c"=bar\00"
@.str.15 = [5 x i8] c"foo=\00"
@.str.16 = [2 x i8] c"=\00"
@.str.17 = [1 x i8] zeroinitializer
@.str.18 = [10 x i8] c"a=\22waldo\22\00"
@.str.19 = [9 x i8] c"a=\22waldo\00"
@.str.20 = [9 x i8] c"a=waldo\22\00"
@.str.21 = [4 x i8] c"a='\00"
@.str.22 = [5 x i8] c"a=''\00"
@.str.23 = [8 x i8] c"FOO=BAR\00"
@.str.24 = [12 x i8] c"WALDO=WALDO\00"
@.str.25 = [7 x i8] c"WALDO=\00"
@.str.26 = [5 x i8] c"PIEP\00"
@.str.27 = [15 x i8] c"SCHLUMPF=SMURF\00"
@.str.28 = [8 x i8] c"FOO=KKK\00"
@.str.29 = [5 x i8] c"FOO=\00"
@.str.30 = [6 x i8] c"PIEP=\00"
@.str.31 = [16 x i8] c"SCHLUMPF=SMURFF\00"
@.str.32 = [13 x i8] c"NANANANA=YES\00"
@str = [12 x i8] c"CLEANED UP:\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x i8*]
%4 = alloca [10 x i8*]
%5 = alloca [29 x i8]
%6 = bitcast [3 x i8*]* %3 to i8*
%7 = bitcast [10 x i8*]* %4 to i8*
%8 = getelementptr inbounds [29 x i8], [29 x i8]* %5, i64 0, i64 0
%9 = call i8** @strv_parse_nulstr(i8* %8, i32 28)
%10 = icmp eq i8** %9, null
br i1 %10, label %21, label %11
11: ; preds = %2
%12 = load i8*, i8** %9
%13 = icmp eq i8* %12, null
br i1 %13, label %21, label %14
14: ; preds = %11, %14
%15 = phi i8* [ %19, %14 ], [ %12, %11 ]
%16 = phi i8** [ %18, %14 ], [ %9, %11 ]
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i8* %15)
%18 = getelementptr inbounds i8*, i8** %16, i64 1
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %14
21: ; preds = %14, %11, %2
%22 = call i32 @strv_free(i8** %9)
%23 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 0
%24 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
%25 = call i8** @replace_env_argv(i8** %23, i8** %24)
%26 = icmp eq i8** %25, null
br i1 %26, label %37, label %27
27: ; preds = %21
%28 = load i8*, i8** %25
%29 = icmp eq i8* %28, null
br i1 %29, label %37, label %30
30: ; preds = %27, %30
%31 = phi i8* [ %35, %30 ], [ %28, %27 ]
%32 = phi i8** [ %34, %30 ], [ %25, %27 ]
%33 = call i32 @puts(i8* %31)
%34 = getelementptr inbounds i8*, i8** %32, i64 1
%35 = load i8*, i8** %34
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %30
37: ; preds = %30, %27, %21
%38 = call i32 @strv_free(i8** %25)
%39 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i64 0, i64 0))
%40 = call i32 @puts(i8* dereferenceable(1) %39)
%41 = call i32 @free(i8* %39)
%42 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
%43 = call i32 @puts(i8* dereferenceable(1) %42)
%44 = call i32 @free(i8* %42)
%45 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0))
%46 = call i32 @puts(i8* dereferenceable(1) %45)
%47 = call i32 @free(i8* %45)
%48 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.16, i64 0, i64 0))
%49 = call i32 @puts(i8* dereferenceable(1) %48)
%50 = call i32 @free(i8* %48)
%51 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.17, i64 0, i64 0))
%52 = call i32 @puts(i8* dereferenceable(1) %51)
%53 = call i32 @free(i8* %51)
%54 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.18, i64 0, i64 0))
%55 = call i32 @puts(i8* dereferenceable(1) %54)
%56 = call i32 @free(i8* %54)
%57 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.19, i64 0, i64 0))
%58 = call i32 @puts(i8* dereferenceable(1) %57)
%59 = call i32 @free(i8* %57)
%60 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.20, i64 0, i64 0))
%61 = call i32 @puts(i8* dereferenceable(1) %60)
%62 = call i32 @free(i8* %60)
%63 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.21, i64 0, i64 0))
%64 = call i32 @puts(i8* dereferenceable(1) %63)
%65 = call i32 @free(i8* %63)
%66 = call i8* @normalize_env_assignment(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.22, i64 0, i64 0))
%67 = call i32 @puts(i8* dereferenceable(1) %66)
%68 = call i32 @free(i8* %66)
%69 = call i8** @strv_new(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.23, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.24, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.25, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.26, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.27, i64 0, i64 0), i32* null)
%70 = call i8** @strv_new(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.28, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.29, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.30, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.31, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.32, i64 0, i64 0), i32* null)
%71 = call i8** @strv_env_merge(i32 2, i8** %69, i8** %70)
%72 = call i32 @strv_free(i8** %69)
%73 = call i32 @strv_free(i8** %70)
%74 = icmp eq i8** %71, null
br i1 %74, label %85, label %75
75: ; preds = %37
%76 = load i8*, i8** %71
%77 = icmp eq i8* %76, null
br i1 %77, label %85, label %78
78: ; preds = %75, %78
%79 = phi i8* [ %83, %78 ], [ %76, %75 ]
%80 = phi i8** [ %82, %78 ], [ %71, %75 ]
%81 = call i32 @puts(i8* %79)
%82 = getelementptr inbounds i8*, i8** %80, i64 1
%83 = load i8*, i8** %82
%84 = icmp eq i8* %83, null
br i1 %84, label %85, label %78
85: ; preds = %78, %75, %37
%86 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%87 = call i8** @strv_env_clean(i8** %71)
%88 = icmp eq i8** %87, null
br i1 %88, label %99, label %89
89: ; preds = %85
%90 = load i8*, i8** %87
%91 = icmp eq i8* %90, null
br i1 %91, label %99, label %92
92: ; preds = %89, %92
%93 = phi i8* [ %97, %92 ], [ %90, %89 ]
%94 = phi i8** [ %96, %92 ], [ %87, %89 ]
%95 = call i32 @puts(i8* %93)
%96 = getelementptr inbounds i8*, i8** %94, i64 1
%97 = load i8*, i8** %96
%98 = icmp eq i8* %97, null
br i1 %98, label %99, label %92
99: ; preds = %92, %89, %85
%100 = call i32 @strv_free(i8** %87)
ret i32 0
}