#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 error_t;

/* Variables and functions */
int argz_add(char **, size_t *, char *);
char *argz_next(char *, size_t, char *);
int envz_add(char **, size_t *, char *, char *);
int /*<<< orphan*/ envz_entry(char *, size_t, char *);
int /*<<< orphan*/ free(char *);
char *strchr(char *, char);
char *strdup(char *);
error_t envz_merge(char **envz, size_t *envz_len, const char *envz2,
                   size_t envz2_len, int override) {
  char *entry = NULL;
  char *name_str = NULL;
  char *val_str = NULL;
  char *name_iter = NULL;
  int retval = 0;
  while ((entry = argz_next((char *)envz2, envz2_len, entry)) && !retval) {
    if (!override) {
      name_str = strdup(entry);
      name_iter = strchr(name_str, '=');
      if (name_iter)
        *name_iter = '\0';
      if (!envz_entry(*envz, *envz_len, name_str)) {
        retval = argz_add(envz, envz_len, entry);
      }
      free(name_str);
    } else {
      name_str = strdup(entry);
      name_iter = strchr(name_str, '=');
      if (name_iter) {
        *name_iter = '\0';
        val_str = name_iter + 1;
      } else {
        val_str = NULL;
      }
      retval = envz_add(envz, envz_len, name_str, val_str);
      free(name_str);
    }
  }
  return retval;
}


