#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 */
int strlen(char *);
int /*<<< orphan*/ strncmp(char const *, char *, int);
int splice_infix(const char *buf, int pos1, int pos2, char *sep, int *spl1,
                 int *spl2) {
  int pos, numpar, l;
  const char *p;
  numpar = 0;
  l = strlen(sep);
  for (pos = pos2 - 1, p = buf + pos; pos >= pos1; pos--, p--) {
    if (*p == ')')
      numpar++;
    if (*p == '(')
      numpar--;
    if (numpar < 0)
      return 0;
    if ((numpar == 0) && (pos2 - pos >= l) && !strncmp(p, sep, l)) {
      *spl1 = pos;
      *spl2 = pos + l;
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<splice_infix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     122f <splice_infix+0x10f>
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x29,%eax
jne    118e <splice_infix+0x6e>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
jne    11a7 <splice_infix+0x87>
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    11bd <splice_infix+0x9d>
movl   $0x0,-0x4(%rbp)
jmp    1236 <splice_infix+0x116>
cmpl   $0x0,-0x38(%rbp)
jne    1210 <splice_infix+0xf0>
mov    -0x18(%rbp),%eax
sub    -0x34(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jl     1210 <splice_infix+0xf0>
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1210 <splice_infix+0xf0>
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x34(%rbp),%ecx
add    -0x3c(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1236 <splice_infix+0x116>
jmp    1215 <splice_infix+0xf5>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
mov    -0x48(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x48(%rbp)
jmp    1169 <splice_infix+0x49>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<splice_infix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%r15
mov    %r8,%r12
mov    %edx,%r13d
mov    %esi,%ebx
mov    %rdi,%r14
mov    %rcx,0x20(%rsp)
mov    %rcx,%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
xor    %eax,%eax
cmp    %ebx,%r13d
jle    120c <splice_infix+0xec>
mov    %r12,0x10(%rsp)
mov    %r15,0x18(%rsp)
lea    -0x1(%r13),%eax
mov    %eax,(%rsp)
cltq
add    %rax,%r14
mov    %r13,0x8(%rsp)
mov    %r13d,%ebp
mov    $0x1,%r13d
xor    %r15d,%r15d
xor    %r12d,%r12d
mov    %ebx,0x4(%rsp)
jmp    11a0 <splice_infix+0x80>
cs nopw 0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%r15
lea    (%r15,%rbp,1),%eax
add    $0x1,%r13d
cmp    %ebx,%eax
jle    120a <splice_infix+0xea>
movzbl (%r14,%r15,1),%eax
xor    %ecx,%ecx
cmp    $0x29,%al
sete   %cl
add    %ecx,%r12d
xor    %ecx,%ecx
cmp    $0x28,%al
sete   %cl
sub    %ecx,%r12d
js     120a <splice_infix+0xea>
jne    1190 <splice_infix+0x70>
cmp    %edx,%r13d
jl     1190 <splice_infix+0x70>
lea    (%r14,%r15,1),%rdi
mov    0x20(%rsp),%rsi
mov    %r14,%rbx
mov    %rdx,%r14
call   1030 <strncmp@plt>
mov    %r14,%rdx
mov    %rbx,%r14
mov    0x4(%rsp),%ebx
test   %eax,%eax
jne    1190 <splice_infix+0x70>
mov    (%rsp),%ecx
add    %r15d,%ecx
mov    0x10(%rsp),%rax
mov    %ecx,(%rax)
add    0x8(%rsp),%edx
lea    (%r15,%rdx,1),%eax
add    $0xffffffff,%eax
mov    0x18(%rsp),%rcx
mov    %eax,(%rcx)
mov    $0x1,%eax
jmp    120c <splice_infix+0xec>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @splice_infix(i8* %0, i32 %1, i32 %2, i8* %3, i32* nocapture writeonly %4, i32* nocapture writeonly %5) {
%7 = tail call i32 @strlen(i8* %3)
%8 = add nsw i32 %2, -1
%9 = icmp sgt i32 %2, %1
br i1 %9, label %10, label %39
10: ; preds = %6
%11 = sext i32 %8 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
br label %13
13: ; preds = %10, %35
%14 = phi i8* [ %37, %35 ], [ %12, %10 ]
%15 = phi i32 [ %23, %35 ], [ 0, %10 ]
%16 = phi i32 [ %36, %35 ], [ %8, %10 ]
%17 = load i8, i8* %14
%18 = icmp eq i8 %17, 41
%19 = zext i1 %18 to i32
%20 = add nuw nsw i32 %15, %19
%21 = icmp eq i8 %17, 40
%22 = sext i1 %21 to i32
%23 = add nsw i32 %20, %22
%24 = icmp slt i32 %23, 0
br i1 %24, label %39, label %25
25: ; preds = %13
%26 = icmp ne i32 %23, 0
%27 = sub nsw i32 %2, %16
%28 = icmp slt i32 %27, %7
%29 = select i1 %26, i1 true, i1 %28
br i1 %29, label %35, label %30
30: ; preds = %25
%31 = tail call i32 @strncmp(i8* %14, i8* %3, i32 %7)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
store i32 %16, i32* %4
%34 = add nsw i32 %16, %7
store i32 %34, i32* %5
br label %39
35: ; preds = %25, %30
%36 = add nsw i32 %16, -1
%37 = getelementptr inbounds i8, i8* %14, i64 -1
%38 = icmp sgt i32 %16, %1
br i1 %38, label %13, label %39
39: ; preds = %13, %35, %6, %33
%40 = phi i32 [ 1, %33 ], [ 0, %6 ], [ 0, %35 ], [ 0, %13 ]
ret i32 %40
}