#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 *splits, int s_length, int i, int j) {
  if (i == j) {
    printf("A%i", i + 1);
  } else {
    printf("(");
    print_optimal_parens(splits, s_length, i, splits[i * s_length + j]);
    print_optimal_parens(splits, s_length, splits[i * s_length + j] + 1, j);
    printf(")");
  }
}


x86 assembly (clang, -O0):
<print_optimal_parens>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    115a <print_optimal_parens+0x3a>
mov    -0x10(%rbp),%esi
add    $0x1,%esi
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bf <print_optimal_parens+0x9f>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
imul   -0xc(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%ecx
call   1040 <print_optimal_parens@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
imul   -0xc(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    -0x14(%rbp),%ecx
call   1040 <print_optimal_parens@plt>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_optimal_parens>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
cmp    %ecx,%edx
jne    1159 <print_optimal_parens+0x29>
add    $0x1,%ebp
lea    0xeb8(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
mov    %ecx,%r15d
mov    %esi,%r14d
mov    %rdi,%rbx
mov    $0x28,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
imul   %r14d,%eax
add    %r15d,%eax
movslq %eax,%r12
mov    (%rbx,%r12,4),%ecx
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1050 <print_optimal_parens@plt>
mov    (%rbx,%r12,4),%edx
add    $0x1,%edx
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r15d,%ecx
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%i\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, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i32, i32* %7
%10 = load i32, i32* %8
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %16
12: ; preds = %4
%13 = load i32, i32* %7
%14 = add nsw i32 %13, 1
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %44
16: ; preds = %4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32*, i32** %5
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = load i32*, i32** %5
%22 = load i32, i32* %7
%23 = load i32, i32* %6
%24 = mul nsw i32 %22, %23
%25 = load i32, i32* %8
%26 = add nsw i32 %24, %25
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %21, i64 %27
%29 = load i32, i32* %28
%30 = load i32*, i32** %5
%31 = load i32, i32* %6
%32 = load i32*, i32** %5
%33 = load i32, i32* %7
%34 = load i32, i32* %6
%35 = mul nsw i32 %33, %34
%36 = load i32, i32* %8
%37 = add nsw i32 %35, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %32, i64 %38
%40 = load i32, i32* %39
%41 = add nsw i32 %40, 1
%42 = load i32, i32* %8
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %44
44: ; preds = %16, %12
ret void
}

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