#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 **ibufpp, const int 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    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x25(%rbp)
je     119f <extract_pattern+0x3f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11af <extract_pattern+0x4f>
jmp    1258 <extract_pattern+0xf8>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
jne    11fd <extract_pattern+0x9d>
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    11f8 <extract_pattern+0x98>
lea    0xe1a(%rip),%rdi
call   1060 <set_error_msg@plt>
movq   $0x0,-0x8(%rbp)
jmp    12f3 <extract_pattern+0x193>
jmp    1247 <extract_pattern+0xe7>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    1242 <extract_pattern+0xe2>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl 0x1(%rax),%eax
cmp    $0xa,%eax
jne    1242 <extract_pattern+0xe2>
lea    0xde9(%rip),%rdi
call   1060 <set_error_msg@plt>
movq   $0x0,-0x8(%rbp)
jmp    12f3 <extract_pattern+0x193>
jmp    1247 <extract_pattern+0xe7>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    117a <extract_pattern+0x1a>
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    0x2de2(%rip),%rdi
lea    0x2de3(%rip),%rsi
call   1080 <resize_buffer@plt>
cmp    $0x0,%eax
jne    1298 <extract_pattern+0x138>
movq   $0x0,-0x8(%rbp)
jmp    12f3 <extract_pattern+0x193>
mov    0x2db9(%rip),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x24(%rbp),%edx
call   1070 <memcpy@plt>
mov    0x2da3(%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     12e8 <extract_pattern+0x188>
mov    0x2d78(%rip),%rdi
mov    -0x24(%rbp),%esi
call   1050 <nul_to_newline@plt>
mov    0x2d69(%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    %rdi,%r14
mov    (%rdi),%rbx
movsbl (%rbx),%eax
cmp    $0xa,%eax
je     11d4 <extract_pattern+0x74>
mov    %esi,%ebp
cmp    %esi,%eax
je     11d4 <extract_pattern+0x74>
nopl   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
movsbl 0x1(%rbx),%eax
add    $0x1,%rbx
cmp    $0xa,%eax
je     11cf <extract_pattern+0x6f>
cmp    %ebp,%eax
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, i32 %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8** %0, i8*** %4
store i32 %1, i32* %5
%8 = load i8**, i8*** %4
%9 = load i8*, i8** %8
store i8* %9, i8** %6
br label %10
10: ; preds = %51, %2
%11 = load i8*, i8** %6
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = load i32, i32* %5
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %21
16: ; preds = %10
%17 = load i8*, i8** %6
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 10
br label %21
21: ; preds = %16, %10
%22 = phi i1 [ false, %10 ], [ %20, %16 ]
br i1 %22, label %23, label %54
23: ; preds = %21
%24 = load i8*, i8** %6
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 91
br i1 %27, label %28, label %37
28: ; preds = %23
%29 = load i8*, i8** %6
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %6
%31 = call i8* @parse_char_class(i8* %30)
store i8* %31, i8** %6
%32 = load i8*, i8** %6
%33 = icmp ne i8* %32, null
br i1 %33, label %36, label %34
34: ; preds = %28
%35 = 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 %87
36: ; preds = %28
br label %51
37: ; preds = %23
%38 = load i8*, i8** %6
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 92
br i1 %41, label %42, label %50
42: ; preds = %37
%43 = load i8*, i8** %6
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %6
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 10
br i1 %47, label %48, label %50
48: ; preds = %42
%49 = 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 %87
50: ; preds = %42, %37
br label %51
51: ; preds = %50, %36
%52 = load i8*, i8** %6
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %6
br label %10
54: ; preds = %21
%55 = load i8*, i8** %6
%56 = load i8**, i8*** %4
%57 = load i8*, i8** %56
%58 = ptrtoint i8* %55 to i64
%59 = ptrtoint i8* %57 to i64
%60 = sub i64 %58, %59
%61 = trunc i64 %60 to i32
store i32 %61, i32* %7
%62 = load i32, i32* %7
%63 = add nsw i32 %62, 1
%64 = call i32 @resize_buffer(i8** @extract_pattern.buf, i32* @extract_pattern.bufsz, i32 %63)
%65 = icmp ne i32 %64, 0
br i1 %65, label %67, label %66
66: ; preds = %54
store i8* null, i8** %3
br label %87
67: ; preds = %54
%68 = load i8*, i8** @extract_pattern.buf
%69 = load i8**, i8*** %4
%70 = load i8*, i8** %69
%71 = load i32, i32* %7
%72 = call i32 @memcpy(i8* %68, i8* %70, i32 %71)
%73 = load i8*, i8** @extract_pattern.buf
%74 = load i32, i32* %7
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
store i8 0, i8* %76
%77 = load i8*, i8** %6
%78 = load i8**, i8*** %4
store i8* %77, i8** %78
%79 = call i64 (...) @isbinary()
%80 = icmp ne i64 %79, 0
br i1 %80, label %81, label %85
81: ; preds = %67
%82 = load i8*, i8** @extract_pattern.buf
%83 = load i32, i32* %7
%84 = call i32 @nul_to_newline(i8* %82, i32 %83)
br label %85
85: ; preds = %81, %67
%86 = load i8*, i8** @extract_pattern.buf
store i8* %86, i8** %3
br label %87
87: ; preds = %85, %66, %48, %34
%88 = load i8*, i8** %3
ret i8* %88
}

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