#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 GetStackSize(int, char *);
int GetStringLength(char *);
char *ReturnNullMallocStack(char *);
char *ReturnOutputMallocStack(char *, char *, int);
char *SurroundWithSymbols(char *output, char *input, const char openSymbol,
                          const char closeSymbol) {
  int length = GetStringLength(input);
  if (length < 1)
    return ReturnNullMallocStack(output);
  int length2 = length + 2;
  char output2[GetStackSize(length2, "char")];
  int i = 0;
  for (i = 1; i <= length; i++) {
    output2[i] = input[i - 1];
  }
  output2[0] = openSymbol;
  output2[i] = closeSymbol;
  i++;
  output2[i] = '\0';
  return ReturnOutputMallocStack(output, output2, i);
}


x86 assembly (clang, -O0):
<SurroundWithSymbols>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %cl,-0x19(%rbp)
mov    %al,-0x1a(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <GetStringLength@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jge    1182 <SurroundWithSymbols+0x42>
mov    -0x10(%rbp),%rdi
call   1030 <ReturnNullMallocStack@plt>
mov    %rax,-0x8(%rbp)
jmp    123d <SurroundWithSymbols+0xfd>
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
lea    0xe6b(%rip),%rsi
call   1060 <GetStackSize@plt>
mov    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     1202 <SurroundWithSymbols+0xc2>
mov    -0x48(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x3c(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
mov    (%rcx,%rdx,1),%dl
movslq -0x3c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11cd <SurroundWithSymbols+0x8d>
mov    -0x48(%rbp),%rsi
mov    -0x19(%rbp),%al
mov    %al,(%rsi)
mov    -0x1a(%rbp),%cl
movslq -0x3c(%rbp),%rax
mov    %cl,(%rsi,%rax,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
movb   $0x0,(%rsi,%rax,1)
mov    -0x10(%rbp),%rdi
mov    -0x3c(%rbp),%edx
call   1040 <ReturnOutputMallocStack@plt>
mov    %rax,-0x8(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SurroundWithSymbols>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %rsi,%r13
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <GetStringLength@plt>
test   %eax,%eax
jle    1203 <SurroundWithSymbols+0xb3>
mov    %eax,%ebx
lea    0x2(%rbx),%edi
lea    0xe77(%rip),%rsi
call   1070 <GetStackSize@plt>
mov    %rsp,-0x40(%rbp)
mov    %r15d,-0x30(%rbp)
mov    %eax,%r15d
add    $0xf,%r15
and    $0xfffffffffffffff0,%r15
mov    %r12d,-0x2c(%rbp)
mov    %rsp,%r12
mov    %r14,-0x38(%rbp)
mov    %r12,%r14
sub    %r15,%r14
neg    %r15
mov    %r14,%rsp
lea    0x1(%r14),%rdi
mov    %ebx,%ebx
mov    %r13,%rsi
mov    %rbx,%rdx
call   1060 <memcpy@plt>
mov    -0x2c(%rbp),%eax
mov    %al,(%r12,%r15,1)
mov    -0x30(%rbp),%eax
mov    %al,0x1(%rbx,%r14,1)
movb   $0x0,0x2(%rbx,%r14,1)
add    $0x2,%rbx
mov    -0x38(%rbp),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <ReturnOutputMallocStack@plt>
mov    -0x40(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <ReturnNullMallocStack@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"char\00"
define i8* @SurroundWithSymbols(i8* %0, i8* %1, i8 signext %2, i8 signext %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8 %2, i8* %8
store i8 %3, i8* %9
%15 = load i8*, i8** %7
%16 = call i32 @GetStringLength(i8* %15)
store i32 %16, i32* %10
%17 = load i32, i32* %10
%18 = icmp slt i32 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %4
%20 = load i8*, i8** %6
%21 = call i8* @ReturnNullMallocStack(i8* %20)
store i8* %21, i8** %5
br label %63
22: ; preds = %4
%23 = load i32, i32* %10
%24 = add nsw i32 %23, 2
store i32 %24, i32* %11
%25 = load i32, i32* %11
%26 = call i32 @GetStackSize(i32 %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%27 = zext i32 %26 to i64
%28 = call i8* @llvm.stacksave()
store i8* %28, i8** %12
%29 = alloca i8, i64 %27
store i64 %27, i64* %13
store i32 0, i32* %14
store i32 1, i32* %14
br label %30
30: ; preds = %44, %22
%31 = load i32, i32* %14
%32 = load i32, i32* %10
%33 = icmp sle i32 %31, %32
br i1 %33, label %34, label %47
34: ; preds = %30
%35 = load i8*, i8** %7
%36 = load i32, i32* %14
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
%40 = load i8, i8* %39
%41 = load i32, i32* %14
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %29, i64 %42
store i8 %40, i8* %43
br label %44
44: ; preds = %34
%45 = load i32, i32* %14
%46 = add nsw i32 %45, 1
store i32 %46, i32* %14
br label %30
47: ; preds = %30
%48 = load i8, i8* %8
%49 = getelementptr inbounds i8, i8* %29, i64 0
store i8 %48, i8* %49
%50 = load i8, i8* %9
%51 = load i32, i32* %14
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %29, i64 %52
store i8 %50, i8* %53
%54 = load i32, i32* %14
%55 = add nsw i32 %54, 1
store i32 %55, i32* %14
%56 = load i32, i32* %14
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %29, i64 %57
store i8 0, i8* %58
%59 = load i8*, i8** %6
%60 = load i32, i32* %14
%61 = call i8* @ReturnOutputMallocStack(i8* %59, i8* %29, i32 %60)
store i8* %61, i8** %5
%62 = load i8*, i8** %12
br label %63
63: ; preds = %47, %19
%64 = load i8*, i8** %5
ret i8* %64
}

LLVM IR (-O2):
@.str = [5 x i8] c"char\00"
define i8* @SurroundWithSymbols(i8* %0, i8* %1, i8 signext %2, i8 signext %3) {
%5 = tail call i32 @GetStringLength(i8* %1)
%6 = icmp slt i32 %5, 1
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i8* @ReturnNullMallocStack(i8* %0)
br label %24
9: ; preds = %4
%10 = add nuw nsw i32 %5, 2
%11 = tail call i32 @GetStackSize(i32 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = zext i32 %11 to i64
%13 = tail call i8* @llvm.stacksave()
%14 = alloca i8, i64 %12
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = zext i32 %5 to i64
%17 = add nuw i32 %5, 1
store i8 %2, i8* %14
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %14, i64 %18
store i8 %3, i8* %19
%20 = add nuw nsw i32 %5, 2
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %14, i64 %21
store i8 0, i8* %22
%23 = call i8* @ReturnOutputMallocStack(i8* %0, i8* %14, i32 %20)
br label %24
24: ; preds = %9, %7
%25 = phi i8* [ %8, %7 ], [ %23, %9 ]
ret i8* %25
}