#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 *CD_getenv(char *, int /*<<< orphan*/);
int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
void list_stack(void) {
  char *token;
  char *stack_list_ptr;
  char *stack_style_ptr;
  char *stack_size_ptr;
  char stack_style[16] = "NONDESTRUCTIVE";
  int stack_size = 1;
  int index = 1;
  stack_list_ptr = CD_getenv("STACK", 0);
  if ((stack_size_ptr = CD_getenv("STACK_SIZE", 0)) != NULL)
    stack_size = atoi(stack_size_ptr);
  if ((stack_style_ptr = CD_getenv("STACK_STYLE", 0)) != NULL)
    strcpy(stack_style, stack_style_ptr);
  printf("\n*** cd Extension's Stack ( User Stack Size: %d   Stack Style: %s ) "
         "***\n\n",
         stack_size, stack_style);
  if (stack_list_ptr == NULL)
    fprintf(stdout, "\tIs Empty\n");
  else
    for (token = strtok(stack_list_ptr, ";"); token && index <= stack_size;
         token = strtok(NULL, ";"), index++)
      fprintf(stdout, " %d.\t %s\n", index, token);
  printf("\n");
}


x86 assembly (clang, -O0):
<list_stack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0xe91(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe8e(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x34(%rbp)
movl   $0x1,-0x38(%rbp)
lea    0xe7d(%rip),%rdi
xor    %esi,%esi
call   1030 <CD_getenv@plt>
mov    %rax,-0x10(%rbp)
lea    0xe71(%rip),%rdi
xor    %esi,%esi
call   1030 <CD_getenv@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11c6 <list_stack+0x66>
mov    -0x20(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x34(%rbp)
lea    0xe54(%rip),%rdi
xor    %esi,%esi
call   1030 <CD_getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11ef <list_stack+0x8f>
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x34(%rbp),%esi
lea    -0x30(%rbp),%rdx
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
jne    122b <list_stack+0xcb>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    12b0 <list_stack+0x150>
mov    -0x10(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x8(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x39(%rbp)
je     125b <list_stack+0xfb>
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
setle  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    126b <list_stack+0x10b>
jmp    12ab <list_stack+0x14b>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%edx
mov    -0x8(%rbp),%rcx
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdee(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x8(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    123f <list_stack+0xdf>
jmp    12b0 <list_stack+0x150>
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_stack>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movaps 0xe7d(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xe82(%rip),%rdi
xor    %esi,%esi
call   1030 <CD_getenv@plt>
mov    %rax,%r14
lea    0xe77(%rip),%rdi
xor    %esi,%esi
call   1030 <CD_getenv@plt>
test   %rax,%rax
je     11b7 <list_stack+0x47>
mov    %rax,%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
jmp    11bc <list_stack+0x4c>
mov    $0x1,%ebp
lea    0xe5e(%rip),%rdi
xor    %esi,%esi
call   1030 <CD_getenv@plt>
test   %rax,%rax
je     11da <list_stack+0x6a>
mov    %rsp,%rdi
mov    %rax,%rsi
call   1050 <strcpy@plt>
lea    0xe4c(%rip),%rdi
mov    %rsp,%rdx
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r14,%r14
je     125d <list_stack+0xed>
lea    0xe89(%rip),%rsi
mov    %r14,%rdi
call   1080 <strtok@plt>
test   %rax,%rax
je     1274 <list_stack+0x104>
test   %ebp,%ebp
jle    1274 <list_stack+0x104>
mov    $0x1,%ebx
mov    0x2dca(%rip),%r12
lea    0xe67(%rip),%r14
lea    0xe5e(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12),%edi
mov    %r14,%rsi
mov    %ebx,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
je     1274 <list_stack+0x104>
lea    0x1(%rbx),%ecx
cmp    %ebp,%ebx
mov    %ecx,%ebx
jl     1230 <list_stack+0xc0>
jmp    1274 <list_stack+0x104>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.list_stack.stack_style = [16 x i8] c"NONDESTRUCTIVE\00\00"
@.str = [6 x i8] c"STACK\00"
@.str.1 = [11 x i8] c"STACK_SIZE\00"
@.str.2 = [12 x i8] c"STACK_STYLE\00"
@.str.3 = [74 x i8] c"\0A*** cd Extension's Stack ( User Stack Size: %d Stack Style: %s ) ***\0A\0A\00"
@stdout = global i32 0
@.str.4 = [11 x i8] c"\09Is Empty\0A\00"
@.str.5 = [2 x i8] c";\00"
@.str.6 = [10 x i8] c" %d.\09 %s\0A\00"
@.str.7 = [2 x i8] c"\0A\00"
define void @list_stack() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [16 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = bitcast [16 x i8]* %5 to i8*
store i32 1, i32* %6
store i32 1, i32* %7
%9 = call i8* @CD_getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 0)
store i8* %9, i8** %2
%10 = call i8* @CD_getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i8* %10, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = load i8*, i8** %4
%14 = call i32 @atoi(i8* %13)
store i32 %14, i32* %6
br label %15
15: ; preds = %12, %0
%16 = call i8* @CD_getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 0)
store i8* %16, i8** %3
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%20 = load i8*, i8** %3
%21 = call i32 @strcpy(i8* %19, i8* %20)
br label %22
22: ; preds = %18, %15
%23 = load i32, i32* %6
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.3, i64 0, i64 0), i32 %23, i8* %24)
%26 = load i8*, i8** %2
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i32, i32* @stdout
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %53
31: ; preds = %22
%32 = load i8*, i8** %2
%33 = call i8* @strtok(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %33, i8** %1
br label %34
34: ; preds = %48, %31
%35 = load i8*, i8** %1
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = load i32, i32* %7
%39 = load i32, i32* %6
%40 = icmp sle i32 %38, %39
br label %41
41: ; preds = %37, %34
%42 = phi i1 [ false, %34 ], [ %40, %37 ]
br i1 %42, label %43, label %52
43: ; preds = %41
%44 = load i32, i32* @stdout
%45 = load i32, i32* %7
%46 = load i8*, i8** %1
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %45, i8* %46)
br label %48
48: ; preds = %43
%49 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %49, i8** %1
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
br label %34
52: ; preds = %41
br label %53
53: ; preds = %52, %28
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@__const.list_stack.stack_style = [16 x i8] c"NONDESTRUCTIVE\00\00"
@.str = [6 x i8] c"STACK\00"
@.str.1 = [11 x i8] c"STACK_SIZE\00"
@.str.2 = [12 x i8] c"STACK_STYLE\00"
@.str.3 = [74 x i8] c"\0A*** cd Extension's Stack ( User Stack Size: %d Stack Style: %s ) ***\0A\0A\00"
@stdout = global i32 0
@.str.4 = [11 x i8] c"\09Is Empty\0A\00"
@.str.5 = [2 x i8] c";\00"
@.str.6 = [10 x i8] c" %d.\09 %s\0A\00"
define void @list_stack() {
%1 = alloca [16 x i8]
%2 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%3 = tail call i8* @CD_getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 0)
%4 = tail call i8* @CD_getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 0)
%5 = icmp eq i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = tail call i32 @atoi(i8* %4)
br label %8
8: ; preds = %6, %0
%9 = phi i32 [ %7, %6 ], [ 1, %0 ]
%10 = tail call i8* @CD_getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 0)
%11 = icmp eq i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = call i32 @strcpy(i8* %2, i8* %10)
br label %14
14: ; preds = %12, %8
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @.str.3, i64 0, i64 0), i32 %9, i8* %2)
%16 = icmp eq i8* %3, null
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @stdout
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %35
20: ; preds = %14
%21 = call i8* @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%22 = icmp ne i8* %21, null
%23 = icmp sgt i32 %9, 0
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %25, label %35
25: ; preds = %20, %25
%26 = phi i32 [ %31, %25 ], [ 1, %20 ]
%27 = phi i8* [ %30, %25 ], [ %21, %20 ]
%28 = load i32, i32* @stdout
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %26, i8* %27)
%30 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%31 = add nuw nsw i32 %26, 1
%32 = icmp ne i8* %30, null
%33 = icmp slt i32 %26, %9
%34 = select i1 %32, i1 %33, i1 false
br i1 %34, label %25, label %35
35: ; preds = %25, %20, %17
%36 = call i32 @putchar(i32 10)
ret void
}