#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 strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *KTraderParse_putSymbolInBrackets(char *_name) {
  int l = strlen(_name) - 1;
  char *p = (char *)malloc(l);
  if (p != NULL) {
    strncpy(p, _name + 1, l - 1);
    p[l - 1] = 0;
  }
  return p;
}


x86 assembly (clang, -O0):
<KTraderParse_putSymbolInBrackets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118a <KTraderParse_putSymbolInBrackets+0x5a>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x1,%rsi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<KTraderParse_putSymbolInBrackets>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%r15d
lea    -0x1(%r15),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     116d <KTraderParse_putSymbolInBrackets+0x3d>
add    $0x1,%r14
movslq %r15d,%r15
lea    -0x2(%r15),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strncpy@plt>
movb   $0x0,-0x2(%rbx,%r15,1)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @KTraderParse_putSymbolInBrackets(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = sub nsw i32 %6, 1
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %25
13: ; preds = %1
%14 = load i8*, i8** %4
%15 = load i8*, i8** %2
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i32, i32* %3
%18 = sub nsw i32 %17, 1
%19 = call i32 @strncpy(i8* %14, i8* %16, i32 %18)
%20 = load i8*, i8** %4
%21 = load i32, i32* %3
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %13, %1
%26 = load i8*, i8** %4
ret i8* %26
}

LLVM IR (-O2):
define i8* @KTraderParse_putSymbolInBrackets(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, -1
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %13, label %7
7: ; preds = %1
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = add nsw i32 %2, -2
%10 = tail call i32 @strncpy(i8* %5, i8* %8, i32 %9)
%11 = sext i32 %9 to i64
%12 = getelementptr inbounds i8, i8* %5, i64 %11
store i8 0, i8* %12
br label %13
13: ; preds = %7, %1
ret i8* %5
}