#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(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *charcat_without_alloc(char *s1, char c) {
  int old_size;
  char *t;
  if (s1) {
    old_size = strlen(s1);
  } else {
    old_size = 0;
  }
  t = malloc(sizeof(char) * (old_size + 2));
  if (s1) {
    strcpy(t, s1);
  }
  t[old_size] = c;
  t[old_size + 1] = '\0';
  return t;
}


x86 assembly (clang, -O0):
<charcat_without_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     115e <charcat_without_alloc+0x2e>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10(%rbp)
jmp    1165 <charcat_without_alloc+0x35>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1194 <charcat_without_alloc+0x64>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x9(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<charcat_without_alloc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
test   %rdi,%rdi
je     1163 <charcat_without_alloc+0x33>
mov    %rdi,%rbp
call   1040 <strlen@plt>
mov    %eax,%r15d
lea    0x2(%r15),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
jmp    1173 <charcat_without_alloc+0x43>
mov    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
xor    %r15d,%r15d
movslq %r15d,%rax
mov    %r14b,(%rbx,%rax,1)
movb   $0x0,0x1(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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