#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__ min(int /*<<< orphan*/, int);
int /*<<< orphan*/ strlen(char *);
char *ee_extract_next_term(char *eqn, char scratch[1024]) {
  int paren_count = 1;
  int i;
  if (eqn[0] != '(')
    return (eqn);
  eqn++;
  for (i = 0; i < (signed int)min(strlen(eqn), 1024 - 1); i++) {
    if (eqn[i] == '(')
      paren_count++;
    if (eqn[i] == ')')
      paren_count--;
    if (paren_count == 0) {
      scratch[i] = '\0';
      break;
    }
    scratch[i] = eqn[i];
  }
  return scratch;
}


x86 assembly (clang, -O0):
<ee_extract_next_term>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
je     1154 <ee_extract_next_term+0x34>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1213 <ee_extract_next_term+0xf3>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
mov    $0x3ff,%esi
call   1040 <min@plt>
mov    %rax,%rcx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    120b <ee_extract_next_term+0xeb>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x28,%eax
jne    11ae <ee_extract_next_term+0x8e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x29,%eax
jne    11cc <ee_extract_next_term+0xac>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11e7 <ee_extract_next_term+0xc7>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    120b <ee_extract_next_term+0xeb>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1167 <ee_extract_next_term+0x47>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ee_extract_next_term>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
cmpb   $0x28,(%rdi)
jne    119e <ee_extract_next_term+0x7e>
mov    %rsi,%r14
add    $0x1,%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
mov    $0x3ff,%esi
call   1040 <min@plt>
test   %eax,%eax
jle    11a8 <ee_extract_next_term+0x88>
mov    $0x1,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r15,%rbx,1),%eax
xor    %ecx,%ecx
cmp    $0x28,%al
sete   %cl
add    %ecx,%ebp
xor    %ecx,%ecx
cmp    $0x29,%al
sete   %cl
sub    %ecx,%ebp
je     11a3 <ee_extract_next_term+0x83>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
mov    $0x3ff,%esi
call   1040 <min@plt>
cltq
cmp    %rax,%rbx
jl     1160 <ee_extract_next_term+0x40>
jmp    11a8 <ee_extract_next_term+0x88>
mov    %r15,%r14
jmp    11a8 <ee_extract_next_term+0x88>
movb   $0x0,(%r14,%rbx,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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