#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 */
char *malloc(int);
int /*<<< orphan*/ rpn_free(char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int rpn_strip_single_quotes(char **str) {
  int _lg, _retcode;
  char *_new_str;
  _lg = strlen(*str);
  if ((*str)[0] != '\'' || (*str)[_lg - 1] != '\'') {
    _retcode = (2);
  } else {
    _new_str = malloc(_lg);
    strncpy(_new_str, *str + 1, _lg - 2);
    _new_str[_lg - 2] = 0;
    rpn_free(*str);
    *str = _new_str;
    _retcode = (0);
  }
  return _retcode;
}


x86 assembly (clang, -O0):
<rpn_strip_single_quotes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x27,%eax
jne    118b <rpn_strip_single_quotes+0x4b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x27,%eax
je     1197 <rpn_strip_single_quotes+0x57>
movl   $0x2,-0x10(%rbp)
jmp    11ec <rpn_strip_single_quotes+0xac>
mov    -0xc(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
add    $0x1,%rsi
mov    -0xc(%rbp),%edx
sub    $0x2,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1060 <rpn_free@plt>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rpn_strip_single_quotes>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    (%r14),%rbx
mov    $0x2,%eax
cmpb   $0x27,(%rbx)
jne    119e <rpn_strip_single_quotes+0x5e>
movslq %ecx,%r15
cmpb   $0x27,-0x1(%r15,%rbx,1)
jne    119e <rpn_strip_single_quotes+0x5e>
mov    %r15d,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
add    $0x1,%rbx
lea    -0x2(%r15),%rdx
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
movb   $0x0,-0x2(%r12,%r15,1)
mov    (%r14),%rdi
call   1060 <rpn_free@plt>
mov    %r12,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @rpn_strip_single_quotes(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = tail call i32 @strlen(i8* %2)
%4 = load i8*, i8** %0
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 39
br i1 %6, label %7, label %22
7: ; preds = %1
%8 = add nsw i32 %3, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %4, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 39
br i1 %12, label %13, label %22
13: ; preds = %7
%14 = tail call i8* @malloc(i32 %3)
%15 = getelementptr inbounds i8, i8* %4, i64 1
%16 = add nsw i32 %3, -2
%17 = tail call i32 @strncpy(i8* %14, i8* %15, i32 %16)
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds i8, i8* %14, i64 %18
store i8 0, i8* %19
%20 = load i8*, i8** %0
%21 = tail call i32 @rpn_free(i8* %20)
store i8* %14, i8** %0
br label %22
22: ; preds = %1, %7, %13
%23 = phi i32 [ 0, %13 ], [ 2, %7 ], [ 2, %1 ]
ret i32 %23
}