#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__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
char *Mult(int **s, int i, int j) {
  if (i < j) {
    char *retVal = (char *)malloc(10);
    char *a = Mult(s, i, s[i][j]);
    char *b = Mult(s, s[i][j] + 1, j);
    sprintf(retVal, "(%s*%s)\0", a, b);
    return retVal;
  } else {
    char *retVal = (char *)malloc(3);
    sprintf(retVal, "A%d\0", i);
    return retVal;
  }
}


x86 assembly (clang, -O0):
<Mult>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11cc <Mult+0x9c>
mov    $0xa,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
call   1040 <Mult@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
add    $0x1,%esi
mov    -0x18(%rbp),%edx
call   1040 <Mult@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f7 <Mult+0xc7>
mov    $0x3,%edi
call   1030 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe21(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Mult>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
cmp    %edx,%esi
jge    119e <Mult+0x6e>
mov    %edx,%r15d
mov    %rdi,%rbx
mov    $0xa,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
movslq %ebp,%r12
mov    (%rbx,%r12,8),%rax
movslq %r15d,%r13
mov    (%rax,%r13,4),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <Mult@plt>
mov    %rax,%rbp
mov    (%rbx,%r12,8),%rax
mov    (%rax,%r13,4),%esi
add    $0x1,%esi
mov    %rbx,%rdi
mov    %r15d,%edx
call   1040 <Mult@plt>
lea    0xe74(%rip),%rsi
mov    %r14,%rdi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    11be <Mult+0x8e>
mov    $0x3,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
lea    0xe57(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"(%s*%s)\00\00"
@.str.1 = [5 x i8] c"A%d\00\00"
define i8* @Mult(i32** %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i32** %0, i32*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%12 = load i32, i32* %6
%13 = load i32, i32* %7
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %48
15: ; preds = %3
%16 = call i64 @malloc(i32 10)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %8
%18 = load i32**, i32*** %5
%19 = load i32, i32* %6
%20 = load i32**, i32*** %5
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32*, i32** %20, i64 %22
%24 = load i32*, i32** %23
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = call i8* @Mult(i32** %18, i32 %19, i32 %28)
store i8* %29, i8** %9
%30 = load i32**, i32*** %5
%31 = load i32**, i32*** %5
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32*, i32** %31, i64 %33
%35 = load i32*, i32** %34
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = load i32, i32* %38
%40 = add nsw i32 %39, 1
%41 = load i32, i32* %7
%42 = call i8* @Mult(i32** %30, i32 %40, i32 %41)
store i8* %42, i8** %10
%43 = load i8*, i8** %8
%44 = load i8*, i8** %9
%45 = load i8*, i8** %10
%46 = call i32 (i8*, i8*, ...) @sprintf(i8* %43, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %44, i8* %45)
%47 = load i8*, i8** %8
store i8* %47, i8** %4
br label %55
48: ; preds = %3
%49 = call i64 @malloc(i32 3)
%50 = inttoptr i64 %49 to i8*
store i8* %50, i8** %11
%51 = load i8*, i8** %11
%52 = load i32, i32* %6
%53 = call i32 (i8*, i8*, ...) @sprintf(i8* %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %52)
%54 = load i8*, i8** %11
store i8* %54, i8** %4
br label %55
55: ; preds = %48, %15
%56 = load i8*, i8** %4
ret i8* %56
}

LLVM IR (-O2):
@.str = [9 x i8] c"(%s*%s)\00\00"
@.str.1 = [5 x i8] c"A%d\00\00"
define i8* @Mult(i32** %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, %2
br i1 %4, label %7, label %23
5: ; preds = %23, %7
%6 = phi i8* [ %9, %7 ], [ %25, %23 ]
ret i8* %6
7: ; preds = %3
%8 = tail call i64 @malloc(i32 10)
%9 = inttoptr i64 %8 to i8*
%10 = sext i32 %1 to i64
%11 = getelementptr inbounds i32*, i32** %0, i64 %10
%12 = load i32*, i32** %11
%13 = sext i32 %2 to i64
%14 = getelementptr inbounds i32, i32* %12, i64 %13
%15 = load i32, i32* %14
%16 = tail call i8* @Mult(i32** %0, i32 %1, i32 %15)
%17 = load i32*, i32** %11
%18 = getelementptr inbounds i32, i32* %17, i64 %13
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
%21 = tail call i8* @Mult(i32** %0, i32 %20, i32 %2)
%22 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %21)
br label %5
23: ; preds = %3
%24 = tail call i64 @malloc(i32 3)
%25 = inttoptr i64 %24 to i8*
%26 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %25, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %1)
br label %5
}