#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(int *);
int /*<<< orphan*/ nrerror(char *);
scalar_t__ space(int);
int /*<<< orphan*/ stderr;
int strlen(char const *);
void make_ptable(const char *structure, int *table) {
  int i, j, hx;
  int *stack;
  hx = 0;
  stack = (int *)space(sizeof(int) * (strlen(structure) + 1));
  for (i = 0; i < strlen(structure); i++) {
    switch (structure[i]) {
    case '.':
      table[i] = -1;
      break;
    case '(':
      stack[hx++] = i;
      break;
    case ')':
      j = stack[--hx];
      if (hx < 0) {
        fprintf(stderr, "%s\n", structure);
        nrerror("unbalanced brackets in make_ptable");
      }
      table[i] = j;
      table[j] = i;
      break;
    }
  }
  if (hx != 0) {
    fprintf(stderr, "%s\n", structure);
    nrerror("unbalanced brackets in make_ptable");
  }
  free(stack);
}


x86 assembly (clang, -O0):
<make_ptable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <space@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    128b <make_ptable+0x13b>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x30(%rbp)
sub    $0x28,%eax
je     11fa <make_ptable+0xaa>
jmp    11c4 <make_ptable+0x74>
mov    -0x30(%rbp),%eax
sub    $0x29,%eax
je     1217 <make_ptable+0xc7>
jmp    11d5 <make_ptable+0x85>
mov    -0x30(%rbp),%eax
sub    $0x2e,%eax
jne    1278 <make_ptable+0x128>
jmp    11e6 <make_ptable+0x96>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
jmp    1278 <make_ptable+0x128>
mov    -0x14(%rbp),%edx
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1278 <make_ptable+0x128>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    125c <make_ptable+0x10c>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdb5(%rip),%rsi
call   1070 <fprintf@plt>
lea    0xdad(%rip),%rdi
call   1050 <nrerror@plt>
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    127d <make_ptable+0x12d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118b <make_ptable+0x3b>
cmpl   $0x0,-0x1c(%rbp)
je     12ba <make_ptable+0x16a>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd57(%rip),%rsi
call   1070 <fprintf@plt>
lea    0xd4f(%rip),%rdi
call   1050 <nrerror@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_ptable>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
call   1060 <strlen@plt>
lea    0x4(,%rax,4),%edi
call   1040 <space@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    123b <make_ptable+0xeb>
xor    %r12d,%r12d
xor    %r13d,%r13d
jmp    11ae <make_ptable+0x5e>
nopl   (%rax)
movslq %r13d,%rax
add    $0x1,%r13d
mov    %r12d,(%r14,%rax,4)
add    $0x1,%r12
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
cmp    %rax,%r12
jge    1212 <make_ptable+0xc2>
movsbl (%rbx,%r12,1),%eax
cmp    $0x28,%eax
je     1190 <make_ptable+0x40>
cmp    $0x29,%eax
je     11d0 <make_ptable+0x80>
cmp    $0x2e,%eax
jne    119b <make_ptable+0x4b>
movl   $0xffffffff,(%r15,%r12,4)
ff
jmp    119b <make_ptable+0x4b>
nopl   0x0(%rax)
movslq %r13d,%rax
mov    -0x4(%r14,%rax,4),%ebp
test   %r13d,%r13d
jg     1201 <make_ptable+0xb1>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
lea    0xe08(%rip),%rdi
call   1050 <nrerror@plt>
add    $0xffffffff,%r13d
movslq %ebp,%rax
mov    %eax,(%r15,%r12,4)
mov    %r12d,(%r15,%rax,4)
jmp    119b <make_ptable+0x4b>
test   %r13d,%r13d
je     123b <make_ptable+0xeb>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
lea    0xdce(%rip),%rdi
call   1050 <nrerror@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

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