#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*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *stderr;
void print_heap_code(FILE *fp, const char **code_ptr) {
  const char *code = *code_ptr;
  switch (*++code) {
  case ' ':
    fputs("  "
          "heap_store();\n",
          fp);
    break;
  case '\t':
    fputs("  "
          "heap_read();\n",
          fp);
    break;
  case '\n':
    fputs("Undefined heap access command is detected: [TT][N]\n", stderr);
    break;
  }
  *code_ptr = code;
}


x86 assembly (clang, -O0):
<print_heap_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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     1186 <print_heap_code+0x76>
jmp    114f <print_heap_code+0x3f>
mov    -0x1c(%rbp),%eax
sub    $0xa,%eax
je     119b <print_heap_code+0x8b>
jmp    1160 <print_heap_code+0x50>
mov    -0x1c(%rbp),%eax
sub    $0x20,%eax
jne    11b1 <print_heap_code+0xa1>
jmp    1171 <print_heap_code+0x61>
mov    -0x8(%rbp),%rsi
lea    0xe84(%rip),%rdi
call   1030 <fputs@plt>
jmp    11b1 <print_heap_code+0xa1>
mov    -0x8(%rbp),%rsi
lea    0xe80(%rip),%rdi
call   1030 <fputs@plt>
jmp    11b1 <print_heap_code+0xa1>
mov    0x2e3e(%rip),%rax
mov    (%rax),%rsi
lea    0xe75(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_heap_code>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rcx
mov    (%rsi),%rbx
movsbl 0x1(%rbx),%eax
add    $0x1,%rbx
cmp    $0x9,%eax
je     1142 <print_heap_code+0x32>
cmp    $0xa,%eax
je     1150 <print_heap_code+0x40>
cmp    $0x20,%eax
jne    1170 <print_heap_code+0x60>
lea    0xec5(%rip),%rdi
mov    $0x10,%esi
jmp    1166 <print_heap_code+0x56>
lea    0xec8(%rip),%rdi
mov    $0xf,%esi
jmp    1166 <print_heap_code+0x56>
mov    0x2e89(%rip),%rax
mov    (%rax),%rcx
lea    0xec0(%rip),%rdi
mov    $0x33,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
mov    %rbx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [17 x i8] c" heap_store();\0A\00"
@.str.1 = [16 x i8] c" heap_read();\0A\00"
@.str.2 = [52 x i8] c"Undefined heap access command is detected: [TT][N]\0A\00"
@stderr = global i32* null
define void @print_heap_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 %21 [
i32 32, label %12
i32 9, label %15
i32 10, label %18
]
12: ; preds = %2
%13 = load i32*, i32** %3
%14 = call i32 @fputs(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* %13)
br label %21
15: ; preds = %2
%16 = load i32*, i32** %3
%17 = call i32 @fputs(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32* %16)
br label %21
18: ; preds = %2
%19 = load i32*, i32** @stderr
%20 = call i32 @fputs(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32* %19)
br label %21
21: ; preds = %2, %18, %15, %12
%22 = load i8*, i8** %5
%23 = load i8**, i8*** %4
store i8* %22, i8** %23
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c" heap_store();\0A\00"
@.str.1 = [16 x i8] c" heap_read();\0A\00"
@.str.2 = [52 x i8] c"Undefined heap access command is detected: [TT][N]\0A\00"
@stderr = global i32* null
define void @print_heap_code(i32* nocapture %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = getelementptr inbounds i8, i8* %3, i64 1
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
switch i32 %6, label %14 [
i32 32, label %7
i32 9, label %9
i32 10, label %11
]
7: ; preds = %2
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 16, i64 1, i32* %0)
br label %14
9: ; preds = %2
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 15, i64 1, i32* %0)
br label %14
11: ; preds = %2
%12 = load i32*, i32** @stderr
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i64 51, i64 1, i32* %12)
br label %14
14: ; preds = %2, %11, %9, %7
store i8* %4, i8** %1
ret void
}