#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*/ caml_startup(char **);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *);
char *solve_equation(char *);
int main(int argc, char **argv) {
  caml_startup(argv);
  char *eq = " a CH3(CH2)3COOH + b O2 -> c H2O + d CO2";
  char *eq2 = " a CH3(CH2)3COOH + b O2 -> c H2O + d CO";
  char *result = solve_equation(eq);
  char *result2 = solve_equation(eq2);
  printf("solution : %s\n", result);
  printf("solution : %s\n", result2);
  free(result2);
  result2 = solve_equation(eq);
  printf("solution : %s\n", result2);
  free(result);
  free(result2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <caml_startup@plt>
lea    0xe9a(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xeb8(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <solve_equation@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <solve_equation@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xeb7(%rip),%rdi
call   1060 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xea7(%rip),%rdi
call   1060 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <solve_equation@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe81(%rip),%rdi
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rdi
call   1050 <caml_startup@plt>
lea    0xea9(%rip),%r14
mov    %r14,%rdi
call   1040 <solve_equation@plt>
mov    %rax,%r15
lea    0xec0(%rip),%rdi
call   1040 <solve_equation@plt>
mov    %rax,%rbx
lea    0xed9(%rip),%r12
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1040 <solve_equation@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [41 x i8] c" a CH3(CH2)3COOH + b O2 -> c H2O + d CO2\00"
@.str.1 = [40 x i8] c" a CH3(CH2)3COOH + b O2 -> c H2O + d CO\00"
@.str.2 = [15 x i8] c"solution : %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = call i32 @caml_startup(i8** %10)
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8** %7
%12 = load i8*, i8** %6
%13 = call i8* @solve_equation(i8* %12)
store i8* %13, i8** %8
%14 = load i8*, i8** %7
%15 = call i8* @solve_equation(i8* %14)
store i8* %15, i8** %9
%16 = load i8*, i8** %8
%17 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %9
%19 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %9
%21 = call i32 @free(i8* %20)
%22 = load i8*, i8** %6
%23 = call i8* @solve_equation(i8* %22)
store i8* %23, i8** %9
%24 = load i8*, i8** %9
%25 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %8
%27 = call i32 @free(i8* %26)
%28 = load i8*, i8** %9
%29 = call i32 @free(i8* %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [41 x i8] c" a CH3(CH2)3COOH + b O2 -> c H2O + d CO2\00"
@.str.1 = [40 x i8] c" a CH3(CH2)3COOH + b O2 -> c H2O + d CO\00"
@.str.2 = [15 x i8] c"solution : %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @caml_startup(i8** %1)
%4 = tail call i8* @solve_equation(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%5 = tail call i8* @solve_equation(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%8 = tail call i32 @free(i8* %5)
%9 = tail call i8* @solve_equation(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = tail call i32 @free(i8* %4)
%12 = tail call i32 @free(i8* %9)
ret i32 0
}