#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*/ exit(int);
scalar_t__ pmalloc(int);
scalar_t__ prealloc(char *, int);
int pstrlen(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *pstrcatchar(char *str, char chr) {
  ;
  ;
  ;
  if (!chr)
    return str;
  if (!str) {
    ;
    str = (char *)pmalloc((1 + 1) * sizeof(char));
    if (str)
      *str = '\0';
  } else {
    ;
    str = (char *)prealloc((char *)str, (pstrlen(str) + 1 + 1) * sizeof(char));
  };
  if (!str) {
    ;
    exit(1);
  }
  sprintf(str + pstrlen(str), "%c", (int)chr);
  return str;
}


x86 assembly (clang, -O0):
<pstrcatchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
cmpb   $0x0,-0x11(%rbp)
jne    1179 <pstrcatchar+0x29>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    121c <pstrcatchar+0xcc>
cmpq   $0x0,-0x10(%rbp)
jne    11a9 <pstrcatchar+0x59>
mov    $0x2,%edi
call   1070 <pmalloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a4 <pstrcatchar+0x54>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    11d5 <pstrcatchar+0x85>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <pstrlen@plt>
mov    -0x20(%rbp),%rdi
add    $0x1,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1040 <prealloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ea <pstrcatchar+0x9a>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <pstrlen@plt>
mov    -0x28(%rbp),%rdi
cltq
add    %rax,%rdi
movsbl -0x11(%rbp),%edx
lea    0xdf1(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pstrcatchar>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
test   %bpl,%bpl
je     1197 <pstrcatchar+0x57>
test   %rbx,%rbx
je     116f <pstrcatchar+0x2f>
mov    %rbx,%rdi
call   1030 <pstrlen@plt>
lea    0x2(%rax),%esi
mov    %rbx,%rdi
call   1040 <prealloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1184 <pstrcatchar+0x44>
jmp    11a1 <pstrcatchar+0x61>
mov    $0x2,%edi
call   1060 <pmalloc@plt>
test   %rax,%rax
je     11a1 <pstrcatchar+0x61>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1030 <pstrlen@plt>
cltq
mov    %bpl,(%rbx,%rax,1)
movb   $0x0,0x1(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    $0x1,%edi
call   1050 <exit@plt>

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

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