#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 */
typedef int /*<<< orphan*/ wordexp_t;

/* Variables and functions */
int WRDE_NOSPACE;
int WRDE_SYNTAX;
int exec_comm(char *, char **, size_t *, size_t *, int, int /*<<< orphan*/ *,
              char const *, char const *);
int /*<<< orphan*/ free(char *);
char *w_addchar(char *, size_t *, size_t *, char const);
char *w_newword(size_t *, size_t *);
int parse_comm(char **word, size_t *word_length, size_t *max_length,
               const char *words, size_t *offset, int flags,
               wordexp_t *pwordexp, const char *ifs, const char *ifs_white) {
  int paren_depth = 1;
  int error = 0;
  int quoted = 0;
  size_t comm_length;
  size_t comm_maxlen;
  char *comm = w_newword(&comm_length, &comm_maxlen);
  for (; words[*offset]; ++(*offset)) {
    switch (words[*offset]) {
    case '\'':
      if (quoted == 0)
        quoted = 1;
      else if (quoted == 1)
        quoted = 0;
      break;
    case '"':
      if (quoted == 0)
        quoted = 2;
      else if (quoted == 2)
        quoted = 0;
      break;
    case ')':
      if (!quoted && --paren_depth == 0) {
        if (comm) {
          error = exec_comm(comm, word, word_length, max_length, flags,
                            pwordexp, ifs, ifs_white);
          free(comm);
        }
        return error;
      }
      break;
    case '(':
      if (!quoted)
        ++paren_depth;
    }
    comm = w_addchar(comm, &comm_length, &comm_maxlen, words[*offset]);
    if (comm == NULL)
      return WRDE_NOSPACE;
  }
  if (comm)
    free(comm);
  return WRDE_SYNTAX;
}


