#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 */
scalar_t__ realloc(char *, size_t);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
int nodelist_common_string_appends_and_extends(char **p_io_string,
                                               size_t *p_current_length,
                                               size_t inc_length,
                                               char *string2append,
                                               char *separator) {
  int fstatus = -1;
  size_t new_output_length;
  size_t new_string_length;
  size_t output_string_length;
  size_t separator_length;
  size_t append_length;
  char *default_separator = " ";
  char *local_separator;
  if (*p_io_string != NULL && string2append != NULL) {
    if (separator != NULL)
      local_separator = separator;
    else
      local_separator = default_separator;
    if (strlen(*p_io_string) == 0)
      local_separator = "";
    output_string_length = strlen(*p_io_string);
    separator_length = strlen(local_separator);
    append_length = strlen(string2append);
    new_string_length = output_string_length + separator_length + append_length;
    if (new_string_length > *p_current_length) {
      new_output_length = *p_current_length;
      while (new_string_length > new_output_length)
        new_output_length += inc_length;
      *p_io_string =
          (char *)realloc(*p_io_string, (new_output_length + 1) * sizeof(char));
      if (*p_io_string != NULL)
        *p_current_length = new_output_length;
      else
        *p_current_length = 0;
    }
    if (*p_io_string != NULL) {
      strncpy(*p_io_string + output_string_length, local_separator,
              separator_length);
      strncpy(*p_io_string + output_string_length + separator_length,
              string2append, append_length);
      *(*p_io_string + output_string_length + separator_length +
        append_length) = '\0';
      fstatus = 0;
    }
  }
  return fstatus;
}


