#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 */
char *malloc(scalar_t__);
char *strapp(char *, char const *);
char *strdup(char const *);
scalar_t__ strlen(char const *);
char *signalFormat_stringAppend(const char *in, const char *app) {
  char *ret;
  if (in == NULL) {
    ret = strdup(app);
  } else {
    char *dp;
    char *sp;
    ret = malloc(strlen(in) + 1 + strlen(app) + 1);
    dp = strapp(ret, in);
    *dp++ = '_';
    dp = strapp(dp, app);
    *dp = '\0';
  }
  return ret;
}


x86 assembly (clang, -O0):
<signalFormat_stringAppend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    116d <signalFormat_stringAppend+0x2d>
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
jmp    11d6 <signalFormat_stringAppend+0x96>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strapp@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x5f,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strapp@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signalFormat_stringAppend>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     1196 <signalFormat_stringAppend+0x56>
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%r15,%rax,1),%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strapp@plt>
movb   $0x5f,(%rax)
lea    0x1(%rax),%rdi
mov    %r14,%rsi
call   1040 <strapp@plt>
movb   $0x0,(%rax)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <strdup@plt>

LLVM IR (-O0):
define i8* @signalFormat_stringAppend(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** %5
br label %31
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %15, 1
%17 = load i8*, i8** %4
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %16, %18
%20 = add nsw i64 %19, 1
%21 = call i8* @malloc(i64 %20)
store i8* %21, i8** %5
%22 = load i8*, i8** %5
%23 = load i8*, i8** %3
%24 = call i8* @strapp(i8* %22, i8* %23)
store i8* %24, i8** %6
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %6
store i8 95, i8* %25
%27 = load i8*, i8** %6
%28 = load i8*, i8** %4
%29 = call i8* @strapp(i8* %27, i8* %28)
store i8* %29, i8** %6
%30 = load i8*, i8** %6
store i8 0, i8* %30
br label %31
31: ; preds = %13, %10
%32 = load i8*, i8** %5
ret i8* %32
}

LLVM IR (-O2):
define i8* @signalFormat_stringAppend(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i8* @strdup(i8* %1)
br label %15
6: ; preds = %2
%7 = tail call i64 @strlen(i8* %0)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%9 = add i64 %7, 2
%10 = add i64 %9, %8
%11 = tail call i8* @malloc(i64 %10)
%12 = tail call i8* @strapp(i8* %11, i8* %0)
%13 = getelementptr inbounds i8, i8* %12, i64 1
store i8 95, i8* %12
%14 = tail call i8* @strapp(i8* %13, i8* %1)
store i8 0, i8* %14
br label %15
15: ; preds = %6, %4
%16 = phi i8* [ %5, %4 ], [ %11, %6 ]
ret i8* %16
}