#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 *BSVM2_NatCall_SigNext(char *);
char *BSVM2_NatCall_SigGetRet(char *sig) {
  char *s;
  if (*sig == '(') {
    s = sig + 1;
    while (*s && (*s != ')')) {
      s = BSVM2_NatCall_SigNext(s);
    }
    if (*s == ')')
      return (s + 1);
    return (NULL);
  }
  return (NULL);
}


x86 assembly (clang, -O0):
<BSVM2_NatCall_SigGetRet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
jne    11ad <BSVM2_NatCall_SigGetRet+0x9d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     115d <BSVM2_NatCall_SigGetRet+0x4d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x29,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    116d <BSVM2_NatCall_SigGetRet+0x5d>
jmp    117f <BSVM2_NatCall_SigGetRet+0x6f>
mov    -0x18(%rbp),%rdi
call   1030 <BSVM2_NatCall_SigNext@plt>
mov    %rax,-0x18(%rbp)
jmp    1138 <BSVM2_NatCall_SigGetRet+0x28>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x29,%eax
jne    11a0 <BSVM2_NatCall_SigGetRet+0x90>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11b5 <BSVM2_NatCall_SigGetRet+0xa5>
movq   $0x0,-0x8(%rbp)
jmp    11b5 <BSVM2_NatCall_SigGetRet+0xa5>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BSVM2_NatCall_SigGetRet>:
push   %rax
cmpb   $0x28,(%rdi)
jne    1136 <BSVM2_NatCall_SigGetRet+0x26>
add    $0x1,%rdi
nopw   0x0(%rax,%rax,1)
movzbl (%rdi),%ecx
test   %cl,%cl
je     113a <BSVM2_NatCall_SigGetRet+0x2a>
cmp    $0x29,%cl
je     113a <BSVM2_NatCall_SigGetRet+0x2a>
call   1030 <BSVM2_NatCall_SigNext@plt>
mov    %rax,%rdi
jmp    1120 <BSVM2_NatCall_SigGetRet+0x10>
xor    %eax,%eax
pop    %rcx
ret
add    $0x1,%rdi
xor    %eax,%eax
cmp    $0x29,%cl
cmove  %rdi,%rax
pop    %rcx
ret

LLVM IR (-O0):
define i8* @BSVM2_NatCall_SigGetRet(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 40
br i1 %8, label %9, label %36
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 1
store i8* %11, i8** %4
br label %12
12: ; preds = %24, %9
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 41
br label %22
22: ; preds = %17, %12
%23 = phi i1 [ false, %12 ], [ %21, %17 ]
br i1 %23, label %24, label %27
24: ; preds = %22
%25 = load i8*, i8** %4
%26 = call i8* @BSVM2_NatCall_SigNext(i8* %25)
store i8* %26, i8** %4
br label %12
27: ; preds = %22
%28 = load i8*, i8** %4
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 41
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8* %34, i8** %2
br label %37
35: ; preds = %27
store i8* null, i8** %2
br label %37
36: ; preds = %1
store i8* null, i8** %2
br label %37
37: ; preds = %36, %35, %32
%38 = load i8*, i8** %2
ret i8* %38
}

LLVM IR (-O2):
define i8* @BSVM2_NatCall_SigGetRet(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 40
br i1 %3, label %4, label %15
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 1
br label %6
6: ; preds = %9, %4
%7 = phi i8* [ %5, %4 ], [ %10, %9 ]
%8 = load i8, i8* %7
switch i8 %8, label %9 [
i8 0, label %11
i8 41, label %11
]
9: ; preds = %6
%10 = tail call i8* @BSVM2_NatCall_SigNext(i8* %7)
br label %6
11: ; preds = %6, %6
%12 = icmp eq i8 %8, 41
%13 = getelementptr inbounds i8, i8* %7, i64 1
%14 = select i1 %12, i8* %13, i8* null
br label %15
15: ; preds = %11, %1
%16 = phi i8* [ null, %1 ], [ %14, %11 ]
ret i8* %16
}