#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__ isbinary();
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ nul_to_newline(char *, int);
char *parse_char_class(char const *);
int /*<<< orphan*/ resize_buffer(char **, int *, int);
int /*<<< orphan*/ set_error_msg(char *);
char *extract_pattern(const char **const ibufpp, const char delimiter) {
  static char *buf = 0;
  static int bufsz = 0;
  const char *nd = *ibufpp;
  int len;
  while (*nd != delimiter && *nd != '\n') {
    if (*nd == '[') {
      nd = parse_char_class(++nd);
      if (!nd) {
        set_error_msg("Unbalanced brackets ([])");
        return 0;
      }
    } else if (*nd == '\\' && *++nd == '\n') {
      set_error_msg("Trailing backslash (\\)");
      return 0;
    }
    ++nd;
  }
  len = nd - *ibufpp;
  if (!resize_buffer(&buf, &bufsz, len + 1))
    return 0;
  memcpy(buf, *ibufpp, len);
  buf[len] = 0;
  *ibufpp = nd;
  if (isbinary())
    nul_to_newline(buf, len);
  return buf;
}


x86 assembly (clang, -O0):
<extract_pattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
movsbl -0x11(%rbp),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x25(%rbp)
je     11a5 <extract_pattern+0x45>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11b5 <extract_pattern+0x55>
jmp    125e <extract_pattern+0xfe>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
jne    1203 <extract_pattern+0xa3>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x20(%rbp)
call   1040 <parse_char_class@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11fe <extract_pattern+0x9e>
lea    0xe14(%rip),%rdi
call   1060 <set_error_msg@plt>
movq   $0x0,-0x8(%rbp)
jmp    12f9 <extract_pattern+0x199>
jmp    124d <extract_pattern+0xed>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    1248 <extract_pattern+0xe8>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl 0x1(%rax),%eax
cmp    $0xa,%eax
jne    1248 <extract_pattern+0xe8>
lea    0xde3(%rip),%rdi
call   1060 <set_error_msg@plt>
movq   $0x0,-0x8(%rbp)
jmp    12f9 <extract_pattern+0x199>
jmp    124d <extract_pattern+0xed>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    117d <extract_pattern+0x1d>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edx
add    $0x1,%edx
lea    0x2ddc(%rip),%rdi
lea    0x2ddd(%rip),%rsi
call   1080 <resize_buffer@plt>
cmp    $0x0,%eax
jne    129e <extract_pattern+0x13e>
movq   $0x0,-0x8(%rbp)
jmp    12f9 <extract_pattern+0x199>
mov    0x2db3(%rip),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x24(%rbp),%edx
call   1070 <memcpy@plt>
mov    0x2d9d(%rip),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    $0x0,%al
call   1030 <isbinary@plt>
cmp    $0x0,%rax
je     12ee <extract_pattern+0x18e>
mov    0x2d72(%rip),%rdi
mov    -0x24(%rbp),%esi
call   1050 <nul_to_newline@plt>
mov    0x2d63(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_pattern>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    (%rdi),%rbx
mov    (%rbx),%al
cmp    %bpl,%al
je     11d4 <extract_pattern+0x74>
cmp    $0xa,%al
je     11d4 <extract_pattern+0x74>
nopw   0x0(%rax,%rax,1)
cmp    $0x5c,%al
je     11b0 <extract_pattern+0x50>
cmp    $0x5b,%al
jne    11be <extract_pattern+0x5e>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <parse_char_class@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11be <extract_pattern+0x5e>
jmp    123c <extract_pattern+0xdc>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpb   $0xa,0x1(%rbx)
je     1245 <extract_pattern+0xe5>
add    $0x1,%rbx
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
cmp    %bpl,%al
je     11cf <extract_pattern+0x6f>
cmp    $0xa,%al
jne    1180 <extract_pattern+0x20>
mov    (%r14),%rax
jmp    11d7 <extract_pattern+0x77>
mov    %rbx,%rax
mov    %rbx,%rbp
sub    %rax,%rbp
lea    0x1(%rbp),%edx
lea    0x2e71(%rip),%rdi
lea    0x2e72(%rip),%rsi
call   1080 <resize_buffer@plt>
test   %eax,%eax
je     1251 <extract_pattern+0xf1>
mov    0x2e5a(%rip),%rdi
mov    (%r14),%rsi
mov    %ebp,%edx
call   1070 <memcpy@plt>
mov    0x2e49(%rip),%rax
movslq %ebp,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    %rbx,(%r14)
xor    %eax,%eax
call   1030 <isbinary@plt>
test   %rax,%rax
je     1233 <extract_pattern+0xd3>
mov    0x2e2c(%rip),%rdi
mov    %ebp,%esi
call   1050 <nul_to_newline@plt>
mov    0x2e1e(%rip),%rax
jmp    1253 <extract_pattern+0xf3>
lea    0xdbd(%rip),%rdi
jmp    124c <extract_pattern+0xec>
lea    0xdcd(%rip),%rdi
call   1060 <set_error_msg@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@extract_pattern.buf = internal global i8* null
@extract_pattern.bufsz = internal global i32 0
@.str = [25 x i8] c"Unbalanced brackets ([])\00"
@.str.1 = [23 x i8] c"Trailing backslash (\\)\00"
define i8* @extract_pattern(i8** %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i32
store i8** %0, i8*** %4
store i8 %1, i8* %5
%8 = load i8**, i8*** %4
%9 = load i8*, i8** %8
store i8* %9, i8** %6
br label %10
10: ; preds = %52, %2
%11 = load i8*, i8** %6
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = load i8, i8* %5
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %13, %15
br i1 %16, label %17, label %22
17: ; preds = %10
%18 = load i8*, i8** %6
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 10
br label %22
22: ; preds = %17, %10
%23 = phi i1 [ false, %10 ], [ %21, %17 ]
br i1 %23, label %24, label %55
24: ; preds = %22
%25 = load i8*, i8** %6
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 91
br i1 %28, label %29, label %38
29: ; preds = %24
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %6
%32 = call i8* @parse_char_class(i8* %31)
store i8* %32, i8** %6
%33 = load i8*, i8** %6
%34 = icmp ne i8* %33, null
br i1 %34, label %37, label %35
35: ; preds = %29
%36 = call i32 @set_error_msg(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %3
br label %88
37: ; preds = %29
br label %52
38: ; preds = %24
%39 = load i8*, i8** %6
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 92
br i1 %42, label %43, label %51
43: ; preds = %38
%44 = load i8*, i8** %6
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %6
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 10
br i1 %48, label %49, label %51
49: ; preds = %43
%50 = call i32 @set_error_msg(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %3
br label %88
51: ; preds = %43, %38
br label %52
52: ; preds = %51, %37
%53 = load i8*, i8** %6
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %6
br label %10
55: ; preds = %22
%56 = load i8*, i8** %6
%57 = load i8**, i8*** %4
%58 = load i8*, i8** %57
%59 = ptrtoint i8* %56 to i64
%60 = ptrtoint i8* %58 to i64
%61 = sub i64 %59, %60
%62 = trunc i64 %61 to i32
store i32 %62, i32* %7
%63 = load i32, i32* %7
%64 = add nsw i32 %63, 1
%65 = call i32 @resize_buffer(i8** @extract_pattern.buf, i32* @extract_pattern.bufsz, i32 %64)
%66 = icmp ne i32 %65, 0
br i1 %66, label %68, label %67
67: ; preds = %55
store i8* null, i8** %3
br label %88
68: ; preds = %55
%69 = load i8*, i8** @extract_pattern.buf
%70 = load i8**, i8*** %4
%71 = load i8*, i8** %70
%72 = load i32, i32* %7
%73 = call i32 @memcpy(i8* %69, i8* %71, i32 %72)
%74 = load i8*, i8** @extract_pattern.buf
%75 = load i32, i32* %7
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %74, i64 %76
store i8 0, i8* %77
%78 = load i8*, i8** %6
%79 = load i8**, i8*** %4
store i8* %78, i8** %79
%80 = call i64 (...) @isbinary()
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %86
82: ; preds = %68
%83 = load i8*, i8** @extract_pattern.buf
%84 = load i32, i32* %7
%85 = call i32 @nul_to_newline(i8* %83, i32 %84)
br label %86
86: ; preds = %82, %68
%87 = load i8*, i8** @extract_pattern.buf
store i8* %87, i8** %3
br label %88
88: ; preds = %86, %67, %49, %35
%89 = load i8*, i8** %3
ret i8* %89
}

LLVM IR (-O2):
@extract_pattern.buf = internal global i8* null
@extract_pattern.bufsz = internal global i32 0
@.str = [25 x i8] c"Unbalanced brackets ([])\00"
@.str.1 = [23 x i8] c"Trailing backslash (\\)\00"
define i8* @extract_pattern(i8** nocapture %0, i8 signext %1) {
%3 = load i8*, i8** %0
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, %1
%6 = icmp eq i8 %4, 10
%7 = or i1 %5, %6
br i1 %7, label %32, label %8
8: ; preds = %2, %23
%9 = phi i8 [ %26, %23 ], [ %4, %2 ]
%10 = phi i8* [ %25, %23 ], [ %3, %2 ]
switch i8 %9, label %23 [
i8 91, label %11
i8 92, label %17
]
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %10, i64 1
%13 = tail call i8* @parse_char_class(i8* %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = tail call i32 @set_error_msg(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %57
17: ; preds = %8
%18 = getelementptr inbounds i8, i8* %10, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 10
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = tail call i32 @set_error_msg(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %57
23: ; preds = %8, %17, %11
%24 = phi i8* [ %13, %11 ], [ %18, %17 ], [ %10, %8 ]
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, %1
%28 = icmp eq i8 %26, 10
%29 = or i1 %27, %28
br i1 %29, label %30, label %8
30: ; preds = %23
%31 = load i8*, i8** %0
br label %32
32: ; preds = %30, %2
%33 = phi i8* [ %3, %2 ], [ %31, %30 ]
%34 = phi i8* [ %3, %2 ], [ %25, %30 ]
%35 = ptrtoint i8* %34 to i64
%36 = ptrtoint i8* %33 to i64
%37 = sub i64 %35, %36
%38 = trunc i64 %37 to i32
%39 = add nsw i32 %38, 1
%40 = tail call i32 @resize_buffer(i8** @extract_pattern.buf, i32* @extract_pattern.bufsz, i32 %39)
%41 = icmp eq i32 %40, 0
br i1 %41, label %57, label %42
42: ; preds = %32
%43 = load i8*, i8** @extract_pattern.buf
%44 = load i8*, i8** %0
%45 = tail call i32 @memcpy(i8* %43, i8* %44, i32 %38)
%46 = load i8*, i8** @extract_pattern.buf
%47 = shl i64 %37, 32
%48 = ashr exact i64 %47, 32
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 0, i8* %49
store i8* %34, i8** %0
%50 = tail call i64 (...) @isbinary()
%51 = icmp eq i64 %50, 0
br i1 %51, label %55, label %52
52: ; preds = %42
%53 = load i8*, i8** @extract_pattern.buf
%54 = tail call i32 @nul_to_newline(i8* %53, i32 %38)
br label %55
55: ; preds = %52, %42
%56 = load i8*, i8** @extract_pattern.buf
br label %57
57: ; preds = %32, %55, %21, %15
%58 = phi i8* [ null, %15 ], [ null, %21 ], [ %56, %55 ], [ null, %32 ]
ret i8* %58
}