x86 assembly (clang, -O0):
<envz_merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1050 <argz_next@plt>
mov    %rax,%rcx
mov    %rcx,-0x30(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x4d(%rbp)
je     11e6 <envz_merge+0x76>
cmpl   $0x0,-0x4c(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x4d(%rbp)
mov    -0x4d(%rbp),%al
test   $0x1,%al
jne    11f6 <envz_merge+0x86>
jmp    12e3 <envz_merge+0x173>
cmpl   $0x0,-0x24(%rbp)
jne    1273 <envz_merge+0x103>
mov    -0x30(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     1231 <envz_merge+0xc1>
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x38(%rbp),%rdx
call   1080 <envz_entry@plt>
cmp    $0x0,%eax
jne    1265 <envz_merge+0xf5>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1070 <argz_add@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    12de <envz_merge+0x16e>
mov    -0x30(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     12b5 <envz_merge+0x145>
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    12bd <envz_merge+0x14d>
movq   $0x0,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
call   1040 <envz_add@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    11b3 <envz_merge+0x43>
mov    -0x4c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<envz_merge>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,0xc(%rsp)
mov    %rsi,%r13
mov    %rdi,%rbp
xor    %r15d,%r15d
mov    %rdx,0x10(%rsp)
mov    %rdx,%rdi
mov    %rcx,%r12
mov    %rcx,%rsi
xor    %edx,%edx
call   1050 <argz_next@plt>
test   %rax,%rax
je     124f <envz_merge+0xdf>
mov    %rax,%rbx
nopl   (%rax)
mov    %rbx,%rdi
call   1090 <strdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
cmpl   $0x0,0xc(%rsp)
je     11e0 <envz_merge+0x70>
test   %rax,%rax
je     1210 <envz_merge+0xa0>
movb   $0x0,(%rax)
add    $0x1,%rax
jmp    1212 <envz_merge+0xa2>
nopl   (%rax)
test   %rax,%rax
je     11e8 <envz_merge+0x78>
movb   $0x0,(%rax)
mov    0x0(%rbp),%rdi
mov    0x0(%r13),%rsi
mov    %r14,%rdx
call   1080 <envz_entry@plt>
xor    %r15d,%r15d
test   %eax,%eax
jne    1226 <envz_merge+0xb6>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1070 <argz_add@plt>
jmp    1223 <envz_merge+0xb3>
nop
xor    %eax,%eax
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
call   1040 <envz_add@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <argz_next@plt>
test   %rax,%rax
je     124f <envz_merge+0xdf>
mov    %rax,%rbx
test   %r15d,%r15d
je     11b0 <envz_merge+0x40>
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @envz_merge(i8** %0, i64* %1, i8* %2, i64 %3, i32 %4) {
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
store i8** %0, i8*** %6
store i64* %1, i64** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store i32 %4, i32* %10
store i8* null, i8** %11
store i8* null, i8** %12
store i8* null, i8** %13
store i8* null, i8** %14
store i32 0, i32* %15
br label %16
16: ; preds = %76, %5
%17 = load i8*, i8** %8
%18 = load i64, i64* %9
%19 = load i8*, i8** %11
%20 = call i8* @argz_next(i8* %17, i64 %18, i8* %19)
store i8* %20, i8** %11
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = load i32, i32* %15
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br label %26
26: ; preds = %22, %16
%27 = phi i1 [ false, %16 ], [ %25, %22 ]
br i1 %27, label %28, label %77
28: ; preds = %26
%29 = load i32, i32* %10
%30 = icmp ne i32 %29, 0
br i1 %30, label %56, label %31
31: ; preds = %28
%32 = load i8*, i8** %11
%33 = call i8* @strdup(i8* %32)
store i8* %33, i8** %12
%34 = load i8*, i8** %12
%35 = call i8* @strchr(i8* %34, i8 signext 61)
store i8* %35, i8** %14
%36 = load i8*, i8** %14
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %40
38: ; preds = %31
%39 = load i8*, i8** %14
store i8 0, i8* %39
br label %40
40: ; preds = %38, %31
%41 = load i8**, i8*** %6
%42 = load i8*, i8** %41
%43 = load i64*, i64** %7
%44 = load i64, i64* %43
%45 = load i8*, i8** %12
%46 = call i32 @envz_entry(i8* %42, i64 %44, i8* %45)
%47 = icmp ne i32 %46, 0
br i1 %47, label %53, label %48
48: ; preds = %40
%49 = load i8**, i8*** %6
%50 = load i64*, i64** %7
%51 = load i8*, i8** %11
%52 = call i32 @argz_add(i8** %49, i64* %50, i8* %51)
store i32 %52, i32* %15
br label %53
53: ; preds = %48, %40
%54 = load i8*, i8** %12
%55 = call i32 @free(i8* %54)
br label %76
56: ; preds = %28
%57 = load i8*, i8** %11
%58 = call i8* @strdup(i8* %57)
store i8* %58, i8** %12
%59 = load i8*, i8** %12
%60 = call i8* @strchr(i8* %59, i8 signext 61)
store i8* %60, i8** %14
%61 = load i8*, i8** %14
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %67
63: ; preds = %56
%64 = load i8*, i8** %14
store i8 0, i8* %64
%65 = load i8*, i8** %14
%66 = getelementptr inbounds i8, i8* %65, i64 1
store i8* %66, i8** %13
br label %68
67: ; preds = %56
store i8* null, i8** %13
br label %68
68: ; preds = %67, %63
%69 = load i8**, i8*** %6
%70 = load i64*, i64** %7
%71 = load i8*, i8** %12
%72 = load i8*, i8** %13
%73 = call i32 @envz_add(i8** %69, i64* %70, i8* %71, i8* %72)
store i32 %73, i32* %15
%74 = load i8*, i8** %12
%75 = call i32 @free(i8* %74)
br label %76
76: ; preds = %68, %53
br label %16
77: ; preds = %26
%78 = load i32, i32* %15
ret i32 %78
}

LLVM IR (-O2):
define i32 @envz_merge(i8** %0, i64* %1, i8* %2, i64 %3, i32 %4) {
%6 = tail call i8* @argz_next(i8* %2, i64 %3, i8* null)
%7 = icmp eq i8* %6, null
br i1 %7, label %37, label %8
8: ; preds = %5
%9 = icmp eq i32 %4, 0
br label %10
10: ; preds = %8, %30
%11 = phi i8* [ %6, %8 ], [ %33, %30 ]
%12 = tail call i8* @strdup(i8* %11)
%13 = tail call i8* @strchr(i8* dereferenceable(1) %12, i8 signext 61)
%14 = icmp eq i8* %13, null
br i1 %9, label %15, label %24
15: ; preds = %10
br i1 %14, label %17, label %16
16: ; preds = %15
store i8 0, i8* %13
br label %17
17: ; preds = %16, %15
%18 = load i8*, i8** %0
%19 = load i64, i64* %1
%20 = tail call i32 @envz_entry(i8* %18, i64 %19, i8* %12)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %17
%23 = tail call i32 @argz_add(i8** %0, i64* %1, i8* %11)
br label %30
24: ; preds = %10
br i1 %14, label %27, label %25
25: ; preds = %24
store i8 0, i8* %13
%26 = getelementptr inbounds i8, i8* %13, i64 1
br label %27
27: ; preds = %24, %25
%28 = phi i8* [ %26, %25 ], [ null, %24 ]
%29 = tail call i32 @envz_add(i8** %0, i64* %1, i8* %12, i8* %28)
br label %30
30: ; preds = %17, %22, %27
%31 = phi i32 [ %29, %27 ], [ 0, %17 ], [ %23, %22 ]
%32 = tail call i32 @free(i8* %12)
%33 = tail call i8* @argz_next(i8* %2, i64 %3, i8* %11)
%34 = icmp ne i8* %33, null
%35 = icmp eq i32 %31, 0
%36 = select i1 %34, i1 %35, i1 false
br i1 %36, label %10, label %37
37: ; preds = %30, %5
%38 = phi i32 [ 0, %5 ], [ %31, %30 ]
ret i32 %38
}