#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int read_nstr(char const **);
int /*<<< orphan*/ *stderr;
void print_stack_code(FILE *fp, const char **code_ptr) {
  const char *code = *code_ptr;
  switch (*++code) {
  case ' ':
    fprintf(fp,
            "  "
            "push(%d);\n",
            read_nstr(&code));
    break;
  case '\t':
    switch (*++code) {
    case ' ':
      fprintf(fp,
              "  "
              "dup_n(%d);\n",
              read_nstr(&code));
      break;
    case '\t':
      fputs("Undefined Stack manipulation command is detected: [S][TT]\n",
            stderr);
      break;
    case '\n':
      fprintf(fp,
              "  "
              "slide(%d);\n",
              read_nstr(&code));
      break;
    }
    break;
  case '\n':
    switch (*++code) {
    case ' ':
      fputs("  "
            "dup_n(0);\n",
            fp);
      break;
    case '\t':
      fputs("  "
            "swap();\n",
            fp);
      break;
    case '\n':
      fputs("  "
            "pop();\n",
            fp);
      break;
    }
    break;
  }
  *code_ptr = code;
}


x86 assembly (clang, -O0):
<print_stack_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl 0x1(%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x9,%eax
je     11b9 <print_stack_code+0x89>
jmp    116f <print_stack_code+0x3f>
mov    -0x1c(%rbp),%eax
sub    $0xa,%eax
je     126a <print_stack_code+0x13a>
jmp    1180 <print_stack_code+0x50>
mov    -0x1c(%rbp),%eax
sub    $0x20,%eax
jne    12ef <print_stack_code+0x1bf>
jmp    1191 <print_stack_code+0x61>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <read_nstr@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xe51(%rip),%rsi
call   1040 <fprintf@plt>
jmp    12ef <print_stack_code+0x1bf>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl 0x1(%rax),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x9,%eax
je     1227 <print_stack_code+0xf7>
jmp    11dd <print_stack_code+0xad>
mov    -0x2c(%rbp),%eax
sub    $0xa,%eax
je     1242 <print_stack_code+0x112>
jmp    11ee <print_stack_code+0xbe>
mov    -0x2c(%rbp),%eax
sub    $0x20,%eax
jne    1265 <print_stack_code+0x135>
jmp    11ff <print_stack_code+0xcf>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <read_nstr@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
lea    0xdf0(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1265 <print_stack_code+0x135>
mov    0x2db2(%rip),%rax
mov    (%rax),%rsi
lea    0xde3(%rip),%rdi
call   1030 <fputs@plt>
jmp    1265 <print_stack_code+0x135>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <read_nstr@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
lea    0xdf6(%rip),%rsi
call   1040 <fprintf@plt>
jmp    12ef <print_stack_code+0x1bf>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl 0x1(%rax),%eax
mov    %eax,-0x44(%rbp)
sub    $0x9,%eax
je     12c5 <print_stack_code+0x195>
jmp    128e <print_stack_code+0x15e>
mov    -0x44(%rbp),%eax
sub    $0xa,%eax
je     12da <print_stack_code+0x1aa>
jmp    129f <print_stack_code+0x16f>
mov    -0x44(%rbp),%eax
sub    $0x20,%eax
jne    12ea <print_stack_code+0x1ba>
jmp    12b0 <print_stack_code+0x180>
mov    -0x8(%rbp),%rsi
lea    0xda9(%rip),%rdi
call   1030 <fputs@plt>
jmp    12ea <print_stack_code+0x1ba>
mov    -0x8(%rbp),%rsi
lea    0xda1(%rip),%rdi
call   1030 <fputs@plt>
jmp    12ea <print_stack_code+0x1ba>
mov    -0x8(%rbp),%rsi
lea    0xd97(%rip),%rdi
call   1030 <fputs@plt>
jmp    12ef <print_stack_code+0x1bf>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_stack_code>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rsp)
movsbl 0x1(%rax),%ecx
cmp    $0x9,%ecx
je     1170 <print_stack_code+0x40>
cmp    $0xa,%ecx
je     11a0 <print_stack_code+0x70>
cmp    $0x20,%ecx
jne    1228 <print_stack_code+0xf8>
mov    %rsp,%rdi
call   1040 <read_nstr@plt>
lea    0xe95(%rip),%rsi
jmp    11f5 <print_stack_code+0xc5>
lea    0x2(%rax),%rcx
mov    %rcx,(%rsp)
movsbl 0x2(%rax),%eax
cmp    $0x9,%eax
je     11c9 <print_stack_code+0x99>
cmp    $0xa,%eax
je     11e6 <print_stack_code+0xb6>
cmp    $0x20,%eax
jne    1228 <print_stack_code+0xf8>
mov    %rsp,%rdi
call   1040 <read_nstr@plt>
lea    0xe6f(%rip),%rsi
jmp    11f5 <print_stack_code+0xc5>
lea    0x2(%rax),%rcx
mov    %rcx,(%rsp)
movsbl 0x2(%rax),%eax
cmp    $0x9,%eax
je     1201 <print_stack_code+0xd1>
cmp    $0xa,%eax
je     120f <print_stack_code+0xdf>
cmp    $0x20,%eax
jne    1228 <print_stack_code+0xf8>
lea    0xea2(%rip),%rdi
mov    $0xc,%esi
jmp    121b <print_stack_code+0xeb>
mov    0x2e10(%rip),%rax
mov    (%rax),%rcx
lea    0xe41(%rip),%rdi
mov    $0x3a,%esi
mov    $0x1,%edx
jmp    1223 <print_stack_code+0xf3>
mov    %rsp,%rdi
call   1040 <read_nstr@plt>
lea    0xe61(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%edx
call   1030 <fprintf@plt>
jmp    1228 <print_stack_code+0xf8>
lea    0xe69(%rip),%rdi
mov    $0xa,%esi
jmp    121b <print_stack_code+0xeb>
lea    0xe66(%rip),%rdi
mov    $0x9,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <fwrite@plt>
mov    (%rsp),%rax
mov    %rax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c" push(%d);\0A\00"
@.str.1 = [14 x i8] c" dup_n(%d);\0A\00"
@.str.2 = [59 x i8] c"Undefined Stack manipulation command is detected: [S][TT]\0A\00"
@stderr = global i32* null
@.str.3 = [14 x i8] c" slide(%d);\0A\00"
@.str.4 = [13 x i8] c" dup_n(0);\0A\00"
@.str.5 = [11 x i8] c" swap();\0A\00"
@.str.6 = [10 x i8] c" pop();\0A\00"
define void @print_stack_code(i32* %0, i8** %1) {
%3 = alloca i32*
%4 = alloca i8**
%5 = alloca i8*
store i32* %0, i32** %3
store i8** %1, i8*** %4
%6 = load i8**, i8*** %4
%7 = load i8*, i8** %6
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = getelementptr inbounds i8, i8* %8, i32 1
store i8* %9, i8** %5
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
switch i32 %11, label %48 [
i32 32, label %12
i32 9, label %16
i32 10, label %33
]
12: ; preds = %2
%13 = load i32*, i32** %3
%14 = call i32 @read_nstr(i8** %5)
%15 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %48
16: ; preds = %2
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %5
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
switch i32 %20, label %32 [
i32 32, label %21
i32 9, label %25
i32 10, label %28
]
21: ; preds = %16
%22 = load i32*, i32** %3
%23 = call i32 @read_nstr(i8** %5)
%24 = call i32 @fprintf(i32* %22, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %32
25: ; preds = %16
%26 = load i32*, i32** @stderr
%27 = call i32 @fputs(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), i32* %26)
br label %32
28: ; preds = %16
%29 = load i32*, i32** %3
%30 = call i32 @read_nstr(i8** %5)
%31 = call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %16, %28, %25, %21
br label %48
33: ; preds = %2
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %5
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
switch i32 %37, label %47 [
i32 32, label %38
i32 9, label %41
i32 10, label %44
]
38: ; preds = %33
%39 = load i32*, i32** %3
%40 = call i32 @fputs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32* %39)
br label %47
41: ; preds = %33
%42 = load i32*, i32** %3
%43 = call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32* %42)
br label %47
44: ; preds = %33
%45 = load i32*, i32** %3
%46 = call i32 @fputs(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32* %45)
br label %47
47: ; preds = %33, %44, %41, %38
br label %48
48: ; preds = %2, %47, %32, %12
%49 = load i8*, i8** %5
%50 = load i8**, i8*** %4
store i8* %49, i8** %50
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c" push(%d);\0A\00"
@.str.1 = [14 x i8] c" dup_n(%d);\0A\00"
@.str.2 = [59 x i8] c"Undefined Stack manipulation command is detected: [S][TT]\0A\00"
@stderr = global i32* null
@.str.3 = [14 x i8] c" slide(%d);\0A\00"
@.str.4 = [13 x i8] c" dup_n(0);\0A\00"
@.str.5 = [11 x i8] c" swap();\0A\00"
@.str.6 = [10 x i8] c" pop();\0A\00"
define void @print_stack_code(i32* nocapture %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = load i8*, i8** %1
%6 = getelementptr inbounds i8, i8* %5, i64 1
store i8* %6, i8** %3
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
switch i32 %8, label %35 [
i32 32, label %9
i32 9, label %12
i32 10, label %25
]
9: ; preds = %2
%10 = call i32 @read_nstr(i8** %3)
%11 = call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %35
12: ; preds = %2
%13 = getelementptr inbounds i8, i8* %5, i64 2
store i8* %13, i8** %3
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
switch i32 %15, label %35 [
i32 32, label %16
i32 9, label %19
i32 10, label %22
]
16: ; preds = %12
%17 = call i32 @read_nstr(i8** %3)
%18 = call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %35
19: ; preds = %12
%20 = load i32*, i32** @stderr
%21 = tail call i64 @fwrite(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), i64 58, i64 1, i32* %20)
br label %35
22: ; preds = %12
%23 = call i32 @read_nstr(i8** %3)
%24 = call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %23)
br label %35
25: ; preds = %2
%26 = getelementptr inbounds i8, i8* %5, i64 2
store i8* %26, i8** %3
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
switch i32 %28, label %35 [
i32 32, label %29
i32 9, label %31
i32 10, label %33
]
29: ; preds = %25
%30 = tail call i64 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i64 12, i64 1, i32* %0)
br label %35
31: ; preds = %25
%32 = tail call i64 @fwrite(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i64 10, i64 1, i32* %0)
br label %35
33: ; preds = %25
%34 = tail call i64 @fwrite(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i64 9, i64 1, i32* %0)
br label %35
35: ; preds = %29, %31, %33, %25, %16, %19, %22, %12, %2, %9
%36 = load i8*, i8** %3
store i8* %36, i8** %1
ret void
}