#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*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ free(short *);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char const *);
scalar_t__ vrna_alloc(int);
int /*<<< orphan*/ vrna_message_error(char *);
short *vrna_ptable(const char *structure) {
  short i, j, hx;
  short length;
  short *stack;
  short *table;
  length = (short)strlen(structure);
  stack = (short *)vrna_alloc(sizeof(short) * (length + 1));
  table = (short *)vrna_alloc(sizeof(short) * (length + 2));
  table[0] = length;
  for (hx = 0, i = 1; i <= length; i++) {
    switch (structure[i - 1]) {
    case '(':
      stack[hx++] = i;
      break;
    case ')':
      j = stack[--hx];
      if (hx < 0) {
        fprintf(stderr, "%s\n", structure);
        vrna_message_error("unbalanced brackets in make_pair_table");
      }
      table[i] = j;
      table[j] = i;
      break;
    default:
      table[i] = 0;
      break;
    }
  }
  if (hx != 0) {
    fprintf(stderr, "%s\n", structure);
    vrna_message_error("unbalanced brackets in make_pair_table");
  }
  free(stack);
  return (table);
}


x86 assembly (clang, -O0):
<vrna_ptable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %ax,-0x10(%rbp)
movswl -0x10(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x1,%rax
mov    %eax,%edi
call   1070 <vrna_alloc@plt>
mov    %rax,-0x18(%rbp)
movswl -0x10(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x1,%rax
mov    %eax,%edi
call   1070 <vrna_alloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%cx
mov    -0x20(%rbp),%rax
mov    %cx,(%rax)
movw   $0x0,-0xe(%rbp)
movw   $0x1,-0xa(%rbp)
movswl -0xa(%rbp),%eax
movswl -0x10(%rbp),%ecx
cmp    %ecx,%eax
jg     12b2 <vrna_ptable+0x162>
mov    -0x8(%rbp),%rax
movswl -0xa(%rbp),%ecx
add    $0xffffffff,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x24(%rbp)
sub    $0x28,%eax
je     11f4 <vrna_ptable+0xa4>
jmp    11e3 <vrna_ptable+0x93>
mov    -0x24(%rbp),%eax
sub    $0x29,%eax
je     1218 <vrna_ptable+0xc8>
jmp    128d <vrna_ptable+0x13d>
mov    -0xa(%rbp),%dx
mov    -0x18(%rbp),%rax
mov    -0xe(%rbp),%cx
mov    %cx,%si
add    $0x1,%si
mov    %si,-0xe(%rbp)
movswq %cx,%rcx
mov    %dx,(%rax,%rcx,2)
jmp    129c <vrna_ptable+0x14c>
mov    -0x18(%rbp),%rax
mov    -0xe(%rbp),%cx
add    $0xffff,%cx
mov    %cx,-0xe(%rbp)
movswq %cx,%rcx
mov    (%rax,%rcx,2),%ax
mov    %ax,-0xc(%rbp)
movswl -0xe(%rbp),%eax
cmp    $0x0,%eax
jge    1266 <vrna_ptable+0x116>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdab(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xda3(%rip),%rdi
call   1060 <vrna_message_error@plt>
mov    -0xc(%rbp),%dx
mov    -0x20(%rbp),%rax
movswq -0xa(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
mov    -0xa(%rbp),%dx
mov    -0x20(%rbp),%rax
movswq -0xc(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
jmp    129c <vrna_ptable+0x14c>
mov    -0x20(%rbp),%rax
movswq -0xa(%rbp),%rcx
movw   $0x0,(%rax,%rcx,2)
jmp    12a1 <vrna_ptable+0x151>
mov    -0xa(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0xa(%rbp)
jmp    11b0 <vrna_ptable+0x60>
movswl -0xe(%rbp),%eax
cmp    $0x0,%eax
je     12e4 <vrna_ptable+0x194>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd2d(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xd25(%rip),%rdi
call   1060 <vrna_message_error@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vrna_ptable>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %rax,%rbx
movswl %bx,%ebp
lea    0x2(%rbp,%rbp,1),%edi
call   1070 <vrna_alloc@plt>
mov    %rax,%r14
lea    0x4(%rbp,%rbp,1),%edi
call   1070 <vrna_alloc@plt>
mov    %r14,%rdi
mov    %bx,(%rax)
test   %bx,%bx
jle    127a <vrna_ptable+0x12a>
mov    $0x1,%bp
xor    %r13d,%r13d
mov    %rdi,0x10(%rsp)
mov    %rax,0x8(%rsp)
jmp    11c3 <vrna_ptable+0x73>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movw   $0x0,(%rax,%r14,2)
add    $0x1,%ebp
cmp    %bx,%bp
jg     1244 <vrna_ptable+0xf4>
movswq %bp,%r14
movsbl -0x1(%r14,%r12,1),%ecx
cmp    $0x29,%ecx
je     11f0 <vrna_ptable+0xa0>
cmp    $0x28,%ecx
jne    11b0 <vrna_ptable+0x60>
movswq %r13w,%rdx
lea    0x1(%r13),%ecx
mov    %bp,(%rdi,%rdx,2)
mov    %ecx,%r13d
jmp    11b7 <vrna_ptable+0x67>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%r13d
movswq %r13w,%rcx
movzwl (%rdi,%rcx,2),%r15d
test   %r13w,%r13w
jns    1231 <vrna_ptable+0xe1>
mov    0x2dd6(%rip),%rcx
mov    (%rcx),%edi
lea    0xded(%rip),%rsi
mov    %r12,%rdx
call   1050 <fprintf@plt>
lea    0xde2(%rip),%rdi
call   1060 <vrna_message_error@plt>
mov    0x8(%rsp),%rax
mov    0x10(%rsp),%rdi
movswq %r15w,%rcx
mov    %cx,(%rax,%r14,2)
mov    %r14w,(%rax,%rcx,2)
jmp    11b7 <vrna_ptable+0x67>
test   %r13w,%r13w
je     127a <vrna_ptable+0x12a>
mov    %rdi,%rbx
mov    0x2d8c(%rip),%rcx
mov    (%rcx),%edi
lea    0xda3(%rip),%rsi
mov    %rax,%rbp
mov    %r12,%rdx
call   1050 <fprintf@plt>
lea    0xd95(%rip),%rdi
call   1060 <vrna_message_error@plt>
mov    %rbp,%rax
mov    %rbx,%rdi
mov    %rax,%rbx
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [39 x i8] c"unbalanced brackets in make_pair_table\00"
define i16* @vrna_ptable(i8* %0) {
%2 = alloca i8*
%3 = alloca i16
%4 = alloca i16
%5 = alloca i16
%6 = alloca i16
%7 = alloca i16*
%8 = alloca i16*
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = call i64 @strlen(i8* %9)
%11 = trunc i64 %10 to i16
store i16 %11, i16* %6
%12 = load i16, i16* %6
%13 = sext i16 %12 to i32
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = mul i64 2, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @vrna_alloc(i32 %17)
%19 = inttoptr i64 %18 to i16*
store i16* %19, i16** %7
%20 = load i16, i16* %6
%21 = sext i16 %20 to i32
%22 = add nsw i32 %21, 2
%23 = sext i32 %22 to i64
%24 = mul i64 2, %23
%25 = trunc i64 %24 to i32
%26 = call i64 @vrna_alloc(i32 %25)
%27 = inttoptr i64 %26 to i16*
store i16* %27, i16** %8
%28 = load i16, i16* %6
%29 = load i16*, i16** %8
%30 = getelementptr inbounds i16, i16* %29, i64 0
store i16 %28, i16* %30
store i16 0, i16* %5
store i16 1, i16* %3
br label %31
31: ; preds = %85, %1
%32 = load i16, i16* %3
%33 = sext i16 %32 to i32
%34 = load i16, i16* %6
%35 = sext i16 %34 to i32
%36 = icmp sle i32 %33, %35
br i1 %36, label %37, label %88
37: ; preds = %31
%38 = load i8*, i8** %2
%39 = load i16, i16* %3
%40 = sext i16 %39 to i32
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %38, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
switch i32 %45, label %79 [
i32 40, label %46
i32 41, label %53
]
46: ; preds = %37
%47 = load i16, i16* %3
%48 = load i16*, i16** %7
%49 = load i16, i16* %5
%50 = add i16 %49, 1
store i16 %50, i16* %5
%51 = sext i16 %49 to i64
%52 = getelementptr inbounds i16, i16* %48, i64 %51
store i16 %47, i16* %52
br label %84
53: ; preds = %37
%54 = load i16*, i16** %7
%55 = load i16, i16* %5
%56 = add i16 %55, -1
store i16 %56, i16* %5
%57 = sext i16 %56 to i64
%58 = getelementptr inbounds i16, i16* %54, i64 %57
%59 = load i16, i16* %58
store i16 %59, i16* %4
%60 = load i16, i16* %5
%61 = sext i16 %60 to i32
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %68
63: ; preds = %53
%64 = load i32, i32* @stderr
%65 = load i8*, i8** %2
%66 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %65)
%67 = call i32 @vrna_message_error(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %68
68: ; preds = %63, %53
%69 = load i16, i16* %4
%70 = load i16*, i16** %8
%71 = load i16, i16* %3
%72 = sext i16 %71 to i64
%73 = getelementptr inbounds i16, i16* %70, i64 %72
store i16 %69, i16* %73
%74 = load i16, i16* %3
%75 = load i16*, i16** %8
%76 = load i16, i16* %4
%77 = sext i16 %76 to i64
%78 = getelementptr inbounds i16, i16* %75, i64 %77
store i16 %74, i16* %78
br label %84
79: ; preds = %37
%80 = load i16*, i16** %8
%81 = load i16, i16* %3
%82 = sext i16 %81 to i64
%83 = getelementptr inbounds i16, i16* %80, i64 %82
store i16 0, i16* %83
br label %84
84: ; preds = %79, %68, %46
br label %85
85: ; preds = %84
%86 = load i16, i16* %3
%87 = add i16 %86, 1
store i16 %87, i16* %3
br label %31
88: ; preds = %31
%89 = load i16, i16* %5
%90 = sext i16 %89 to i32
%91 = icmp ne i32 %90, 0
br i1 %91, label %92, label %97
92: ; preds = %88
%93 = load i32, i32* @stderr
%94 = load i8*, i8** %2
%95 = call i32 @fprintf(i32 %93, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %94)
%96 = call i32 @vrna_message_error(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %97
97: ; preds = %92, %88
%98 = load i16*, i16** %7
%99 = call i32 @free(i16* %98)
%100 = load i16*, i16** %8
ret i16* %100
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [39 x i8] c"unbalanced brackets in make_pair_table\00"
define i16* @vrna_ptable(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i16
%4 = sext i16 %3 to i32
%5 = shl nsw i32 %4, 1
%6 = add nsw i32 %5, 2
%7 = tail call i64 @vrna_alloc(i32 %6)
%8 = inttoptr i64 %7 to i16*
%9 = add nsw i32 %5, 4
%10 = tail call i64 @vrna_alloc(i32 %9)
%11 = inttoptr i64 %10 to i16*
store i16 %3, i16* %11
%12 = icmp slt i16 %3, 1
br i1 %12, label %51, label %13
13: ; preds = %1, %41
%14 = phi i16 [ %43, %41 ], [ 1, %1 ]
%15 = phi i16 [ %42, %41 ], [ 0, %1 ]
%16 = sext i16 %14 to i64
%17 = add nsw i64 %16, -1
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
switch i32 %20, label %39 [
i32 40, label %21
i32 41, label %25
]
21: ; preds = %13
%22 = add i16 %15, 1
%23 = sext i16 %15 to i64
%24 = getelementptr inbounds i16, i16* %8, i64 %23
store i16 %14, i16* %24
br label %41
25: ; preds = %13
%26 = add i16 %15, -1
%27 = sext i16 %26 to i64
%28 = getelementptr inbounds i16, i16* %8, i64 %27
%29 = load i16, i16* %28
%30 = icmp slt i16 %26, 0
br i1 %30, label %31, label %35
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%34 = tail call i32 @vrna_message_error(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %31, %25
%36 = getelementptr inbounds i16, i16* %11, i64 %16
store i16 %29, i16* %36
%37 = sext i16 %29 to i64
%38 = getelementptr inbounds i16, i16* %11, i64 %37
store i16 %14, i16* %38
br label %41
39: ; preds = %13
%40 = getelementptr inbounds i16, i16* %11, i64 %16
store i16 0, i16* %40
br label %41
41: ; preds = %21, %35, %39
%42 = phi i16 [ %15, %39 ], [ %26, %35 ], [ %22, %21 ]
%43 = add i16 %14, 1
%44 = icmp sgt i16 %43, %3
br i1 %44, label %45, label %13
45: ; preds = %41
%46 = icmp eq i16 %42, 0
br i1 %46, label %51, label %47
47: ; preds = %45
%48 = load i32, i32* @stderr
%49 = tail call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%50 = tail call i32 @vrna_message_error(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %51
51: ; preds = %1, %47, %45
%52 = tail call i32 @free(i16* %8)
ret i16* %11
}