#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*/ assert(char);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, unsigned long);
unsigned long strlen(char *);
int /*<<< orphan*/ xt_core_trace(char *);
char *xt_core_string_append_char(char *original, char addition) {
  assert(addition);
  char *new_string;
  unsigned long original_size;
  unsigned long new_string_size;
  if (original) {
    original_size = strlen(original);
    new_string_size = original_size + 1;
    new_string = malloc(new_string_size + 1);
    if (new_string) {
      memcpy(new_string, original, original_size);
      *(new_string + original_size) = addition;
      *(new_string + new_string_size) = '\0';
    } else {
      xt_core_trace("malloc");
    }
    free(original);
  } else {
    new_string = malloc(1 + 1);
    if (new_string) {
      *(new_string) = addition;
      *(new_string + 1) = '\0';
    } else {
      xt_core_trace("malloc");
    }
  }
  return new_string;
}


x86 assembly (clang, -O0):
<xt_core_string_append_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x8(%rbp)
je     1207 <xt_core_string_append_char+0xa7>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ed <xt_core_string_append_char+0x8d>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x9(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11f9 <xt_core_string_append_char+0x99>
lea    0xe0c(%rip),%rdi
call   1080 <xt_core_trace@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
jmp    1247 <xt_core_string_append_char+0xe7>
mov    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1236 <xt_core_string_append_char+0xd6>
mov    -0x9(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    1242 <xt_core_string_append_char+0xe2>
lea    0xdc3(%rip),%rdi
call   1080 <xt_core_trace@plt>
jmp    1247 <xt_core_string_append_char+0xe7>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xt_core_string_append_char>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
mov    %esi,%edi
call   1050 <assert@plt>
test   %r15,%r15
je     11ae <xt_core_string_append_char+0x4e>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
lea    0x2(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11c9 <xt_core_string_append_char+0x69>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <memcpy@plt>
mov    %r14b,0x0(%rbp,%rbx,1)
movb   $0x0,0x1(%rbp,%rbx,1)
jmp    11d5 <xt_core_string_append_char+0x75>
mov    $0x2,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11eb <xt_core_string_append_char+0x8b>
mov    %rax,%rbp
mov    %r14b,(%rax)
movb   $0x0,0x1(%rax)
jmp    11dd <xt_core_string_append_char+0x7d>
lea    0xe30(%rip),%rdi
call   1080 <xt_core_trace@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe0e(%rip),%rdi
call   1080 <xt_core_trace@plt>
xor    %ebp,%ebp
jmp    11dd <xt_core_string_append_char+0x7d>

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

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
define i8* @xt_core_string_append_char(i8* %0, i8 signext %1) {
%3 = tail call i32 @assert(i8 signext %1)
%4 = icmp eq i8* %0, null
br i1 %4, label %20, label %5
5: ; preds = %2
%6 = tail call i64 @strlen(i8* %0)
%7 = trunc i64 %6 to i32
%8 = add i32 %7, 2
%9 = tail call i8* @malloc(i32 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %5
%12 = add i64 %6, 1
%13 = tail call i32 @memcpy(i8* %9, i8* %0, i64 %6)
%14 = getelementptr inbounds i8, i8* %9, i64 %6
store i8 %1, i8* %14
%15 = getelementptr inbounds i8, i8* %9, i64 %12
store i8 0, i8* %15
br label %18
16: ; preds = %5
%17 = tail call i32 @xt_core_trace(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
%19 = tail call i32 @free(i8* %0)
br label %27
20: ; preds = %2
%21 = tail call dereferenceable_or_null(2) i8* @malloc(i32 2)
%22 = icmp eq i8* %21, null
br i1 %22, label %25, label %23
23: ; preds = %20
store i8 %1, i8* %21
%24 = getelementptr inbounds i8, i8* %21, i64 1
store i8 0, i8* %24
br label %27
25: ; preds = %20
%26 = tail call i32 @xt_core_trace(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %23, %25, %18
%28 = phi i8* [ %9, %18 ], [ %21, %23 ], [ null, %25 ]
ret i8* %28
}