x86 assembly (clang, -O0):
<nodelist_common_string_appends_and_extends>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
lea    0xea6(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     12e2 <nodelist_common_string_appends_and_extends+0x1b2>
cmpq   $0x0,-0x20(%rbp)
je     12e2 <nodelist_common_string_appends_and_extends+0x1b2>
cmpq   $0x0,-0x28(%rbp)
je     118f <nodelist_common_string_appends_and_extends+0x5f>
mov    -0x28(%rbp),%rax
mov    %rax,-0x68(%rbp)
jmp    1197 <nodelist_common_string_appends_and_extends+0x67>
mov    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    11b8 <nodelist_common_string_appends_and_extends+0x88>
lea    0xe4d(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x68(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%rax
add    -0x50(%rbp),%rax
add    -0x58(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jbe    127d <nodelist_common_string_appends_and_extends+0x14d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x38(%rbp),%rax
jbe    122d <nodelist_common_string_appends_and_extends+0xfd>
mov    -0x18(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    120e <nodelist_common_string_appends_and_extends+0xde>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x38(%rbp),%rsi
add    $0x1,%rsi
shl    $0x0,%rsi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     126d <nodelist_common_string_appends_and_extends+0x13d>
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1278 <nodelist_common_string_appends_and_extends+0x148>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
jmp    127d <nodelist_common_string_appends_and_extends+0x14d>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     12dd <nodelist_common_string_appends_and_extends+0x1ad>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
add    -0x48(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x50(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
add    -0x48(%rbp),%rdi
add    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x58(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
add    -0x48(%rbp),%rax
add    -0x50(%rbp),%rax
mov    -0x58(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x2c(%rbp)
jmp    12e2 <nodelist_common_string_appends_and_extends+0x1b2>
mov    -0x2c(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nodelist_common_string_appends_and_extends>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    $0xffffffff,%eax
test   %rcx,%rcx
je     124d <nodelist_common_string_appends_and_extends+0x11d>
mov    (%rdi),%rbp
test   %rbp,%rbp
je     124d <nodelist_common_string_appends_and_extends+0x11d>
mov    %rcx,%r13
mov    %rdx,%r12
mov    %rdi,0x8(%rsp)
test   %r8,%r8
lea    0xe93(%rip),%rax
cmovne %r8,%rax
cmpb   $0x0,0x0(%rbp)
lea    0xe85(%rip),%r15
cmovne %rax,%r15
mov    %rbp,%rdi
mov    %rsi,0x10(%rsp)
call   1040 <strlen@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %r14,0x20(%rsp)
mov    %rbx,0x18(%rsp)
lea    (%rbx,%r14,1),%rcx
add    %rax,%rcx
mov    0x10(%rsp),%rdx
mov    (%rdx),%r14
mov    %rax,%rbx
cmp    %r14,%rcx
jbe    1208 <nodelist_common_string_appends_and_extends+0xd8>
sub    %r12,%r14
nopw   0x0(%rax,%rax,1)
add    %r12,%r14
cmp    %r14,%rcx
ja     11d0 <nodelist_common_string_appends_and_extends+0xa0>
lea    0x1(%r14),%rsi
mov    %rbp,%rdi
call   1050 <realloc@plt>
mov    %rax,%rbp
mov    0x8(%rsp),%r12
mov    %rax,(%r12)
test   %rax,%rax
cmove  %rax,%r14
mov    0x10(%rsp),%rax
mov    %r14,(%rax)
mov    $0xffffffff,%eax
jne    120d <nodelist_common_string_appends_and_extends+0xdd>
jmp    124d <nodelist_common_string_appends_and_extends+0x11d>
mov    0x8(%rsp),%r12
mov    0x20(%rsp),%r14
add    %r14,%rbp
mov    %rbp,%rdi
mov    %r15,%rsi
mov    0x18(%rsp),%rbp
mov    %rbp,%rdx
call   1030 <strncpy@plt>
mov    (%r12),%rdi
add    %r14,%rdi
add    %rbp,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
mov    (%r12),%rax
add    %r14,%rax
add    %rbp,%rax
movb   $0x0,(%rbx,%rax,1)
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [1 x i8] zeroinitializer
define i32 @nodelist_common_string_appends_and_extends(i8** %0, i64* %1, i64 %2, i8* %3, i8* %4) {
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = alloca i8*
%18 = alloca i8*
store i8** %0, i8*** %6
store i64* %1, i64** %7
store i64 %2, i64* %8
store i8* %3, i8** %9
store i8* %4, i8** %10
store i32 -1, i32* %11
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %17
%19 = load i8**, i8*** %6
%20 = load i8*, i8** %19
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %114
22: ; preds = %5
%23 = load i8*, i8** %9
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %114
25: ; preds = %22
%26 = load i8*, i8** %10
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = load i8*, i8** %10
store i8* %29, i8** %18
br label %32
30: ; preds = %25
%31 = load i8*, i8** %17
store i8* %31, i8** %18
br label %32
32: ; preds = %30, %28
%33 = load i8**, i8*** %6
%34 = load i8*, i8** %33
%35 = call i64 @strlen(i8* %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %18
br label %38
38: ; preds = %37, %32
%39 = load i8**, i8*** %6
%40 = load i8*, i8** %39
%41 = call i64 @strlen(i8* %40)
store i64 %41, i64* %14
%42 = load i8*, i8** %18
%43 = call i64 @strlen(i8* %42)
store i64 %43, i64* %15
%44 = load i8*, i8** %9
%45 = call i64 @strlen(i8* %44)
store i64 %45, i64* %16
%46 = load i64, i64* %14
%47 = load i64, i64* %15
%48 = add i64 %46, %47
%49 = load i64, i64* %16
%50 = add i64 %48, %49
store i64 %50, i64* %13
%51 = load i64, i64* %13
%52 = load i64*, i64** %7
%53 = load i64, i64* %52
%54 = icmp ugt i64 %51, %53
br i1 %54, label %55, label %84
55: ; preds = %38
%56 = load i64*, i64** %7
%57 = load i64, i64* %56
store i64 %57, i64* %12
br label %58
58: ; preds = %62, %55
%59 = load i64, i64* %13
%60 = load i64, i64* %12
%61 = icmp ugt i64 %59, %60
br i1 %61, label %62, label %66
62: ; preds = %58
%63 = load i64, i64* %8
%64 = load i64, i64* %12
%65 = add i64 %64, %63
store i64 %65, i64* %12
br label %58
66: ; preds = %58
%67 = load i8**, i8*** %6
%68 = load i8*, i8** %67
%69 = load i64, i64* %12
%70 = add i64 %69, 1
%71 = mul i64 %70, 1
%72 = call i64 @realloc(i8* %68, i64 %71)
%73 = inttoptr i64 %72 to i8*
%74 = load i8**, i8*** %6
store i8* %73, i8** %74
%75 = load i8**, i8*** %6
%76 = load i8*, i8** %75
%77 = icmp ne i8* %76, null
br i1 %77, label %78, label %81
78: ; preds = %66
%79 = load i64, i64* %12
%80 = load i64*, i64** %7
store i64 %79, i64* %80
br label %83
81: ; preds = %66
%82 = load i64*, i64** %7
store i64 0, i64* %82
br label %83
83: ; preds = %81, %78
br label %84
84: ; preds = %83, %38
%85 = load i8**, i8*** %6
%86 = load i8*, i8** %85
%87 = icmp ne i8* %86, null
br i1 %87, label %88, label %113
88: ; preds = %84
%89 = load i8**, i8*** %6
%90 = load i8*, i8** %89
%91 = load i64, i64* %14
%92 = getelementptr inbounds i8, i8* %90, i64 %91
%93 = load i8*, i8** %18
%94 = load i64, i64* %15
%95 = call i32 @strncpy(i8* %92, i8* %93, i64 %94)
%96 = load i8**, i8*** %6
%97 = load i8*, i8** %96
%98 = load i64, i64* %14
%99 = getelementptr inbounds i8, i8* %97, i64 %98
%100 = load i64, i64* %15
%101 = getelementptr inbounds i8, i8* %99, i64 %100
%102 = load i8*, i8** %9
%103 = load i64, i64* %16
%104 = call i32 @strncpy(i8* %101, i8* %102, i64 %103)
%105 = load i8**, i8*** %6
%106 = load i8*, i8** %105
%107 = load i64, i64* %14
%108 = getelementptr inbounds i8, i8* %106, i64 %107
%109 = load i64, i64* %15
%110 = getelementptr inbounds i8, i8* %108, i64 %109
%111 = load i64, i64* %16
%112 = getelementptr inbounds i8, i8* %110, i64 %111
store i8 0, i8* %112
store i32 0, i32* %11
br label %113
113: ; preds = %88, %84
br label %114
114: ; preds = %113, %22, %5
%115 = load i32, i32* %11
ret i32 %115
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [1 x i8] zeroinitializer
define i32 @nodelist_common_string_appends_and_extends(i8** nocapture %0, i64* nocapture %1, i64 %2, i8* %3, i8* %4) {
%6 = load i8*, i8** %0
%7 = icmp ne i8* %6, null
%8 = icmp ne i8* %3, null
%9 = and i1 %8, %7
br i1 %9, label %10, label %46
10: ; preds = %5
%11 = icmp eq i8* %4, null
%12 = select i1 %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %4
%13 = load i8, i8* %6
%14 = icmp eq i8 %13, 0
%15 = select i1 %14, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %12
%16 = tail call i64 @strlen(i8* dereferenceable(1) %6)
%17 = tail call i64 @strlen(i8* dereferenceable(1) %15)
%18 = tail call i64 @strlen(i8* %3)
%19 = add i64 %17, %16
%20 = add i64 %19, %18
%21 = load i64, i64* %1
%22 = icmp ugt i64 %20, %21
br i1 %22, label %23, label %34
23: ; preds = %10, %23
%24 = phi i64 [ %26, %23 ], [ %21, %10 ]
%25 = icmp ugt i64 %20, %24
%26 = add i64 %24, %2
br i1 %25, label %23, label %27
27: ; preds = %23
%28 = add i64 %24, 1
%29 = tail call i64 @realloc(i8* %6, i64 %28)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %0
%31 = icmp eq i64 %29, 0
%32 = select i1 %31, i64 0, i64 %24
store i64 %32, i64* %1
%33 = icmp eq i64 %29, 0
br i1 %33, label %46, label %34
34: ; preds = %10, %27
%35 = phi i8* [ %30, %27 ], [ %6, %10 ]
%36 = getelementptr inbounds i8, i8* %35, i64 %16
%37 = tail call i32 @strncpy(i8* %36, i8* %15, i64 %17)
%38 = load i8*, i8** %0
%39 = getelementptr inbounds i8, i8* %38, i64 %16
%40 = getelementptr inbounds i8, i8* %39, i64 %17
%41 = tail call i32 @strncpy(i8* %40, i8* %3, i64 %18)
%42 = load i8*, i8** %0
%43 = getelementptr inbounds i8, i8* %42, i64 %16
%44 = getelementptr inbounds i8, i8* %43, i64 %17
%45 = getelementptr inbounds i8, i8* %44, i64 %18
store i8 0, i8* %45
br label %46
46: ; preds = %27, %34, %5
%47 = phi i32 [ 0, %34 ], [ -1, %27 ], [ -1, %5 ]
ret i32 %47
}