#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 strlen(char *);
scalar_t__ xrealloc(void *, int);
char *str_append_char(char *source, char c) {
  int strsiz;
  char *nptr;
  strsiz = source == NULL ? 1 : strlen(source) + 1;
  nptr = (char *)xrealloc((void *)source, strsiz + 1);
  if (nptr == NULL)
    return NULL;
  nptr[strsiz - 1] = c;
  nptr[strsiz] = '\0';
  return nptr;
}


x86 assembly (clang, -O0):
<str_append_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114a <str_append_char+0x2a>
mov    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1159 <str_append_char+0x39>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    $0x1,%esi
call   1040 <xrealloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118a <str_append_char+0x6a>
movq   $0x0,-0x8(%rbp)
jmp    11b1 <str_append_char+0x91>
mov    -0x11(%rbp),%dl
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_append_char>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbp
test   %rdi,%rdi
je     113e <str_append_char+0x1e>
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
add    $0x1,%ebx
jmp    1143 <str_append_char+0x23>
mov    $0x1,%ebx
lea    0x1(%rbx),%esi
mov    %rbp,%rdi
call   1040 <xrealloc@plt>
test   %rax,%rax
je     1161 <str_append_char+0x41>
movslq %ebx,%rcx
mov    %r14b,-0x1(%rax,%rcx,1)
movb   $0x0,(%rax,%rcx,1)
jmp    1163 <str_append_char+0x43>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @str_append_char(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8 %1, i8* %5
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
br label %15
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 %13, 1
br label %15
15: ; preds = %11, %10
%16 = phi i32 [ 1, %10 ], [ %14, %11 ]
store i32 %16, i32* %6
%17 = load i8*, i8** %4
%18 = load i32, i32* %6
%19 = add nsw i32 %18, 1
%20 = call i64 @xrealloc(i8* %17, i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %7
%22 = load i8*, i8** %7
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %15
store i8* null, i8** %3
br label %37
25: ; preds = %15
%26 = load i8, i8* %5
%27 = load i8*, i8** %7
%28 = load i32, i32* %6
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
store i8 %26, i8* %31
%32 = load i8*, i8** %7
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 0, i8* %35
%36 = load i8*, i8** %7
store i8* %36, i8** %3
br label %37
37: ; preds = %25, %24
%38 = load i8*, i8** %3
ret i8* %38
}

LLVM IR (-O2):
define i8* @str_append_char(i8* %0, i8 signext %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, 1
br label %7
7: ; preds = %2, %4
%8 = phi i32 [ %6, %4 ], [ 1, %2 ]
%9 = add nsw i32 %8, 1
%10 = tail call i64 @xrealloc(i8* %0, i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = icmp eq i64 %10, 0
br i1 %12, label %19, label %13
13: ; preds = %7
%14 = add nsw i32 %8, -1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %11, i64 %15
store i8 %1, i8* %16
%17 = sext i32 %8 to i64
%18 = getelementptr inbounds i8, i8* %11, i64 %17
store i8 0, i8* %18
br label %19
19: ; preds = %7, %13
%20 = phi i8* [ %11, %13 ], [ null, %7 ]
ret i8* %20
}