#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 _pkgconfig_error(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
char *realloc(char *, size_t);
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
size_t strlen(char const *);
int _string_append(char **string, char const *append) {
  size_t slen = (*string != NULL) ? strlen(*string) : 0;
  size_t alen = (append != NULL) ? strlen(append) : 0;
  char *p;
  if (alen == 0)
    return 0;
  if ((p = realloc(*string, slen + alen + 1)) == NULL)
    return -_pkgconfig_error(1, "%s", strerror(errno));
  *string = p;
  strcpy(*string + slen, append);
  return 0;
}


x86 assembly (clang, -O0):
<_string_append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1183 <_string_append+0x33>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
jmp    118e <_string_append+0x3e>
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
jmp    118e <_string_append+0x3e>
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b3 <_string_append+0x63>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x40(%rbp)
jmp    11be <_string_append+0x6e>
xor    %eax,%eax
mov    %rax,-0x40(%rbp)
jmp    11be <_string_append+0x6e>
mov    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11dd <_string_append+0x8d>
movl   $0x0,-0x4(%rbp)
jmp    1258 <_string_append+0x108>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
add    -0x28(%rbp),%rsi
add    $0x1,%rsi
call   1060 <realloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1232 <_string_append+0xe2>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%edx
mov    $0x1,%edi
lea    0xde1(%rip),%rsi
call   1050 <_pkgconfig_error@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1258 <_string_append+0x108>
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
add    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_string_append>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r13
mov    %rdi,%r15
mov    (%rdi),%rbx
xor    %r14d,%r14d
test   %rbx,%rbx
je     117c <_string_append+0x2c>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
test   %r13,%r13
jne    1184 <_string_append+0x34>
jmp    11e0 <_string_append+0x90>
xor    %r12d,%r12d
test   %r13,%r13
je     11e0 <_string_append+0x90>
mov    %r13,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     11e0 <_string_append+0x90>
lea    (%r12,%rax,1),%rsi
add    $0x1,%rsi
mov    %rbx,%rdi
call   1060 <realloc@plt>
test   %rax,%rax
je     11b9 <_string_append+0x69>
mov    %rax,(%r15)
add    %rax,%r12
mov    %r12,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
jmp    11e0 <_string_append+0x90>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe32(%rip),%rsi
mov    $0x1,%edi
mov    %eax,%edx
call   1050 <_pkgconfig_error@plt>
mov    %eax,%r14d
neg    %r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@errno = global i32 0
define i32 @_string_append(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
%9 = load i8**, i8*** %4
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8**, i8*** %4
%14 = load i8*, i8** %13
%15 = call i64 @strlen(i8* %14)
br label %17
16: ; preds = %2
br label %17
17: ; preds = %16, %12
%18 = phi i64 [ %15, %12 ], [ 0, %16 ]
store i64 %18, i64* %6
%19 = load i8*, i8** %5
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i8*, i8** %5
%23 = call i64 @strlen(i8* %22)
br label %25
24: ; preds = %17
br label %25
25: ; preds = %24, %21
%26 = phi i64 [ %23, %21 ], [ 0, %24 ]
store i64 %26, i64* %7
%27 = load i64, i64* %7
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 0, i32* %3
br label %53
30: ; preds = %25
%31 = load i8**, i8*** %4
%32 = load i8*, i8** %31
%33 = load i64, i64* %6
%34 = load i64, i64* %7
%35 = add i64 %33, %34
%36 = add i64 %35, 1
%37 = call i8* @realloc(i8* %32, i64 %36)
store i8* %37, i8** %8
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %44
39: ; preds = %30
%40 = load i32, i32* @errno
%41 = call i32 @strerror(i32 %40)
%42 = call i32 @_pkgconfig_error(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %41)
%43 = sub nsw i32 0, %42
store i32 %43, i32* %3
br label %53
44: ; preds = %30
%45 = load i8*, i8** %8
%46 = load i8**, i8*** %4
store i8* %45, i8** %46
%47 = load i8**, i8*** %4
%48 = load i8*, i8** %47
%49 = load i64, i64* %6
%50 = getelementptr inbounds i8, i8* %48, i64 %49
%51 = load i8*, i8** %5
%52 = call i32 @strcpy(i8* %50, i8* %51)
store i32 0, i32* %3
br label %53
53: ; preds = %44, %39, %29
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@errno = global i32 0
define i32 @_string_append(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i64 @strlen(i8* %3)
br label %7
7: ; preds = %2, %5
%8 = phi i64 [ %6, %5 ], [ 0, %2 ]
%9 = icmp eq i8* %1, null
br i1 %9, label %26, label %10
10: ; preds = %7
%11 = tail call i64 @strlen(i8* %1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %26, label %13
13: ; preds = %10
%14 = add i64 %8, 1
%15 = add i64 %14, %11
%16 = tail call i8* @realloc(i8* %3, i64 %15)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %23
18: ; preds = %13
%19 = load i32, i32* @errno
%20 = tail call i32 @strerror(i32 %19)
%21 = tail call i32 @_pkgconfig_error(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = sub nsw i32 0, %21
br label %26
23: ; preds = %13
store i8* %16, i8** %0
%24 = getelementptr inbounds i8, i8* %16, i64 %8
%25 = tail call i32 @strcpy(i8* %24, i8* %1)
br label %26
26: ; preds = %7, %10, %23, %18
%27 = phi i32 [ %22, %18 ], [ 0, %23 ], [ 0, %10 ], [ 0, %7 ]
ret i32 %27
}