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

/* Variables and functions */
int /*<<< orphan*/ ENOMEM;
int /*<<< orphan*/ argz_create_sep(char const *, int, char **, size_t *);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
scalar_t__ realloc(char *, size_t);
error_t argz_add_sep(char **argz, size_t *argz_len, const char *str, int sep) {
  char *str_argz = 0;
  size_t str_argz_len = 0;
  size_t last = *argz_len;
  argz_create_sep(str, sep, &str_argz, &str_argz_len);
  if (str_argz_len) {
    *argz_len += str_argz_len;
    if (!(*argz = (char *)realloc(*argz, *argz_len)))
      return ENOMEM;
    memcpy(*argz + last, str_argz, str_argz_len);
  }
  return 0;
}


x86 assembly (clang, -O0):
<argz_add_sep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1030 <argz_create_sep@plt>
cmpq   $0x0,-0x38(%rbp)
je     11dc <argz_add_sep+0xac>
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   1050 <realloc@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11c4 <argz_add_sep+0x94>
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11e3 <argz_add_sep+0xb3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
add    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1040 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<argz_add_sep>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rax
mov    %rsi,%rbp
mov    %rdi,%rbx
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    (%rsi),%r15
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%r8
mov    %rax,%rdi
mov    %ecx,%esi
mov    %r8,%rcx
call   1030 <argz_create_sep@plt>
mov    0x8(%rsp),%rsi
xor    %r14d,%r14d
test   %rsi,%rsi
je     11b5 <argz_add_sep+0x85>
add    0x0(%rbp),%rsi
mov    %rsi,0x0(%rbp)
mov    (%rbx),%rdi
call   1050 <realloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     11ab <argz_add_sep+0x7b>
add    %r15,%rax
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1040 <memcpy@plt>
jmp    11b5 <argz_add_sep+0x85>
mov    0x2e2e(%rip),%rax
mov    (%rax),%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ENOMEM = global i32 0
define i32 @argz_add_sep(i8** %0, i64* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
store i8** %0, i8*** %6
store i64* %1, i64** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i8* null, i8** %10
store i64 0, i64* %11
%13 = load i64*, i64** %7
%14 = load i64, i64* %13
store i64 %14, i64* %12
%15 = load i8*, i8** %8
%16 = load i32, i32* %9
%17 = call i32 @argz_create_sep(i8* %15, i32 %16, i8** %10, i64* %11)
%18 = load i64, i64* %11
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %43
20: ; preds = %4
%21 = load i64, i64* %11
%22 = load i64*, i64** %7
%23 = load i64, i64* %22
%24 = add i64 %23, %21
store i64 %24, i64* %22
%25 = load i8**, i8*** %6
%26 = load i8*, i8** %25
%27 = load i64*, i64** %7
%28 = load i64, i64* %27
%29 = call i64 @realloc(i8* %26, i64 %28)
%30 = inttoptr i64 %29 to i8*
%31 = load i8**, i8*** %6
store i8* %30, i8** %31
%32 = icmp ne i8* %30, null
br i1 %32, label %35, label %33
33: ; preds = %20
%34 = load i32, i32* @ENOMEM
store i32 %34, i32* %5
br label %44
35: ; preds = %20
%36 = load i8**, i8*** %6
%37 = load i8*, i8** %36
%38 = load i64, i64* %12
%39 = getelementptr inbounds i8, i8* %37, i64 %38
%40 = load i8*, i8** %10
%41 = load i64, i64* %11
%42 = call i32 @memcpy(i8* %39, i8* %40, i64 %41)
br label %43
43: ; preds = %35, %4
store i32 0, i32* %5
br label %44
44: ; preds = %43, %33
%45 = load i32, i32* %5
ret i32 %45
}

LLVM IR (-O2):
@ENOMEM = global i32 0
define i32 @argz_add_sep(i8** nocapture %0, i64* nocapture %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%8 = bitcast i64* %6 to i8*
store i64 0, i64* %6
%9 = load i64, i64* %1
%10 = call i32 @argz_create_sep(i8* %2, i32 %3, i8** %5, i64* %6)
%11 = load i64, i64* %6
%12 = icmp eq i64 %11, 0
br i1 %12, label %27, label %13
13: ; preds = %4
%14 = load i64, i64* %1
%15 = add i64 %14, %11
store i64 %15, i64* %1
%16 = load i8*, i8** %0
%17 = call i64 @realloc(i8* %16, i64 %15)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %0
%19 = icmp eq i64 %17, 0
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = load i32, i32* @ENOMEM
br label %27
22: ; preds = %13
%23 = getelementptr inbounds i8, i8* %18, i64 %9
%24 = load i8*, i8** %5
%25 = load i64, i64* %6
%26 = call i32 @memcpy(i8* %23, i8* %24, i64 %25)
br label %27
27: ; preds = %4, %22, %20
%28 = phi i32 [ %21, %20 ], [ 0, %22 ], [ 0, %4 ]
ret i32 %28
}