#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 *close_parens(char *, char *);
char *strchr(char *, char);
char *strstr(char *, char *);
char *first_operator(char *pattern, char *start, char *end) {
  char *position, *open, *close;
  close = start;
  while ((position = strstr(close, pattern)) != NULL && position < end) {
    while (position > close) {
      open = strchr(close, '(');
      if (open != NULL && open < end)
        close = close_parens(open, end);
      else
        return position;
    }
    if (position > open && position < close)
      continue;
    else
      return position;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<first_operator>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,%rcx
mov    %rcx,-0x28(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x39(%rbp)
je     117d <first_operator+0x4d>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
setb   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    118d <first_operator+0x5d>
jmp    1221 <first_operator+0xf1>
jmp    1192 <first_operator+0x62>
mov    -0x28(%rbp),%rax
cmp    -0x38(%rbp),%rax
jbe    11f3 <first_operator+0xc3>
mov    -0x38(%rbp),%rdi
mov    $0x28,%esi
call   1030 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11e1 <first_operator+0xb1>
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11e1 <first_operator+0xb1>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <close_parens@plt>
mov    %rax,-0x38(%rbp)
jmp    11ee <first_operator+0xbe>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1229 <first_operator+0xf9>
jmp    1192 <first_operator+0x62>
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jbe    1214 <first_operator+0xe4>
mov    -0x28(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    1214 <first_operator+0xe4>
jmp    114c <first_operator+0x1c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1229 <first_operator+0xf9>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<first_operator>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r14
mov    %r13,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     11b9 <first_operator+0x89>
mov    %rax,%r12
mov    $0x0,%eax
cmp    %r15,%r12
jae    11af <first_operator+0x7f>
cmp    %r13,%r12
jbe    119d <first_operator+0x6d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
mov    $0x28,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11ac <first_operator+0x7c>
mov    %rax,%rbx
cmp    %r15,%rax
jae    11ac <first_operator+0x7c>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <close_parens@plt>
mov    %rax,%r13
cmp    %rax,%r12
ja     1170 <first_operator+0x40>
cmp    %rbx,%r12
jbe    11ac <first_operator+0x7c>
mov    %r12,%rax
cmp    %r13,%r12
jb     1142 <first_operator+0x12>
jmp    11af <first_operator+0x7f>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
xor    %eax,%eax
jmp    11af <first_operator+0x7f>

LLVM IR (-O0):
define i8* @first_operator(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %6
store i8* %11, i8** %10
br label %12
12: ; preds = %52, %3
%13 = load i8*, i8** %10
%14 = load i8*, i8** %5
%15 = call i8* @strstr(i8* %13, i8* %14)
store i8* %15, i8** %8
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i8*, i8** %8
%19 = load i8*, i8** %7
%20 = icmp ult i8* %18, %19
br label %21
21: ; preds = %17, %12
%22 = phi i1 [ false, %12 ], [ %20, %17 ]
br i1 %22, label %23, label %55
23: ; preds = %21
br label %24
24: ; preds = %43, %23
%25 = load i8*, i8** %8
%26 = load i8*, i8** %10
%27 = icmp ugt i8* %25, %26
br i1 %27, label %28, label %44
28: ; preds = %24
%29 = load i8*, i8** %10
%30 = call i8* @strchr(i8* %29, i8 signext 40)
store i8* %30, i8** %9
%31 = load i8*, i8** %9
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %41
33: ; preds = %28
%34 = load i8*, i8** %9
%35 = load i8*, i8** %7
%36 = icmp ult i8* %34, %35
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i8*, i8** %9
%39 = load i8*, i8** %7
%40 = call i8* @close_parens(i8* %38, i8* %39)
store i8* %40, i8** %10
br label %43
41: ; preds = %33, %28
%42 = load i8*, i8** %8
store i8* %42, i8** %4
br label %56
43: ; preds = %37
br label %24
44: ; preds = %24
%45 = load i8*, i8** %8
%46 = load i8*, i8** %9
%47 = icmp ugt i8* %45, %46
br i1 %47, label %48, label %53
48: ; preds = %44
%49 = load i8*, i8** %8
%50 = load i8*, i8** %10
%51 = icmp ult i8* %49, %50
br i1 %51, label %52, label %53
52: ; preds = %48
br label %12
53: ; preds = %48, %44
%54 = load i8*, i8** %8
store i8* %54, i8** %4
br label %56
55: ; preds = %21
store i8* null, i8** %4
br label %56
56: ; preds = %55, %53, %41
%57 = load i8*, i8** %4
ret i8* %57
}

LLVM IR (-O2):
define i8* @first_operator(i8* nocapture %0, i8* %1, i8* %2) {
br label %4
4: ; preds = %22, %3
%5 = phi i8* [ undef, %3 ], [ %23, %22 ]
%6 = phi i8* [ %1, %3 ], [ %24, %22 ]
%7 = tail call i8* @strstr(i8* dereferenceable(1) %6, i8* dereferenceable(1) %0)
%8 = icmp ne i8* %7, null
%9 = icmp ult i8* %7, %2
%10 = and i1 %8, %9
br i1 %10, label %11, label %28
11: ; preds = %4
%12 = icmp ugt i8* %7, %6
br i1 %12, label %13, label %22
13: ; preds = %11, %19
%14 = phi i8* [ %20, %19 ], [ %6, %11 ]
%15 = tail call i8* @strchr(i8* dereferenceable(1) %14, i8 signext 40)
%16 = icmp ne i8* %15, null
%17 = icmp ult i8* %15, %2
%18 = and i1 %16, %17
br i1 %18, label %19, label %28
19: ; preds = %13
%20 = tail call i8* @close_parens(i8* %15, i8* %2)
%21 = icmp ugt i8* %7, %20
br i1 %21, label %13, label %22
22: ; preds = %19, %11
%23 = phi i8* [ %5, %11 ], [ %15, %19 ]
%24 = phi i8* [ %6, %11 ], [ %20, %19 ]
%25 = icmp ugt i8* %7, %23
%26 = icmp ult i8* %7, %24
%27 = select i1 %25, i1 %26, i1 false
br i1 %27, label %4, label %28
28: ; preds = %4, %22, %13
%29 = phi i8* [ %7, %13 ], [ null, %4 ], [ %7, %22 ]
ret i8* %29
}