#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__ calloc(unsigned int, int);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
unsigned int strlen(char const *);
int /*<<< orphan*/ strncpy(unsigned char *, unsigned char const *,
                           unsigned int);
unsigned char *elim_par(const unsigned char *par_str) {
  unsigned char *ret;
  unsigned int par_len = strlen((const char *)par_str);
  if (par_len < 2)
    return NULL;
  if (par_str[0] != '(' || par_str[par_len - 1] != ')')
    return NULL;
  ret = (unsigned char *)calloc(par_len, sizeof(char));
  if (!(ret)) {
    perror(NULL);
    return NULL;
  };
  strncpy(ret, par_str + 1, par_len - 2);
  ret[par_len - 2] = '\0';
  return ret;
}


x86 assembly (clang, -O0):
<elim_par>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jae    116f <elim_par+0x2f>
movq   $0x0,-0x8(%rbp)
jmp    1206 <elim_par+0xc6>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x28,%eax
jne    1198 <elim_par+0x58>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%eax
cmp    $0x29,%eax
je     11a5 <elim_par+0x65>
movq   $0x0,-0x8(%rbp)
jmp    1206 <elim_par+0xc6>
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d7 <elim_par+0x97>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    1206 <elim_par+0xc6>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    -0x1c(%rbp),%edx
sub    $0x2,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x2,%ecx
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elim_par>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    $0x2,%eax
jb     1196 <elim_par+0x56>
cmpb   $0x28,(%rbx)
jne    1196 <elim_par+0x56>
mov    %eax,%r15d
lea    -0x1(%r15),%eax
cmpb   $0x29,(%rbx,%rax,1)
jne    1196 <elim_par+0x56>
mov    %r15d,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     11a2 <elim_par+0x62>
mov    %rax,%r14
add    $0x1,%rbx
add    $0xfffffffe,%r15d
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r14,%r15,1)
jmp    1199 <elim_par+0x59>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %r14d,%r14d
xor    %edi,%edi
call   1060 <perror@plt>
jmp    1199 <elim_par+0x59>

LLVM IR (-O0):
define i8* @elim_par(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp ult i32 %8, 2
br i1 %9, label %10, label %11
10: ; preds = %1
store i8* null, i8** %2
br label %48
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = icmp ne i32 %15, 40
br i1 %16, label %26, label %17
17: ; preds = %11
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = sub i32 %19, 1
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = icmp ne i32 %24, 41
br i1 %25, label %26, label %27
26: ; preds = %17, %11
store i8* null, i8** %2
br label %48
27: ; preds = %17
%28 = load i32, i32* %5
%29 = call i64 @calloc(i32 %28, i32 1)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %4
%31 = load i8*, i8** %4
%32 = icmp ne i8* %31, null
br i1 %32, label %35, label %33
33: ; preds = %27
%34 = call i32 @perror(i32* null)
store i8* null, i8** %2
br label %48
35: ; preds = %27
%36 = load i8*, i8** %4
%37 = load i8*, i8** %3
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i32, i32* %5
%40 = sub i32 %39, 2
%41 = call i32 @strncpy(i8* %36, i8* %38, i32 %40)
%42 = load i8*, i8** %4
%43 = load i32, i32* %5
%44 = sub i32 %43, 2
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
store i8 0, i8* %46
%47 = load i8*, i8** %4
store i8* %47, i8** %2
br label %48
48: ; preds = %35, %33, %26, %10
%49 = load i8*, i8** %2
ret i8* %49
}

LLVM IR (-O2):
define i8* @elim_par(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp ult i32 %2, 2
br i1 %3, label %25, label %4
4: ; preds = %1
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 40
br i1 %6, label %7, label %25
7: ; preds = %4
%8 = add i32 %2, -1
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 41
br i1 %12, label %13, label %25
13: ; preds = %7
%14 = tail call i64 @calloc(i32 %2, i32 1)
%15 = inttoptr i64 %14 to i8*
%16 = icmp eq i64 %14, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @perror(i32* null)
br label %25
19: ; preds = %13
%20 = getelementptr inbounds i8, i8* %0, i64 1
%21 = add i32 %2, -2
%22 = tail call i32 @strncpy(i8* %15, i8* %20, i32 %21)
%23 = zext i32 %21 to i64
%24 = getelementptr inbounds i8, i8* %15, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %4, %7, %1, %19, %17
%26 = phi i8* [ %15, %19 ], [ null, %17 ], [ null, %1 ], [ null, %7 ], [ null, %4 ]
ret i8* %26
}