#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*/ free(char *);
char *malloc(int);
int strlen(char *);
char *agregar_parentesis(char *original) {
  int longitud = strlen(original);
  char *resultado = malloc(longitud + 3);
  resultado[0] = '(';
  for (int i = 0; i < longitud; i++)
    resultado[i + 1] = original[i];
  resultado[longitud + 1] = ')';
  resultado[longitud + 2] = 0;
  free(original);
  return resultado;
}


x86 assembly (clang, -O0):
<agregar_parentesis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
add    $0x3,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x28,(%rax)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119a <agregar_parentesis+0x6a>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1165 <agregar_parentesis+0x35>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x29,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<agregar_parentesis>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%r15d
lea    0x3(%r15),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movb   $0x28,(%rax)
test   %r15d,%r15d
jle    1176 <agregar_parentesis+0x36>
mov    %rbx,%rdi
add    $0x1,%rdi
mov    %r15d,%edx
mov    %r14,%rsi
call   1050 <memcpy@plt>
movslq %r15d,%rax
movw   $0x29,0x1(%rax,%rbx,1)
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define noalias i8* @agregar_parentesis(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 3
%4 = tail call i8* @malloc(i32 %3)
store i8 40, i8* %4
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = getelementptr i8, i8* %4, i64 1
%8 = zext i32 %2 to i64
br label %9
9: ; preds = %6, %1
%10 = add nsw i32 %2, 1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %4, i64 %11
store i8 41, i8* %12
%13 = add nsw i32 %2, 2
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %4, i64 %14
store i8 0, i8* %15
%16 = tail call i32 @free(i8* %0)
ret i8* %4
}