#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 *eval_clause(char const *, int, int, char **);
int /*<<< orphan*/ pperror(char *, char const *);
char *xstrdup(char *);
char *expand_dollar_with_args(const char **str, int argc, char *argv[]) {
  const char *p = *str;
  const char *q;
  int nest = 0;
  if (*p != '(') {
    *str = p;
    return xstrdup("$");
  }
  p++;
  q = p;
  while (*q) {
    if (*q == '(') {
      nest++;
    } else if (*q == ')') {
      if (nest-- == 0)
        break;
    }
    q++;
  }
  if (!*q)
    pperror("unterminated reference to '%s': missing ')'", p);
  *str = q + 1;
  return eval_clause(p, q - p, argc, argv);
}


x86 assembly (clang, -O0):
<expand_dollar_with_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
je     1185 <expand_dollar_with_args+0x55>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
lea    0xe89(%rip),%rdi
call   1050 <xstrdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1255 <expand_dollar_with_args+0x125>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
je     1208 <expand_dollar_with_args+0xd8>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
jne    11c4 <expand_dollar_with_args+0x94>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11f7 <expand_dollar_with_args+0xc7>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x29,%eax
jne    11f2 <expand_dollar_with_args+0xc2>
mov    -0x34(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x34(%rbp)
cmp    $0x0,%eax
jne    11ed <expand_dollar_with_args+0xbd>
jmp    1208 <expand_dollar_with_args+0xd8>
jmp    11f2 <expand_dollar_with_args+0xc2>
jmp    11f7 <expand_dollar_with_args+0xc7>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1199 <expand_dollar_with_args+0x69>
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1225 <expand_dollar_with_args+0xf5>
mov    -0x28(%rbp),%rsi
lea    0xde2(%rip),%rdi
call   1040 <pperror@plt>
mov    -0x30(%rbp),%rcx
add    $0x1,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1030 <eval_clause@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand_dollar_with_args>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%rbx
cmpb   $0x28,(%rbx)
jne    1187 <expand_dollar_with_args+0x57>
mov    %rdx,%r14
mov    %esi,%r12d
mov    %rdi,%r13
lea    0x1(%rbx),%r15
add    $0x2,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
jmp    116a <expand_dollar_with_args+0x3a>
nopw   0x0(%rax,%rax,1)
add    $0x1,%eax
add    $0x1,%ebp
add    $0x1,%rbx
movzbl -0x1(%rbx),%ecx
cmp    $0x28,%cl
je     1160 <expand_dollar_with_args+0x30>
cmp    $0x29,%cl
je     1180 <expand_dollar_with_args+0x50>
test   %cl,%cl
jne    1163 <expand_dollar_with_args+0x33>
jmp    11a1 <expand_dollar_with_args+0x71>
xchg   %ax,%ax
sub    $0x1,%eax
jae    1163 <expand_dollar_with_args+0x33>
jmp    11b0 <expand_dollar_with_args+0x80>
lea    0xe72(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <xstrdup@plt>
lea    0xe5a(%rip),%rdi
mov    %r15,%rsi
call   1040 <pperror@plt>
mov    %rbx,0x0(%r13)
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <eval_clause@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"$\00"
@.str.1 = [44 x i8] c"unterminated reference to '%s': missing ')'\00"
define i8* @expand_dollar_with_args(i8** %0, i32 %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8** %0, i8*** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%11 = load i8**, i8*** %5
%12 = load i8*, i8** %11
store i8* %12, i8** %8
store i32 0, i32* %10
%13 = load i8*, i8** %8
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 40
br i1 %16, label %17, label %21
17: ; preds = %3
%18 = load i8*, i8** %8
%19 = load i8**, i8*** %5
store i8* %18, i8** %19
%20 = call i8* @xstrdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %20, i8** %4
br label %73
21: ; preds = %3
%22 = load i8*, i8** %8
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %8
%24 = load i8*, i8** %8
store i8* %24, i8** %9
br label %25
25: ; preds = %49, %21
%26 = load i8*, i8** %9
%27 = load i8, i8* %26
%28 = icmp ne i8 %27, 0
br i1 %28, label %29, label %52
29: ; preds = %25
%30 = load i8*, i8** %9
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 40
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
store i32 %36, i32* %10
br label %49
37: ; preds = %29
%38 = load i8*, i8** %9
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 41
br i1 %41, label %42, label %48
42: ; preds = %37
%43 = load i32, i32* %10
%44 = add nsw i32 %43, -1
store i32 %44, i32* %10
%45 = icmp eq i32 %43, 0
br i1 %45, label %46, label %47
46: ; preds = %42
br label %52
47: ; preds = %42
br label %48
48: ; preds = %47, %37
br label %49
49: ; preds = %48, %34
%50 = load i8*, i8** %9
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %9
br label %25
52: ; preds = %46, %25
%53 = load i8*, i8** %9
%54 = load i8, i8* %53
%55 = icmp ne i8 %54, 0
br i1 %55, label %59, label %56
56: ; preds = %52
%57 = load i8*, i8** %8
%58 = call i32 @pperror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %57)
br label %59
59: ; preds = %56, %52
%60 = load i8*, i8** %9
%61 = getelementptr inbounds i8, i8* %60, i64 1
%62 = load i8**, i8*** %5
store i8* %61, i8** %62
%63 = load i8*, i8** %8
%64 = load i8*, i8** %9
%65 = load i8*, i8** %8
%66 = ptrtoint i8* %64 to i64
%67 = ptrtoint i8* %65 to i64
%68 = sub i64 %66, %67
%69 = trunc i64 %68 to i32
%70 = load i32, i32* %6
%71 = load i8**, i8*** %7
%72 = call i8* @eval_clause(i8* %63, i32 %69, i32 %70, i8** %71)
store i8* %72, i8** %4
br label %73
73: ; preds = %59, %17
%74 = load i8*, i8** %4
ret i8* %74
}

LLVM IR (-O2):
@.str = [2 x i8] c"$\00"
@.str.1 = [44 x i8] c"unterminated reference to '%s': missing ')'\00"
define i8* @expand_dollar_with_args(i8** nocapture %0, i32 %1, i8** %2) {
%4 = load i8*, i8** %0
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 40
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i8* @xstrdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %32
9: ; preds = %3
%10 = getelementptr inbounds i8, i8* %4, i64 1
br label %11
11: ; preds = %20, %9
%12 = phi i8* [ %10, %9 ], [ %22, %20 ]
%13 = phi i32 [ 0, %9 ], [ %21, %20 ]
%14 = load i8, i8* %12
switch i8 %14, label %20 [
i8 0, label %23
i8 40, label %15
i8 41, label %17
]
15: ; preds = %11
%16 = add nsw i32 %13, 1
br label %20
17: ; preds = %11
%18 = add nsw i32 %13, -1
%19 = icmp eq i32 %13, 0
br i1 %19, label %25, label %20
20: ; preds = %11, %17, %15
%21 = phi i32 [ %16, %15 ], [ %18, %17 ], [ %13, %11 ]
%22 = getelementptr inbounds i8, i8* %12, i64 1
br label %11
23: ; preds = %11
%24 = tail call i32 @pperror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %10)
br label %25
25: ; preds = %17, %23
%26 = getelementptr inbounds i8, i8* %12, i64 1
store i8* %26, i8** %0
%27 = ptrtoint i8* %12 to i64
%28 = ptrtoint i8* %10 to i64
%29 = sub i64 %27, %28
%30 = trunc i64 %29 to i32
%31 = tail call i8* @eval_clause(i8* %10, i32 %30, i32 %1, i8** %2)
br label %32
32: ; preds = %25, %7
%33 = phi i8* [ %8, %7 ], [ %31, %25 ]
ret i8* %33
}