#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 */
unsigned int __ecm_TMulGen_space(unsigned int, unsigned int, unsigned int);
unsigned int TUpTree_space(unsigned int k) {
  unsigned int m, l;
  unsigned int r1, r2;
  m = k / 2;
  l = k - m;
  if (k == 1)
    return 0;
  r1 = __ecm_TMulGen_space(l - 1, m - 1, k - 1) + l;
  if (m != l) {
    r2 = __ecm_TMulGen_space(m - 1, l - 1, k - 1) + k;
    r1 = (((r1) < (r2)) ? (r2) : (r1));
  }
  r2 = TUpTree_space(l);
  r1 = (((r1) < (r2)) ? (r2) : (r1));
  if (m != l) {
    r2 = TUpTree_space(m);
    r1 = (((r1) < (r2)) ? (r2) : (r1));
  }
  return r1;
}


x86 assembly (clang, -O0):
<TUpTree_space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1153 <TUpTree_space+0x33>
movl   $0x0,-0x4(%rbp)
jmp    122a <TUpTree_space+0x10a>
mov    -0x10(%rbp),%edi
sub    $0x1,%edi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
call   1030 <__ecm_TMulGen_space@plt>
add    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     11bc <TUpTree_space+0x9c>
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%esi
sub    $0x1,%esi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
call   1030 <__ecm_TMulGen_space@plt>
add    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    11b0 <TUpTree_space+0x90>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11b6 <TUpTree_space+0x96>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <TUpTree_space@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    11de <TUpTree_space+0xbe>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11e4 <TUpTree_space+0xc4>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     1224 <TUpTree_space+0x104>
mov    -0xc(%rbp),%edi
call   1040 <TUpTree_space@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    1218 <TUpTree_space+0xf8>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    121e <TUpTree_space+0xfe>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TUpTree_space>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebp,%ebp
cmp    $0x1,%edi
je     11a9 <TUpTree_space+0x89>
mov    %edi,%r15d
mov    %edi,%r14d
shr    %r14d
mov    %edi,%r12d
sub    %r14d,%r12d
lea    -0x1(%r12),%edi
lea    -0x1(%r14),%r13d
lea    -0x1(%r15),%ebx
mov    %edi,0x4(%rsp)
mov    %r13d,%esi
mov    %ebx,%edx
call   1030 <__ecm_TMulGen_space@plt>
mov    %eax,%ebp
add    %r12d,%ebp
cmp    %r12d,%r14d
jne    1175 <TUpTree_space+0x55>
mov    %r14d,%edi
call   1040 <TUpTree_space@plt>
cmp    %eax,%ebp
cmovb  %eax,%ebp
jmp    11a9 <TUpTree_space+0x89>
mov    %r13d,%edi
mov    0x4(%rsp),%esi
mov    %ebx,%edx
call   1030 <__ecm_TMulGen_space@plt>
mov    %eax,%ebx
add    %r15d,%ebx
cmp    %ebx,%ebp
cmovae %ebp,%ebx
mov    %r12d,%edi
call   1040 <TUpTree_space@plt>
cmp    %eax,%ebx
cmovb  %eax,%ebx
mov    %r14d,%edi
call   1040 <TUpTree_space@plt>
cmp    %eax,%ebx
cmovb  %eax,%ebx
mov    %ebx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @TUpTree_space(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
%8 = load i32, i32* %3
%9 = udiv i32 %8, 2
store i32 %9, i32* %4
%10 = load i32, i32* %3
%11 = load i32, i32* %4
%12 = sub i32 %10, %11
store i32 %12, i32* %5
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %1
store i32 0, i32* %2
br label %77
16: ; preds = %1
%17 = load i32, i32* %5
%18 = sub i32 %17, 1
%19 = load i32, i32* %4
%20 = sub i32 %19, 1
%21 = load i32, i32* %3
%22 = sub i32 %21, 1
%23 = call i32 @__ecm_TMulGen_space(i32 %18, i32 %20, i32 %22)
%24 = load i32, i32* %5
%25 = add i32 %23, %24
store i32 %25, i32* %6
%26 = load i32, i32* %4
%27 = load i32, i32* %5
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %48
29: ; preds = %16
%30 = load i32, i32* %4
%31 = sub i32 %30, 1
%32 = load i32, i32* %5
%33 = sub i32 %32, 1
%34 = load i32, i32* %3
%35 = sub i32 %34, 1
%36 = call i32 @__ecm_TMulGen_space(i32 %31, i32 %33, i32 %35)
%37 = load i32, i32* %3
%38 = add i32 %36, %37
store i32 %38, i32* %7
%39 = load i32, i32* %6
%40 = load i32, i32* %7
%41 = icmp ult i32 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %29
%43 = load i32, i32* %7
br label %46
44: ; preds = %29
%45 = load i32, i32* %6
br label %46
46: ; preds = %44, %42
%47 = phi i32 [ %43, %42 ], [ %45, %44 ]
store i32 %47, i32* %6
br label %48
48: ; preds = %46, %16
%49 = load i32, i32* %5
%50 = call i32 @TUpTree_space(i32 %49)
store i32 %50, i32* %7
%51 = load i32, i32* %6
%52 = load i32, i32* %7
%53 = icmp ult i32 %51, %52
br i1 %53, label %54, label %56
54: ; preds = %48
%55 = load i32, i32* %7
br label %58
56: ; preds = %48
%57 = load i32, i32* %6
br label %58
58: ; preds = %56, %54
%59 = phi i32 [ %55, %54 ], [ %57, %56 ]
store i32 %59, i32* %6
%60 = load i32, i32* %4
%61 = load i32, i32* %5
%62 = icmp ne i32 %60, %61
br i1 %62, label %63, label %75
63: ; preds = %58
%64 = load i32, i32* %4
%65 = call i32 @TUpTree_space(i32 %64)
store i32 %65, i32* %7
%66 = load i32, i32* %6
%67 = load i32, i32* %7
%68 = icmp ult i32 %66, %67
br i1 %68, label %69, label %71
69: ; preds = %63
%70 = load i32, i32* %7
br label %73
71: ; preds = %63
%72 = load i32, i32* %6
br label %73
73: ; preds = %71, %69
%74 = phi i32 [ %70, %69 ], [ %72, %71 ]
store i32 %74, i32* %6
br label %75
75: ; preds = %73, %58
%76 = load i32, i32* %6
store i32 %76, i32* %2
br label %77
77: ; preds = %75, %15
%78 = load i32, i32* %2
ret i32 %78
}