x86 assembly (clang, -O0):
<parse_comm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
movl   $0x1,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
lea    -0x48(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1060 <w_newword@plt>
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rcx),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     131f <parse_comm+0x1df>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rcx),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0xffffffde,%eax
mov    %eax,%ecx
mov    %rcx,-0x60(%rbp)
sub    $0x7,%eax
ja     12c7 <parse_comm+0x187>
mov    -0x60(%rbp),%rax
lea    0xe2d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x0,-0x40(%rbp)
jne    11f2 <parse_comm+0xb2>
movl   $0x1,-0x40(%rbp)
jmp    1208 <parse_comm+0xc8>
cmpl   $0x1,-0x40(%rbp)
jne    1203 <parse_comm+0xc3>
movl   $0x0,-0x40(%rbp)
jmp    1208 <parse_comm+0xc8>
jmp    12c7 <parse_comm+0x187>
cmpl   $0x0,-0x40(%rbp)
jne    1223 <parse_comm+0xe3>
movl   $0x2,-0x40(%rbp)
jmp    1239 <parse_comm+0xf9>
cmpl   $0x2,-0x40(%rbp)
jne    1234 <parse_comm+0xf4>
movl   $0x0,-0x40(%rbp)
jmp    1239 <parse_comm+0xf9>
jmp    12c7 <parse_comm+0x187>
cmpl   $0x0,-0x40(%rbp)
jne    12aa <parse_comm+0x16a>
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
cmp    $0x0,%eax
jne    12aa <parse_comm+0x16a>
cmpq   $0x0,-0x58(%rbp)
je     129f <parse_comm+0x15f>
mov    -0x58(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x34(%rbp),%r8d
mov    0x10(%rbp),%r9
mov    0x18(%rbp),%r10
mov    0x20(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <exec_comm@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    133f <parse_comm+0x1ff>
jmp    12c7 <parse_comm+0x187>
cmpl   $0x0,-0x40(%rbp)
jne    12c2 <parse_comm+0x182>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    12c7 <parse_comm+0x187>
mov    -0x58(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rcx),%rcx
lea    -0x48(%rbp),%rsi
lea    -0x50(%rbp),%rdx
movsbl (%rax,%rcx,1),%ecx
call   1050 <w_addchar@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1307 <parse_comm+0x1c7>
mov    0x2ce3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    133f <parse_comm+0x1ff>
jmp    130c <parse_comm+0x1cc>
mov    -0x30(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1192 <parse_comm+0x52>
cmpq   $0x0,-0x58(%rbp)
je     1333 <parse_comm+0x1f3>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    0x2cae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_comm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9d,%r15d
mov    %r8,%rbp
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,0x20(%rsp)
lea    0x30(%rsp),%rdi
lea    0x28(%rsp),%rsi
call   1060 <w_newword@plt>
mov    %rax,%rbx
mov    0x0(%rbp),%rax
mov    (%r14,%rax,1),%al
test   %al,%al
je     1256 <parse_comm+0x116>
mov    %r13,0x10(%rsp)
mov    %r12,0x18(%rsp)
mov    %r15d,0xc(%rsp)
mov    $0x1,%r13d
lea    0xe60(%rip),%r15
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%ecx
lea    -0x22(%rcx),%eax
cmp    $0x7,%eax
ja     1220 <parse_comm+0xe0>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
test   %r12d,%r12d
je     1210 <parse_comm+0xd0>
cmp    $0x2,%r12d
jmp    11d9 <parse_comm+0x99>
nop
test   %r12d,%r12d
je     1218 <parse_comm+0xd8>
cmp    $0x1,%r12d
mov    $0x0,%eax
cmove  %eax,%r12d
jmp    1220 <parse_comm+0xe0>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x1,%r12d
adc    $0x0,%r13d
jmp    1220 <parse_comm+0xe0>
nopw   0x0(%rax,%rax,1)
test   %r12d,%r12d
jne    1220 <parse_comm+0xe0>
xor    %r12d,%r12d
add    $0xffffffff,%r13d
jne    1220 <parse_comm+0xe0>
jmp    1286 <parse_comm+0x146>
mov    $0x2,%r12d
jmp    1220 <parse_comm+0xe0>
mov    $0x1,%r12d
xchg   %ax,%ax
mov    %rbx,%rdi
lea    0x30(%rsp),%rsi
lea    0x28(%rsp),%rdx
call   1050 <w_addchar@plt>
test   %rax,%rax
je     126c <parse_comm+0x12c>
mov    %rax,%rbx
mov    0x0(%rbp),%rax
lea    0x1(%rax),%rcx
mov    %rcx,0x0(%rbp)
movzbl 0x1(%r14,%rax,1),%eax
test   %al,%al
jne    11b0 <parse_comm+0x70>
jmp    125b <parse_comm+0x11b>
test   %rbx,%rbx
je     1263 <parse_comm+0x123>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2d7e(%rip),%rax
jmp    1273 <parse_comm+0x133>
mov    0x2d6d(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %rbx,%rbx
je     12ca <parse_comm+0x18a>
mov    %rbx,%rdi
mov    0x20(%rsp),%rsi
mov    0x10(%rsp),%rdx
mov    0x18(%rsp),%rcx
mov    0xc(%rsp),%r8d
mov    0x70(%rsp),%r9
push   0x80(%rsp)
push   0x80(%rsp)
call   1040 <exec_comm@plt>
add    $0x10,%rsp
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1275 <parse_comm+0x135>
xor    %ebp,%ebp
jmp    1275 <parse_comm+0x135>

LLVM IR (-O0):
@WRDE_NOSPACE = global i32 0
@WRDE_SYNTAX = global i32 0
define i32 @parse_comm(i8** %0, i64* %1, i64* %2, i8* %3, i64* %4, i32 %5, i32* %6, i8* %7, i8* %8) {
%10 = alloca i32
%11 = alloca i8**
%12 = alloca i64*
%13 = alloca i64*
%14 = alloca i8*
%15 = alloca i64*
%16 = alloca i32
%17 = alloca i32*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i64
%24 = alloca i64
%25 = alloca i8*
store i8** %0, i8*** %11
store i64* %1, i64** %12
store i64* %2, i64** %13
store i8* %3, i8** %14
store i64* %4, i64** %15
store i32 %5, i32* %16
store i32* %6, i32** %17
store i8* %7, i8** %18
store i8* %8, i8** %19
store i32 1, i32* %20
store i32 0, i32* %21
store i32 0, i32* %22
%26 = call i8* @w_newword(i64* %23, i64* %24)
store i8* %26, i8** %25
br label %27
27: ; preds = %106, %9
%28 = load i8*, i8** %14
%29 = load i64*, i64** %15
%30 = load i64, i64* %29
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = icmp ne i8 %32, 0
br i1 %33, label %34, label %110
34: ; preds = %27
%35 = load i8*, i8** %14
%36 = load i64*, i64** %15
%37 = load i64, i64* %36
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
switch i32 %40, label %93 [
i32 39, label %41
i32 34, label %51
i32 41, label %61
i32 40, label %86
]
41: ; preds = %34
%42 = load i32, i32* %22
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %41
store i32 1, i32* %22
br label %50
45: ; preds = %41
%46 = load i32, i32* %22
%47 = icmp eq i32 %46, 1
br i1 %47, label %48, label %49
48: ; preds = %45
store i32 0, i32* %22
br label %49
49: ; preds = %48, %45
br label %50
50: ; preds = %49, %44
br label %93
51: ; preds = %34
%52 = load i32, i32* %22
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %51
store i32 2, i32* %22
br label %60
55: ; preds = %51
%56 = load i32, i32* %22
%57 = icmp eq i32 %56, 2
br i1 %57, label %58, label %59
58: ; preds = %55
store i32 0, i32* %22
br label %59
59: ; preds = %58, %55
br label %60
60: ; preds = %59, %54
br label %93
61: ; preds = %34
%62 = load i32, i32* %22
%63 = icmp ne i32 %62, 0
br i1 %63, label %85, label %64
64: ; preds = %61
%65 = load i32, i32* %20
%66 = add nsw i32 %65, -1
store i32 %66, i32* %20
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %85
68: ; preds = %64
%69 = load i8*, i8** %25
%70 = icmp ne i8* %69, null
br i1 %70, label %71, label %83
71: ; preds = %68
%72 = load i8*, i8** %25
%73 = load i8**, i8*** %11
%74 = load i64*, i64** %12
%75 = load i64*, i64** %13
%76 = load i32, i32* %16
%77 = load i32*, i32** %17
%78 = load i8*, i8** %18
%79 = load i8*, i8** %19
%80 = call i32 @exec_comm(i8* %72, i8** %73, i64* %74, i64* %75, i32 %76, i32* %77, i8* %78, i8* %79)
store i32 %80, i32* %21
%81 = load i8*, i8** %25
%82 = call i32 @free(i8* %81)
br label %83
83: ; preds = %71, %68
%84 = load i32, i32* %21
store i32 %84, i32* %10
br label %118
85: ; preds = %64, %61
br label %93
86: ; preds = %34
%87 = load i32, i32* %22
%88 = icmp ne i32 %87, 0
br i1 %88, label %92, label %89
89: ; preds = %86
%90 = load i32, i32* %20
%91 = add nsw i32 %90, 1
store i32 %91, i32* %20
br label %92
92: ; preds = %89, %86
br label %93
93: ; preds = %92, %34, %85, %60, %50
%94 = load i8*, i8** %25
%95 = load i8*, i8** %14
%96 = load i64*, i64** %15
%97 = load i64, i64* %96
%98 = getelementptr inbounds i8, i8* %95, i64 %97
%99 = load i8, i8* %98
%100 = call i8* @w_addchar(i8* %94, i64* %23, i64* %24, i8 signext %99)
store i8* %100, i8** %25
%101 = load i8*, i8** %25
%102 = icmp eq i8* %101, null
br i1 %102, label %103, label %105
103: ; preds = %93
%104 = load i32, i32* @WRDE_NOSPACE
store i32 %104, i32* %10
br label %118
105: ; preds = %93
br label %106
106: ; preds = %105
%107 = load i64*, i64** %15
%108 = load i64, i64* %107
%109 = add i64 %108, 1
store i64 %109, i64* %107
br label %27
110: ; preds = %27
%111 = load i8*, i8** %25
%112 = icmp ne i8* %111, null
br i1 %112, label %113, label %116
113: ; preds = %110
%114 = load i8*, i8** %25
%115 = call i32 @free(i8* %114)
br label %116
116: ; preds = %113, %110
%117 = load i32, i32* @WRDE_SYNTAX
store i32 %117, i32* %10
br label %118
118: ; preds = %116, %103, %83
%119 = load i32, i32* %10
ret i32 %119
}

LLVM IR (-O2):
@WRDE_NOSPACE = global i32 0
@WRDE_SYNTAX = global i32 0
define i32 @parse_comm(i8** %0, i64* %1, i64* %2, i8* nocapture %3, i64* nocapture %4, i32 %5, i32* %6, i8* %7, i8* %8) {
%10 = alloca i64
%11 = alloca i64
%12 = bitcast i64* %10 to i8*
%13 = bitcast i64* %11 to i8*
%14 = call i8* @w_newword(i64* %10, i64* %11)
%15 = load i64, i64* %4
%16 = getelementptr inbounds i8, i8* %3, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %62, label %19
19: ; preds = %9, %56
%20 = phi i8 [ %60, %56 ], [ %17, %9 ]
%21 = phi i8* [ %52, %56 ], [ %14, %9 ]
%22 = phi i32 [ %51, %56 ], [ 0, %9 ]
%23 = phi i32 [ %50, %56 ], [ 1, %9 ]
%24 = sext i8 %20 to i32
switch i32 %24, label %49 [
i32 39, label %25
i32 34, label %30
i32 41, label %35
i32 40, label %45
]
25: ; preds = %19
%26 = icmp eq i32 %22, 0
br i1 %26, label %49, label %27
27: ; preds = %25
%28 = icmp eq i32 %22, 1
%29 = select i1 %28, i32 0, i32 %22
br label %49
30: ; preds = %19
%31 = icmp eq i32 %22, 0
br i1 %31, label %49, label %32
32: ; preds = %30
%33 = icmp eq i32 %22, 2
%34 = select i1 %33, i32 0, i32 %22
br label %49
35: ; preds = %19
%36 = icmp eq i32 %22, 0
br i1 %36, label %37, label %49
37: ; preds = %35
%38 = add nsw i32 %23, -1
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %49
40: ; preds = %37
%41 = icmp eq i8* %21, null
br i1 %41, label %69, label %42
42: ; preds = %40
%43 = call i32 @exec_comm(i8* %21, i8** %0, i64* %1, i64* %2, i32 %5, i32* %6, i8* %7, i8* %8)
%44 = call i32 @free(i8* %21)
br label %69
45: ; preds = %19
%46 = icmp eq i32 %22, 0
%47 = zext i1 %46 to i32
%48 = add nsw i32 %23, %47
br label %49
49: ; preds = %45, %30, %25, %35, %37, %32, %27, %19
%50 = phi i32 [ %23, %19 ], [ %23, %35 ], [ %38, %37 ], [ %23, %32 ], [ %23, %27 ], [ %23, %25 ], [ %23, %30 ], [ %48, %45 ]
%51 = phi i32 [ %22, %19 ], [ %22, %35 ], [ 0, %37 ], [ %34, %32 ], [ %29, %27 ], [ 1, %25 ], [ 2, %30 ], [ %22, %45 ]
%52 = call i8* @w_addchar(i8* %21, i64* %10, i64* %11, i8 signext %20)
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = load i32, i32* @WRDE_NOSPACE
br label %69
56: ; preds = %49
%57 = load i64, i64* %4
%58 = add i64 %57, 1
store i64 %58, i64* %4
%59 = getelementptr inbounds i8, i8* %3, i64 %58
%60 = load i8, i8* %59
%61 = icmp eq i8 %60, 0
br i1 %61, label %64, label %19
62: ; preds = %9
%63 = icmp eq i8* %14, null
br i1 %63, label %67, label %64
64: ; preds = %56, %62
%65 = phi i8* [ %14, %62 ], [ %52, %56 ]
%66 = call i32 @free(i8* %65)
br label %67
67: ; preds = %64, %62
%68 = load i32, i32* @WRDE_SYNTAX
br label %69
69: ; preds = %40, %42, %67, %54
%70 = phi i32 [ %55, %54 ], [ %68, %67 ], [ %43, %42 ], [ 0, %40 ]
ret i32 %70
}