#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*/ traverse(char *, int, int /*<<< orphan*/, int, int,
                            int /*<<< orphan*/, char *, int, char ***, int *);
char **removeInvalidParentheses(char *s, int *returnSize) {
  char **arr = (char **)malloc(sizeof(char *));
  *returnSize = 0;
  int left = 0, right = 0;
  for (int i = 0; s[i]; i++) {
    if (s[i] == '(')
      left++;
    else if (s[i] == ')') {
      if (left)
        left--;
      else
        right++;
    }
  }
  int len = strlen(s);
  char *stack = (char *)malloc(sizeof(char) * len);
  int top = -1;
  traverse(s, len, 0, left, right, 0, stack, top, &arr, returnSize);
  return arr;
}


x86 assembly (clang, -O0):
<removeInvalidParentheses>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x58,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11f6 <removeInvalidParentheses+0xc6>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x28,%eax
jne    11a3 <removeInvalidParentheses+0x73>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e3 <removeInvalidParentheses+0xb3>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x29,%eax
jne    11de <removeInvalidParentheses+0xae>
cmpl   $0x0,-0x24(%rbp)
je     11d0 <removeInvalidParentheses+0xa0>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    11d9 <removeInvalidParentheses+0xa9>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11de <removeInvalidParentheses+0xae>
jmp    11e3 <removeInvalidParentheses+0xb3>
jmp    11e8 <removeInvalidParentheses+0xb8>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    116e <removeInvalidParentheses+0x3e>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x30(%rbp)
movslq -0x30(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x38(%rbp),%rbx
mov    -0x3c(%rbp),%r11d
mov    -0x18(%rbp),%rax
xor    %r9d,%r9d
lea    -0x20(%rbp),%r10
mov    %r9d,%edx
mov    %rbx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1040 <traverse@plt>
mov    -0x20(%rbp),%rax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<removeInvalidParentheses>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,0x8(%rsp)
movl   $0x0,(%r14)
xor    %ebp,%ebp
mov    %r15,%rax
xor    %ebx,%ebx
jmp    1178 <removeInvalidParentheses+0x48>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   %cl,%cl
je     11b0 <removeInvalidParentheses+0x80>
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x28,%cl
je     11a0 <removeInvalidParentheses+0x70>
cmp    $0x29,%cl
jne    1170 <removeInvalidParentheses+0x40>
test   %ebx,%ebx
je     11a9 <removeInvalidParentheses+0x79>
add    $0xffffffff,%ebx
add    $0x1,%rax
jmp    1178 <removeInvalidParentheses+0x48>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebx
add    $0x1,%rax
jmp    1178 <removeInvalidParentheses+0x48>
add    $0x1,%ebp
xor    %ebx,%ebx
jmp    1174 <removeInvalidParentheses+0x44>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %eax,%edi
call   1050 <malloc@plt>
lea    0x8(%rsp),%r10
mov    %r15,%rdi
mov    %r12d,%esi
xor    %edx,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
xor    %r9d,%r9d
push   %r14
push   %r10
push   $0xffffffffffffffff
push   %rax
call   1040 <traverse@plt>
add    $0x20,%rsp
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8** @removeInvalidParentheses(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%12 = call i64 @malloc(i32 8)
%13 = inttoptr i64 %12 to i8**
store i8** %13, i8*** %5
%14 = load i32*, i32** %4
store i32 0, i32* %14
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %15
15: ; preds = %53, %2
%16 = load i8*, i8** %3
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = icmp ne i8 %20, 0
br i1 %21, label %22, label %56
22: ; preds = %15
%23 = load i8*, i8** %3
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 40
br i1 %29, label %30, label %33
30: ; preds = %22
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %52
33: ; preds = %22
%34 = load i8*, i8** %3
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 41
br i1 %40, label %41, label %51
41: ; preds = %33
%42 = load i32, i32* %6
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i32, i32* %6
%46 = add nsw i32 %45, -1
store i32 %46, i32* %6
br label %50
47: ; preds = %41
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %50
50: ; preds = %47, %44
br label %51
51: ; preds = %50, %33
br label %52
52: ; preds = %51, %30
br label %53
53: ; preds = %52
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
br label %15
56: ; preds = %15
%57 = load i8*, i8** %3
%58 = call i32 @strlen(i8* %57)
store i32 %58, i32* %9
%59 = load i32, i32* %9
%60 = sext i32 %59 to i64
%61 = mul i64 1, %60
%62 = trunc i64 %61 to i32
%63 = call i64 @malloc(i32 %62)
%64 = inttoptr i64 %63 to i8*
store i8* %64, i8** %10
store i32 -1, i32* %11
%65 = load i8*, i8** %3
%66 = load i32, i32* %9
%67 = load i32, i32* %6
%68 = load i32, i32* %7
%69 = load i8*, i8** %10
%70 = load i32, i32* %11
%71 = load i32*, i32** %4
%72 = call i32 @traverse(i8* %65, i32 %66, i32 0, i32 %67, i32 %68, i32 0, i8* %69, i32 %70, i8*** %5, i32* %71)
%73 = load i8**, i8*** %5
ret i8** %73
}

LLVM IR (-O2):
define i8** @removeInvalidParentheses(i8* %0, i32* %1) {
%3 = alloca i8**
%4 = bitcast i8*** %3 to i8*
%5 = tail call i64 @malloc(i32 8)
%6 = inttoptr i64 %5 to i8**
store i8** %6, i8*** %3
store i32 0, i32* %1
br label %7
7: ; preds = %27, %2
%8 = phi i64 [ %30, %27 ], [ 0, %2 ]
%9 = phi i32 [ %28, %27 ], [ 0, %2 ]
%10 = phi i32 [ %29, %27 ], [ 0, %2 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %8
%12 = load i8, i8* %11
switch i8 %12, label %27 [
i8 0, label %13
i8 40, label %19
i8 41, label %21
]
13: ; preds = %7
%14 = tail call i32 @strlen(i8* %0)
%15 = tail call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = call i32 @traverse(i8* %0, i32 %14, i32 0, i32 %10, i32 %9, i32 0, i8* %16, i32 -1, i8*** %3, i32* %1)
%18 = load i8**, i8*** %3
ret i8** %18
19: ; preds = %7
%20 = add nsw i32 %10, 1
br label %27
21: ; preds = %7
%22 = icmp eq i32 %10, 0
br i1 %22, label %25, label %23
23: ; preds = %21
%24 = add nsw i32 %10, -1
br label %27
25: ; preds = %21
%26 = add nsw i32 %9, 1
br label %27
27: ; preds = %7, %19, %23, %25
%28 = phi i32 [ %9, %19 ], [ %9, %23 ], [ %26, %25 ], [ %9, %7 ]
%29 = phi i32 [ %20, %19 ], [ %24, %23 ], [ 0, %25 ], [ %10, %7 ]
%30 = add nuw i64 %8, 1
br label %7
}