#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*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ testa_apagao(int, int *, int);
void subseqLex(int n) {
  int *s, k;
  s = (int *)malloc((n + 1) * sizeof(int));
  s[0] = 0;
  k = 0;
  while (1) {
    if (s[k] < n) {
      s[k + 1] = s[k] + 1;
      k += 1;
    } else {
      s[k - 1] += 1;
      k -= 1;
    }
    if (k == 0)
      break;
    testa_apagao(35, s, k);
  }
  system("pause");
  free(s);
}


x86 assembly (clang, -O0):
<subseqLex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x4(%rbp),%eax
jge    11b3 <subseqLex+0x73>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d2 <subseqLex+0x92>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11e1 <subseqLex+0xa1>
jmp    11f7 <subseqLex+0xb7>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x23,%edi
call   1050 <testa_apagao@plt>
jmp    1173 <subseqLex+0x33>
lea    0xe02(%rip),%rdi
call   1040 <system@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<subseqLex>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
lea    0x4(,%r14,4),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movl   $0x0,(%rax)
xor    %eax,%eax
xor    %ebp,%ebp
cmp    %r14d,%eax
jge    1190 <subseqLex+0x50>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%eax
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %eax,0x4(%rbx,%rcx,4)
test   %ebp,%ebp
jne    119f <subseqLex+0x5f>
jmp    11bb <subseqLex+0x7b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq %ebp,%rax
add    $0xffffffff,%ebp
addl   $0x1,-0x4(%rbx,%rax,4)
test   %ebp,%ebp
je     11bb <subseqLex+0x7b>
mov    $0x23,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <testa_apagao@plt>
movslq %ebp,%rax
mov    (%rbx,%rax,4),%eax
cmp    %r14d,%eax
jge    1190 <subseqLex+0x50>
jmp    1170 <subseqLex+0x30>
lea    0xe3e(%rip),%rdi
call   1040 <system@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <free@plt>

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

LLVM IR (-O2):
@.str = [6 x i8] c"pause\00"
define void @subseqLex(i32 %0) {
%2 = shl i32 %0, 2
%3 = add i32 %2, 4
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i32*
store i32 0, i32* %5
br label %6
6: ; preds = %24, %1
%7 = phi i32 [ 0, %1 ], [ %28, %24 ]
%8 = phi i32 [ 0, %1 ], [ %22, %24 ]
%9 = icmp slt i32 %7, %0
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = add nsw i32 %7, 1
%12 = add nsw i32 %8, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %5, i64 %13
store i32 %11, i32* %14
br label %21
15: ; preds = %6
%16 = add nsw i32 %8, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %5, i64 %17
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
store i32 %20, i32* %18
br label %21
21: ; preds = %15, %10
%22 = phi i32 [ %12, %10 ], [ %16, %15 ]
%23 = icmp eq i32 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %21
%25 = tail call i32 @testa_apagao(i32 35, i32* %5, i32 %22)
%26 = sext i32 %22 to i64
%27 = getelementptr inbounds i32, i32* %5, i64 %26
%28 = load i32, i32* %27
br label %6
29: ; preds = %21
%30 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%31 = tail call i32 @free(i32* %5)
ret void
}