#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *toString(char *input_str) {
  if (input_str[0] == '"') {
    return input_str;
  } else {
    int malloc_length = (int)strlen(input_str) + 2;
    char *output = (char *)malloc(sizeof(char) * (malloc_length + 1));
    strcpy(output, "\"");
    strcat(output, input_str);
    strcat(output, "\"");
    output[malloc_length] = 0;
    return output;
  }
}


x86 assembly (clang, -O0):
<toString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    1169 <toString+0x29>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d0 <toString+0x90>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toString>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
cmpb   $0x22,(%rdi)
je     119d <toString+0x5d>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%r14
lea    0x3(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
lea    0xe93(%rip),%r12
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <strcat@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <strcat@plt>
add    $0x2,%r14d
movslq %r14d,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"\22\00"
define i8* @toString(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 34
br i1 %3, label %17, label %4
4: ; preds = %1
%5 = tail call i64 @strlen(i8* %0)
%6 = trunc i64 %5 to i32
%7 = add nsw i32 %6, 3
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @strcat(i8* %9, i8* %0)
%12 = tail call i32 @strcat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = shl i64 %5, 32
%14 = add i64 %13, 8589934592
%15 = ashr exact i64 %14, 32
%16 = getelementptr inbounds i8, i8* %9, i64 %15
store i8 0, i8* %16
br label %17
17: ; preds = %1, %4
%18 = phi i8* [ %9, %4 ], [ %0, %1 ]
ret i8* %18
}