#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__ asm_str_insidesep(char *, char **, char, char);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ test_insidesep(char *, char, char);
int main(void) {
  printf("\nWorking\n");
  test_insidesep("(xx(yy)zz)", '(', ')');
  printf("\nWorking 2\n");
  test_insidesep("(xx(aa(bb)cc)zz)", '(', ')');
  printf("\nWorking All\n");
  test_insidesep("(ca)", '(', ')');
  printf("\nDifferent Side Balance\n");
  test_insidesep("(ca))", '(', ')');
  printf("\nNo Seperators\n");
  test_insidesep("ca", '(', ')');
  printf("\nNo 1\n");
  test_insidesep("(ca", '(', ')');
  printf("\nNo 2\n");
  test_insidesep("ca)", '(', ')');
  printf("\nTwo Seperators\n");
  test_insidesep("(asdf) (ghjk)", '(', ')');
  char *exp = malloc(128);
  char *dst = malloc(128);
  strcpy(exp, "(asdf(qq)j(fn)kl)");
  printf("\n%s\n", exp);
  while (asm_str_insidesep(dst, &exp, '(', ')')) {
    printf("%s -> %s\n", exp, dst);
  }
  free(exp);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe86(%rip),%rdi
mov    $0x28,%esi
mov    $0x29,%edx
call   1060 <test_insidesep@plt>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe79(%rip),%rdi
mov    $0x28,%esi
mov    $0x29,%edx
call   1060 <test_insidesep@plt>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe74(%rip),%rdi
mov    $0x28,%esi
mov    $0x29,%edx
call   1060 <test_insidesep@plt>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe6e(%rip),%rdi
mov    $0x28,%esi
mov    $0x29,%edx
call   1060 <test_insidesep@plt>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe68(%rip),%rdi
mov    $0x28,%esi
mov    $0x29,%edx
call   1060 <test_insidesep@plt>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe43(%rip),%rdi
mov    $0x28,%esi
mov    $0x29,%edx
call   1060 <test_insidesep@plt>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xde5(%rip),%rdi
mov    $0x28,%esi
mov    $0x29,%edx
call   1060 <test_insidesep@plt>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe17(%rip),%rdi
mov    $0x28,%esi
mov    $0x29,%edx
call   1060 <test_insidesep@plt>
mov    $0x80,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x80,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdef(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rsi
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x28,%edx
mov    $0x29,%ecx
call   1080 <asm_str_insidesep@plt>
cmp    $0x0,%rax
je     1309 <main+0x1a9>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12cd <main+0x16d>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeda(%rip),%rdi
call   1050 <puts@plt>
lea    0xe74(%rip),%rdi
mov    $0x28,%esi
mov    $0x29,%edx
call   1070 <test_insidesep@plt>
lea    0xec1(%rip),%rdi
call   1050 <puts@plt>
lea    0xe5d(%rip),%rdi
mov    $0x28,%esi
mov    $0x29,%edx
call   1070 <test_insidesep@plt>
lea    0xeaa(%rip),%rdi
call   1050 <puts@plt>
lea    0xe4c(%rip),%rdi
mov    $0x28,%esi
mov    $0x29,%edx
call   1070 <test_insidesep@plt>
lea    0xe95(%rip),%rdi
call   1050 <puts@plt>
lea    0xe2f(%rip),%rdi
mov    $0x28,%esi
mov    $0x29,%edx
call   1070 <test_insidesep@plt>
lea    0xe8b(%rip),%rdi
call   1050 <puts@plt>
lea    0xe14(%rip),%rdi
mov    $0x28,%esi
mov    $0x29,%edx
call   1070 <test_insidesep@plt>
lea    0xe78(%rip),%rdi
call   1050 <puts@plt>
lea    0xdf1(%rip),%rdi
mov    $0x28,%esi
mov    $0x29,%edx
call   1070 <test_insidesep@plt>
lea    0xe5c(%rip),%rdi
call   1050 <puts@plt>
lea    0xdc5(%rip),%rdi
mov    $0x28,%esi
mov    $0x29,%edx
call   1070 <test_insidesep@plt>
lea    0xe40(%rip),%rdi
call   1050 <puts@plt>
lea    0xdb1(%rip),%rdi
mov    $0x28,%esi
mov    $0x29,%edx
call   1070 <test_insidesep@plt>
mov    $0x80,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rax,0x8(%rsp)
mov    $0x80,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xd8a(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
lea    0xd8d(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x28,%edx
mov    $0x29,%ecx
call   1090 <asm_str_insidesep@plt>
test   %rax,%rax
je     131c <main+0x1ac>
lea    0xd65(%rip),%r14
lea    0x8(%rsp),%r15
mov    0x8(%rsp),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x28,%edx
mov    $0x29,%ecx
call   1090 <asm_str_insidesep@plt>
test   %rax,%rax
jne    12f0 <main+0x180>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"\0AWorking\0A\00"
@.str.1 = [11 x i8] c"(xx(yy)zz)\00"
@.str.2 = [12 x i8] c"\0AWorking 2\0A\00"
@.str.3 = [17 x i8] c"(xx(aa(bb)cc)zz)\00"
@.str.4 = [14 x i8] c"\0AWorking All\0A\00"
@.str.5 = [5 x i8] c"(ca)\00"
@.str.6 = [25 x i8] c"\0ADifferent Side Balance\0A\00"
@.str.7 = [6 x i8] c"(ca))\00"
@.str.8 = [16 x i8] c"\0ANo Seperators\0A\00"
@.str.9 = [3 x i8] c"ca\00"
@.str.10 = [7 x i8] c"\0ANo 1\0A\00"
@.str.11 = [4 x i8] c"(ca\00"
@.str.12 = [7 x i8] c"\0ANo 2\0A\00"
@.str.13 = [4 x i8] c"ca)\00"
@.str.14 = [17 x i8] c"\0ATwo Seperators\0A\00"
@.str.15 = [14 x i8] c"(asdf) (ghjk)\00"
@.str.16 = [18 x i8] c"(asdf(qq)j(fn)kl)\00"
@.str.17 = [5 x i8] c"\0A%s\0A\00"
@.str.18 = [10 x i8] c"%s -> %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @test_insidesep(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8 signext 40, i8 signext 41)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @test_insidesep(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8 signext 40, i8 signext 41)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%9 = call i32 @test_insidesep(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8 signext 40, i8 signext 41)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%11 = call i32 @test_insidesep(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8 signext 40, i8 signext 41)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%13 = call i32 @test_insidesep(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8 signext 40, i8 signext 41)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
%15 = call i32 @test_insidesep(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8 signext 40, i8 signext 41)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
%17 = call i32 @test_insidesep(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), i8 signext 40, i8 signext 41)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.14, i64 0, i64 0))
%19 = call i32 @test_insidesep(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.15, i64 0, i64 0), i8 signext 40, i8 signext 41)
%20 = call i8* @malloc(i32 128)
store i8* %20, i8** %2
%21 = call i8* @malloc(i32 128)
store i8* %21, i8** %3
%22 = load i8*, i8** %2
%23 = call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.16, i64 0, i64 0))
%24 = load i8*, i8** %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.17, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %30, %0
%27 = load i8*, i8** %3
%28 = call i64 @asm_str_insidesep(i8* %27, i8** %2, i8 signext 40, i8 signext 41)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i8*, i8** %2
%32 = load i8*, i8** %3
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.18, i64 0, i64 0), i8* %31, i8* %32)
br label %26
34: ; preds = %26
%35 = load i8*, i8** %2
%36 = call i32 @free(i8* %35)
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@.str.1 = [11 x i8] c"(xx(yy)zz)\00"
@.str.3 = [17 x i8] c"(xx(aa(bb)cc)zz)\00"
@.str.5 = [5 x i8] c"(ca)\00"
@.str.7 = [6 x i8] c"(ca))\00"
@.str.9 = [3 x i8] c"ca\00"
@.str.11 = [4 x i8] c"(ca\00"
@.str.13 = [4 x i8] c"ca)\00"
@.str.15 = [14 x i8] c"(asdf) (ghjk)\00"
@.str.16 = [18 x i8] c"(asdf(qq)j(fn)kl)\00"
@.str.17 = [5 x i8] c"\0A%s\0A\00"
@.str.18 = [10 x i8] c"%s -> %s\0A\00"
@str = [9 x i8] c"\0AWorking\00"
@str.19 = [11 x i8] c"\0AWorking 2\00"
@str.20 = [13 x i8] c"\0AWorking All\00"
@str.21 = [24 x i8] c"\0ADifferent Side Balance\00"
@str.22 = [15 x i8] c"\0ANo Seperators\00"
@str.23 = [6 x i8] c"\0ANo 1\00"
@str.24 = [6 x i8] c"\0ANo 2\00"
@str.25 = [16 x i8] c"\0ATwo Seperators\00"
define i32 @main() {
%1 = alloca i8*
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @test_insidesep(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8 signext 40, i8 signext 41)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.19, i64 0, i64 0))
%5 = tail call i32 @test_insidesep(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8 signext 40, i8 signext 41)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.20, i64 0, i64 0))
%7 = tail call i32 @test_insidesep(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8 signext 40, i8 signext 41)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.21, i64 0, i64 0))
%9 = tail call i32 @test_insidesep(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8 signext 40, i8 signext 41)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.22, i64 0, i64 0))
%11 = tail call i32 @test_insidesep(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8 signext 40, i8 signext 41)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.23, i64 0, i64 0))
%13 = tail call i32 @test_insidesep(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8 signext 40, i8 signext 41)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.24, i64 0, i64 0))
%15 = tail call i32 @test_insidesep(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), i8 signext 40, i8 signext 41)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.25, i64 0, i64 0))
%17 = tail call i32 @test_insidesep(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.15, i64 0, i64 0), i8 signext 40, i8 signext 41)
%18 = bitcast i8** %1 to i8*
%19 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
store i8* %19, i8** %1
%20 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
%21 = tail call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.16, i64 0, i64 0))
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.17, i64 0, i64 0), i8* %19)
%23 = call i64 @asm_str_insidesep(i8* %20, i8** %1, i8 signext 40, i8 signext 41)
%24 = icmp eq i64 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %0, %25
%26 = load i8*, i8** %1
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.18, i64 0, i64 0), i8* %26, i8* %20)
%28 = call i64 @asm_str_insidesep(i8* %20, i8** %1, i8 signext 40, i8 signext 41)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %25
30: ; preds = %25, %0
%31 = load i8*, i8** %1
%32 = call i32 @free(i8* %31)
ret i32 0
}