#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 */
int /*<<< orphan*/ enough_mem(char **);
scalar_t__ malloc(scalar_t__);
scalar_t__ realloc(char *, scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strlen(char *);
void config_append_string(char **s, char *appstr) {
  if (!appstr || !s) {
    return;
  }
  if (!*s) {
    *s = (char *)malloc(strlen(appstr) + 1);
    enough_mem(s);
    *s[0] = '\0';
  } else {
    *s = (char *)realloc(*s, strlen(*s) + strlen(appstr) + 1);
    enough_mem(s);
  }
  strcat(*s, appstr);
}


x86 assembly (clang, -O0):
<config_append_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1176 <config_append_string+0x26>
cmpq   $0x0,-0x8(%rbp)
jne    117b <config_append_string+0x2b>
jmp    121b <config_append_string+0xcb>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11c0 <config_append_string+0x70>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <enough_mem@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
jmp    120b <config_append_string+0xbb>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdi
add    %rax,%rsi
add    $0x1,%rsi
call   1060 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <enough_mem@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_append_string>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11a0 <config_append_string+0x50>
mov    %rsi,%r14
test   %rsi,%rsi
je     11a0 <config_append_string+0x50>
mov    %rdi,%rbx
mov    (%rdi),%r15
test   %r15,%r15
je     11ac <config_append_string+0x5c>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%r12,%rax,1),%rsi
add    $0x1,%rsi
mov    %r15,%rdi
call   1060 <realloc@plt>
mov    %rax,(%rbx)
mov    %rbx,%rdi
call   1040 <enough_mem@plt>
jmp    11ce <config_append_string+0x7e>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
call   1050 <malloc@plt>
mov    %rax,(%rbx)
mov    %rbx,%rdi
call   1040 <enough_mem@plt>
mov    (%rbx),%rax
movb   $0x0,(%rax)
mov    (%rbx),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1070 <strcat@plt>

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

LLVM IR (-O2):
define void @config_append_string(i8** %0, i8* %1) {
%3 = icmp ne i8* %1, null
%4 = icmp ne i8** %0, null
%5 = and i1 %4, %3
br i1 %5, label %6, label %27
6: ; preds = %2
%7 = load i8*, i8** %0
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %16
9: ; preds = %6
%10 = tail call i64 @strlen(i8* %1)
%11 = add nsw i64 %10, 1
%12 = tail call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %0
%14 = tail call i32 @enough_mem(i8** %0)
%15 = load i8*, i8** %0
store i8 0, i8* %15
br label %24
16: ; preds = %6
%17 = tail call i64 @strlen(i8* %7)
%18 = tail call i64 @strlen(i8* %1)
%19 = add i64 %17, 1
%20 = add i64 %19, %18
%21 = tail call i64 @realloc(i8* %7, i64 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %0
%23 = tail call i32 @enough_mem(i8** %0)
br label %24
24: ; preds = %16, %9
%25 = load i8*, i8** %0
%26 = tail call i32 @strcat(i8* %25, i8* %1)
br label %27
27: ; preds = %2, %24
ret void
}