#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 /*<<< orphan*/ dbgprintf(char *, char const *);
char *find_matching_parenthesis(char const *);
int /*<<< orphan*/ isspace(char const);
char *skip_space(char const *);
char *find_expr_end(const char *e) {
  dbgprintf("find_expr_end: %s\n", e);
  if (*e == '\'')
    ++e;
  e = skip_space(e);
  if (*e == '(') {
    e = find_matching_parenthesis(e);
    return (char *)(*e == ')' ? e + 1 : e);
  } else {
    while (!isspace(*e) && *e != '(' && *e != ')' && *e != '\0')
      ++e;
    return (char *)e;
  }
}


x86 assembly (clang, -O0):
<find_expr_end>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea9(%rip),%rdi
call   1050 <dbgprintf@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x27,%eax
jne    1178 <find_expr_end+0x38>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <skip_space@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
jne    11d8 <find_expr_end+0x98>
mov    -0x10(%rbp),%rdi
call   1060 <find_matching_parenthesis@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x29,%eax
jne    11c3 <find_expr_end+0x83>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11cb <find_expr_end+0x8b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    125c <find_expr_end+0x11c>
jmp    11dd <find_expr_end+0x9d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
jne    1233 <find_expr_end+0xf3>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x28,%ecx
mov    %al,-0x19(%rbp)
je     1233 <find_expr_end+0xf3>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x29,%ecx
mov    %al,-0x19(%rbp)
je     1233 <find_expr_end+0xf3>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1243 <find_expr_end+0x103>
jmp    1254 <find_expr_end+0x114>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11dd <find_expr_end+0x9d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_expr_end>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xeb2(%rip),%rdi
mov    %rbx,%rsi
call   1050 <dbgprintf@plt>
xor    %edi,%edi
cmpb   $0x27,(%rbx)
sete   %dil
add    %rbx,%rdi
call   1030 <skip_space@plt>
mov    %rax,%rbx
mov    (%rax),%al
cmp    $0x28,%al
jne    1185 <find_expr_end+0x45>
mov    %rbx,%rdi
call   1060 <find_matching_parenthesis@plt>
xor    %ebx,%ebx
cmpb   $0x29,(%rax)
sete   %bl
add    %rax,%rbx
jmp    11c0 <find_expr_end+0x80>
movsbl %al,%edi
call   1040 <isspace@plt>
test   %eax,%eax
jne    11c0 <find_expr_end+0x80>
movabs $0x30000000001,%r14
jmp    11b1 <find_expr_end+0x71>
nopl   (%rax)
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1040 <isspace@plt>
test   %eax,%eax
jne    11c0 <find_expr_end+0x80>
movzbl (%rbx),%eax
cmp    $0x29,%rax
ja     11a0 <find_expr_end+0x60>
bt     %rax,%r14
jae    11a0 <find_expr_end+0x60>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"find_expr_end: %s\0A\00"
define i8* @find_expr_end(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = call i32 @dbgprintf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 39
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %3
br label %13
13: ; preds = %10, %1
%14 = load i8*, i8** %3
%15 = call i8* @skip_space(i8* %14)
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 40
br i1 %19, label %20, label %34
20: ; preds = %13
%21 = load i8*, i8** %3
%22 = call i8* @find_matching_parenthesis(i8* %21)
store i8* %22, i8** %3
%23 = load i8*, i8** %3
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 41
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 1
br label %32
30: ; preds = %20
%31 = load i8*, i8** %3
br label %32
32: ; preds = %30, %27
%33 = phi i8* [ %29, %27 ], [ %31, %30 ]
store i8* %33, i8** %2
br label %62
34: ; preds = %13
br label %35
35: ; preds = %57, %34
%36 = load i8*, i8** %3
%37 = load i8, i8* %36
%38 = call i32 @isspace(i8 signext %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %55, label %40
40: ; preds = %35
%41 = load i8*, i8** %3
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 40
br i1 %44, label %45, label %55
45: ; preds = %40
%46 = load i8*, i8** %3
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 41
br i1 %49, label %50, label %55
50: ; preds = %45
%51 = load i8*, i8** %3
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 0
br label %55
55: ; preds = %50, %45, %40, %35
%56 = phi i1 [ false, %45 ], [ false, %40 ], [ false, %35 ], [ %54, %50 ]
br i1 %56, label %57, label %60
57: ; preds = %55
%58 = load i8*, i8** %3
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %3
br label %35
60: ; preds = %55
%61 = load i8*, i8** %3
store i8* %61, i8** %2
br label %62
62: ; preds = %60, %32
%63 = load i8*, i8** %2
ret i8* %63
}

LLVM IR (-O2):
@.str = [19 x i8] c"find_expr_end: %s\0A\00"
define i8* @find_expr_end(i8* %0) {
%2 = tail call i32 @dbgprintf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 39
%5 = zext i1 %4 to i64
%6 = getelementptr i8, i8* %0, i64 %5
%7 = tail call i8* @skip_space(i8* %6)
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 40
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = tail call i32 @isspace(i8 signext %8)
%12 = icmp eq i32 %11, 0
br i1 %12, label %19, label %27
13: ; preds = %1
%14 = tail call i8* @find_matching_parenthesis(i8* %7)
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 41
%17 = zext i1 %16 to i64
%18 = getelementptr i8, i8* %14, i64 %17
br label %27
19: ; preds = %10, %22
%20 = phi i8* [ %23, %22 ], [ %7, %10 ]
%21 = load i8, i8* %20
switch i8 %21, label %22 [
i8 40, label %27
i8 41, label %27
i8 0, label %27
]
22: ; preds = %19
%23 = getelementptr inbounds i8, i8* %20, i64 1
%24 = load i8, i8* %23
%25 = tail call i32 @isspace(i8 signext %24)
%26 = icmp eq i32 %25, 0
br i1 %26, label %19, label %27
27: ; preds = %19, %19, %19, %22, %10, %13
%28 = phi i8* [ %18, %13 ], [ %7, %10 ], [ %20, %19 ], [ %20, %19 ], [ %20, %19 ], [ %23, %22 ]
ret i8* %28
}