LLVM IR (-O2):
define i32 @TUpTree_space(i32 %0) {
%2 = lshr i32 %0, 1
%3 = sub i32 %0, %2
%4 = icmp eq i32 %0, 1
br i1 %4, label %12, label %5
5: ; preds = %1
%6 = add i32 %3, -1
%7 = add nsw i32 %2, -1
%8 = add i32 %0, -1
%9 = tail call i32 @__ecm_TMulGen_space(i32 %6, i32 %7, i32 %8)
%10 = add i32 %9, %3
%11 = icmp eq i32 %2, %3
br i1 %11, label %14, label %18
12: ; preds = %1, %18, %14
%13 = phi i32 [ %17, %14 ], [ %28, %18 ], [ 0, %1 ]
ret i32 %13
14: ; preds = %5
%15 = tail call i32 @TUpTree_space(i32 %2)
%16 = icmp ult i32 %10, %15
%17 = select i1 %16, i32 %15, i32 %10
br label %12
18: ; preds = %5
%19 = tail call i32 @__ecm_TMulGen_space(i32 %7, i32 %6, i32 %8)
%20 = add i32 %19, %0
%21 = icmp ult i32 %10, %20
%22 = select i1 %21, i32 %20, i32 %10
%23 = tail call i32 @TUpTree_space(i32 %3)
%24 = icmp ult i32 %22, %23
%25 = select i1 %24, i32 %23, i32 %22
%26 = tail call i32 @TUpTree_space(i32 %2)
%27 = icmp ult i32 %25, %26
%28 = select i1 %27, i32 %26, i32 %25
br label %12
}