#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*/ printf(char *, ...);
void print_optimal_parens(int *s, int i, int j) {
  if (i == j)
    printf("A%d", i);
  else {
    printf("(");
    print_optimal_parens(s, i, *(s + (i - 1) * 6 + j));
    print_optimal_parens(s, *(s + (i - 1) * 6 + j) + 1, j);
    printf(")");
  }
}


x86 assembly (clang, -O0):
<print_optimal_parens>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    1154 <print_optimal_parens+0x34>
mov    -0xc(%rbp),%esi
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c7 <print_optimal_parens+0xa7>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
imul   $0x6,%ecx,%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
call   1040 <print_optimal_parens@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
imul   $0x6,%ecx,%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <print_optimal_parens@plt>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_optimal_parens>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebx
cmp    %edx,%esi
jne    1156 <print_optimal_parens+0x26>
lea    0xebb(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
mov    %edx,%ebp
mov    %rdi,%r14
mov    $0x28,%edi
call   1030 <putchar@plt>
lea    (%rbx,%rbx,2),%eax
add    %eax,%eax
add    $0xfffffffa,%eax
cltq
lea    (%r14,%rax,4),%r15
movslq %ebp,%r12
mov    (%r15,%r12,4),%edx
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <print_optimal_parens@plt>
mov    (%r15,%r12,4),%esi
add    $0x1,%esi
mov    %r14,%rdi
mov    %ebp,%edx
call   1050 <print_optimal_parens@plt>
mov    $0x29,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"A%d\00"
@.str.1 = [2 x i8] c"(\00"
@.str.2 = [2 x i8] c")\00"
define void @print_optimal_parens(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %5
%8 = load i32, i32* %6
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i32, i32* %5
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %41
13: ; preds = %3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32*, i32** %4
%16 = load i32, i32* %5
%17 = load i32*, i32** %4
%18 = load i32, i32* %5
%19 = sub nsw i32 %18, 1
%20 = mul nsw i32 %19, 6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %17, i64 %21
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = load i32*, i32** %4
%28 = load i32*, i32** %4
%29 = load i32, i32* %5
%30 = sub nsw i32 %29, 1
%31 = mul nsw i32 %30, 6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %28, i64 %32
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = add nsw i32 %37, 1
%39 = load i32, i32* %6
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %13, %10
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"A%d\00"
define void @print_optimal_parens(i32* %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %1, %2
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %7
7: ; preds = %5, %8
ret void
8: ; preds = %3
%9 = tail call i32 @putchar(i32 40)
%10 = mul i32 %1, 6
%11 = add i32 %10, -6
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %0, i64 %12
%14 = sext i32 %2 to i64
%15 = getelementptr inbounds i32, i32* %13, i64 %14
%16 = load i32, i32* %15
tail call void @print_optimal_parens(i32* %0, i32 %1, i32 %16)
%17 = load i32, i32* %15
%18 = add nsw i32 %17, 1
tail call void @print_optimal_parens(i32* %0, i32 %18, i32 %2)
%19 = tail call i32 @putchar(i32 41)
br label %7
}