#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 *, int, int, int, int volatile);
int /*<<< orphan*/ test_two_recursion_help(int, int /*<<< orphan*/,
                                           int volatile *);
void test_two_recursion(int size) {
  volatile int vla1[size];
  for (int i = 0; i < size; i++) {
    volatile int vla2[size];
    test_two_recursion_help(size, 0, vla2);
    if (i > 0)
      vla1[i] = vla1[i - 1] + vla2[size - 1];
    else
      vla1[i] = vla2[size - 1];
  }
  printf("test_two_recursion w/ size %d, should be\n  (%d - 1) * %d == %d\n",
         size, size, size, vla1[size - 1]);
}


x86 assembly (clang, -O0):
<test_two_recursion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11fe <test_two_recursion+0xde>
mov    -0x4(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x40(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1030 <test_two_recursion_help@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    11ce <test_two_recursion+0xae>
mov    -0x38(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
mov    (%rax,%rdx,4),%edx
mov    -0x4(%rbp),%esi
sub    $0x1,%esi
movslq %esi,%rsi
mov    (%rcx,%rsi,4),%ecx
add    %ecx,%edx
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11e9 <test_two_recursion+0xc9>
mov    -0x38(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    -0x4(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
mov    (%rcx,%rdx,4),%edx
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1159 <test_two_recursion+0x39>
mov    -0x38(%rbp),%rax
mov    -0x4(%rbp),%esi
mov    -0x4(%rbp),%edx
mov    -0x4(%rbp),%ecx
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
movslq %edi,%rdi
mov    (%rax,%rdi,4),%r8d
lea    0xde1(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_two_recursion>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r15d
mov    %edi,%ebx
mov    %rsp,%rdx
lea    0xf(,%rbx,4),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rdx
mov    %rdx,%rsp
lea    -0x1(%r15),%eax
test   %edi,%edi
jle    118f <test_two_recursion+0x6f>
mov    %rsp,%r13
mov    %eax,%r12d
mov    %rsp,%r14
mov    %rcx,-0x40(%rbp)
sub    %rcx,%r14
mov    %r14,%rsp
mov    %r15d,%edi
xor    %esi,%esi
mov    %rdx,-0x38(%rbp)
mov    %r14,%rdx
call   1030 <test_two_recursion_help@plt>
mov    -0x38(%rbp),%rdx
mov    (%r14,%r12,4),%eax
mov    %eax,(%rdx)
mov    %r13,%rsp
cmp    $0x1,%r15d
jne    1194 <test_two_recursion+0x74>
xor    %r12d,%r12d
jmp    11e4 <test_two_recursion+0xc4>
movslq %eax,%r12
jmp    11e4 <test_two_recursion+0xc4>
add    $0xffffffffffffffff,%rbx
xor    %r13d,%r13d
mov    %r15,-0x30(%rbp)
nop
mov    %rbx,%r14
mov    %rsp,%r15
mov    %rsp,%rbx
sub    -0x40(%rbp),%rbx
mov    %rbx,%rsp
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <test_two_recursion_help@plt>
mov    -0x38(%rbp),%rdx
mov    %r13d,%eax
mov    (%rdx,%rax,4),%eax
add    (%rbx,%r12,4),%eax
mov    %eax,0x4(%rdx,%r13,4)
mov    %r15,%rsp
mov    %r14,%rbx
add    $0x1,%r13
cmp    %r13,%r14
jne    11a0 <test_two_recursion+0x80>
mov    -0x30(%rbp),%r15
mov    (%rdx,%r12,4),%r8d
lea    0xe11(%rip),%rdi
mov    %r15d,%esi
mov    %r15d,%edx
mov    %r15d,%ecx
call   1040 <printf@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [64 x i8] c"test_two_recursion w/ size %d, should be\0A (%d - 1) * %d == %d\0A\00"
define void @test_two_recursion(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
store i32 %0, i32* %2
%8 = load i32, i32* %2
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %3
%11 = alloca i32, i64 %9
store i64 %9, i64* %4
store i32 0, i32* %5
br label %12
12: ; preds = %51, %1
%13 = load i32, i32* %5
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %54
16: ; preds = %12
%17 = load i32, i32* %2
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %6
%20 = alloca i32, i64 %18
store i64 %18, i64* %7
%21 = load i32, i32* %2
%22 = call i32 @test_two_recursion_help(i32 %21, i32 0, i32* %20)
%23 = load i32, i32* %5
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %40
25: ; preds = %16
%26 = load i32, i32* %5
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %11, i64 %28
%30 = load volatile i32, i32* %29
%31 = load i32, i32* %2
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %20, i64 %33
%35 = load volatile i32, i32* %34
%36 = add nsw i32 %30, %35
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %11, i64 %38
store volatile i32 %36, i32* %39
br label %49
40: ; preds = %16
%41 = load i32, i32* %2
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %20, i64 %43
%45 = load volatile i32, i32* %44
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %11, i64 %47
store volatile i32 %45, i32* %48
br label %49
49: ; preds = %40, %25
%50 = load i8*, i8** %6
br label %51
51: ; preds = %49
%52 = load i32, i32* %5
%53 = add nsw i32 %52, 1
store i32 %53, i32* %5
br label %12
54: ; preds = %12
%55 = load i32, i32* %2
%56 = load i32, i32* %2
%57 = load i32, i32* %2
%58 = load i32, i32* %2
%59 = sub nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32, i32* %11, i64 %60
%62 = load volatile i32, i32* %61
%63 = call i32 @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i32 %55, i32 %56, i32 %57, i32 %62)
%64 = load i8*, i8** %3
ret void
}

LLVM IR (-O2):
@.str = [64 x i8] c"test_two_recursion w/ size %d, should be\0A (%d - 1) * %d == %d\0A\00"
define void @test_two_recursion(i32 %0) {
%2 = zext i32 %0 to i64
%3 = alloca i32, i64 %2
%4 = icmp sgt i32 %0, 0
%5 = add nsw i32 %0, -1
br i1 %4, label %8, label %6
6: ; preds = %1
%7 = sext i32 %5 to i64
br label %16
8: ; preds = %1
%9 = zext i32 %5 to i64
%10 = call i8* @llvm.stacksave()
%11 = alloca i32, i64 %2
%12 = call i32 @test_two_recursion_help(i32 %0, i32 0, i32* %11)
%13 = getelementptr inbounds i32, i32* %11, i64 %9
%14 = load volatile i32, i32* %13
store volatile i32 %14, i32* %3
%15 = icmp eq i32 %0, 1
br i1 %15, label %16, label %21
16: ; preds = %21, %8, %6
%17 = phi i64 [ %7, %6 ], [ 0, %8 ], [ %9, %21 ]
%18 = getelementptr inbounds i32, i32* %3, i64 %17
%19 = load volatile i32, i32* %18
%20 = call i32 @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %0, i32 %0, i32 %19)
ret void
21: ; preds = %8, %21
%22 = phi i64 [ %34, %21 ], [ 1, %8 ]
%23 = call i8* @llvm.stacksave()
%24 = alloca i32, i64 %2
%25 = call i32 @test_two_recursion_help(i32 %0, i32 0, i32* %24)
%26 = add nuw i64 %22, 4294967295
%27 = and i64 %26, 4294967295
%28 = getelementptr inbounds i32, i32* %3, i64 %27
%29 = load volatile i32, i32* %28
%30 = getelementptr inbounds i32, i32* %24, i64 %9
%31 = load volatile i32, i32* %30
%32 = add nsw i32 %31, %29
%33 = getelementptr inbounds i32, i32* %3, i64 %22
store volatile i32 %32, i32* %33
%34 = add nuw nsw i64 %22, 1
%35 = icmp eq i64 %34, %2
br i1 %35, label %16, label %21
}