#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 */
char *new_str(char *);
char *s_inc(char *, char *);
int /*<<< orphan*/ *tt_momenta(char *, int, int, long, int, int *);
char *l_getMomenta(int isOrig, int table, long top, int n, int *err) {
  char *ret = NULL;
  char buf[256];
  int saverr = *err;
  if (isOrig)
    isOrig = 2;
  else
    isOrig = 3;
  if (tt_momenta(buf, isOrig, table, top, n, err) != NULL) {
    ret = new_str("[");
    ret = s_inc(s_inc(ret, buf), "]");
  } else {
    *err = saverr;
    ret = new_str("");
  }
  if (tt_momenta(buf, isOrig - 2, table, top, n, err) != NULL)
    ret = s_inc(ret, buf);
  else
    *err = saverr;
  return ret;
}


x86 assembly (clang, -O0):
<l_getMomenta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x134(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1176 <l_getMomenta+0x46>
movl   $0x2,-0x4(%rbp)
jmp    117d <l_getMomenta+0x4d>
movl   $0x3,-0x4(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    -0x20(%rbp),%r9
call   1050 <tt_momenta@plt>
cmp    $0x0,%rax
je     11dd <l_getMomenta+0xad>
lea    0xe54(%rip),%rdi
call   1030 <new_str@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x130(%rbp),%rsi
call   1040 <s_inc@plt>
mov    %rax,%rdi
lea    0xe33(%rip),%rsi
call   1040 <s_inc@plt>
mov    %rax,-0x28(%rbp)
jmp    11f9 <l_getMomenta+0xc9>
mov    -0x134(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
lea    0xe11(%rip),%rdi
call   1030 <new_str@plt>
mov    %rax,-0x28(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x4(%rbp),%esi
sub    $0x2,%esi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    -0x20(%rbp),%r9
call   1050 <tt_momenta@plt>
cmp    $0x0,%rax
je     123d <l_getMomenta+0x10d>
mov    -0x28(%rbp),%rdi
lea    -0x130(%rbp),%rsi
call   1040 <s_inc@plt>
mov    %rax,-0x28(%rbp)
jmp    1249 <l_getMomenta+0x119>
mov    -0x134(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<l_getMomenta>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %r8,%r13
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%r12d
mov    (%r8),%ebx
xor    %ebp,%ebp
test   %edi,%edi
sete   %bpl
or     $0x2,%ebp
lea    0x10(%rsp),%rdi
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r15,%rcx
mov    %r14d,%r8d
mov    %r13,%r9
call   1050 <tt_momenta@plt>
test   %rax,%rax
mov    %ebx,0xc(%rsp)
je     11a6 <l_getMomenta+0x76>
lea    0xe7d(%rip),%rdi
call   1030 <new_str@plt>
lea    0x10(%rsp),%rsi
mov    %rax,%rdi
call   1040 <s_inc@plt>
lea    0xe66(%rip),%rsi
mov    %rax,%rdi
call   1040 <s_inc@plt>
jmp    11b6 <l_getMomenta+0x86>
mov    %ebx,0x0(%r13)
lea    0xe50(%rip),%rdi
call   1030 <new_str@plt>
mov    %rax,%rbx
add    $0xfffffffe,%ebp
lea    0x10(%rsp),%rdi
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r15,%rcx
mov    %r14d,%r8d
mov    %r13,%r9
call   1050 <tt_momenta@plt>
test   %rax,%rax
je     11eb <l_getMomenta+0xbb>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <s_inc@plt>
mov    %rax,%rbx
jmp    11f3 <l_getMomenta+0xc3>
mov    0xc(%rsp),%eax
mov    %eax,0x0(%r13)
mov    %rbx,%rax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"[\00"
@.str.1 = [2 x i8] c"]\00"
@.str.2 = [1 x i8] zeroinitializer
define i8* @l_getMomenta(i32 %0, i32 %1, i64 %2, i32 %3, i32* %4) {
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%8 = load i32, i32* %4
%9 = icmp eq i32 %0, 0
%10 = select i1 %9, i32 3, i32 2
%11 = call i32* @tt_momenta(i8* %7, i32 %10, i32 %1, i64 %2, i32 %3, i32* %4)
%12 = icmp eq i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %5
%14 = call i8* @new_str(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = call i8* @s_inc(i8* %14, i8* %7)
%16 = call i8* @s_inc(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %19
17: ; preds = %5
store i32 %8, i32* %4
%18 = call i8* @new_str(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %13
%20 = phi i8* [ %16, %13 ], [ %18, %17 ]
%21 = add nsw i32 %10, -2
%22 = call i32* @tt_momenta(i8* %7, i32 %21, i32 %1, i64 %2, i32 %3, i32* %4)
%23 = icmp eq i32* %22, null
br i1 %23, label %26, label %24
24: ; preds = %19
%25 = call i8* @s_inc(i8* %20, i8* %7)
br label %27
26: ; preds = %19
store i32 %8, i32* %4
br label %27
27: ; preds = %26, %24
%28 = phi i8* [ %25, %24 ], [ %20, %26 ]
ret i8* %28
}