// File: /workspace/github_cpp_makefile_star2_O2/yanlinlin82[P]icpp/icpp.cpp
// Function: call_ext(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int)
int call_ext(const string& name, int sp)
{
	log<3>("[DEBUG] external call: %s\n", name.c_str());
	if (name == "operator<<(ostream,int)") {
		int b = m[sp + 1];
		int a = m[sp + 2];
		log<3>("[DEBUG] args: %d, %d\n", a, b);
		string aa = get_data_symbol(a);
		if (aa == "cout") {
			cout << b;
		} else if (aa == "cerr") {
			cerr << b;
		} else {
			err("Unsupported operator<< for %d('%s')\n", m[a], aa.c_str());
			exit(1);
		}
		return a;
	} else if (name == "operator<<(ostream,const char*)") {
		int b = m[sp + 1];
		int a = m[sp + 2];
		log<3>("[DEBUG] args: %d, %d\n", a, b);
		string aa = get_data_symbol(a);
		const char* s = reinterpret_cast<const char*>(&m[b]);
		if (aa == "cout") {
			cout << s;
		} else if (aa == "cerr") {
			cerr << s;
		} else {
			err("Unsupported operator<< for %d('%s')\n", m[a], aa.c_str());
			exit(1);
		}
		return a;
	} else if (name == "operator<<(ostream,(*)(endl_t))") {
		int b = m[sp + 1];
		int a = m[sp + 2];
		log<3>("[DEBUG] args: %d, %d\n", a, b);
		string aa = get_data_symbol(a);
		if (aa == "cout") {
			cout << endl;
		} else if (aa == "cerr") {
			cerr << endl;
		} else {
			err("Unsupported operator<< for %d('%s')\n", m[a], aa.c_str());
			exit(1);
		}
		return a;
	} else if (name == "printf(const char*,...)") {
		int var_arg_count = m[sp + 1];
		int var_arg_start = sp + 1 + var_arg_count;
		const char* fmt = reinterpret_cast<const char*>(&m[m[var_arg_start + 1]]);
		int n = 0;
		for (int i = 0; *fmt; ++fmt) {
			if (*fmt == '%') {
				char c = *++fmt;
				if (c == 'd' || c == 'c') {
					if (i >= var_arg_count) { n += printf("<missing>"); }
					else { n += printf((c == 'd' ? "%d" : "%c"), m[var_arg_start - i]); }
					++i;
				} else if (c == 's' || c == 'p') {
					if (i >= var_arg_count) { n += printf("<missing>"); }
					else { n += printf((c == 's' ? "%s" : "%p"), reinterpret_cast<const char*>(&m[m[var_arg_start - i]])); }
					++i;
				} else {
					n += printf("%c", c);
				}
			} else {
				n += printf("%c", *fmt);
			}
		}
		return n;
	} else {
		err("Unsupported function '%s'\n", name.c_str());
		exit(1);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %ebx
movq %rdi, %r14
movq (%rdi), %rsi
leaq 0x8f56(%rip), %rdi      # 0x171ef
xorl %eax, %eax
callq 0xf138
leaq 0x8f63(%rip), %rsi      # 0x1720a
movq %r14, %rdi
callq 0xf4c8
testb %al, %al
je 0xe30e
movq 0x12f8e(%rip), %rax     # 0x21248
movslq %ebx, %rcx
movl 0x4(%rax,%rcx,4), %r14d
movl 0x8(%rax,%rcx,4), %ebx
leaq 0x8f55(%rip), %rdi      # 0x17222
movl %ebx, %esi
movl %r14d, %edx
xorl %eax, %eax
callq 0xf138
movslq %ebx, %r15
leaq -0x50(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0xe222
leaq 0x8bbc(%rip), %rsi      # 0x16eae
movq %r12, %rdi
callq 0xf4c8
testb %al, %al
je 0xe38b
movq 0x12cbf(%rip), %rdi     # 0x20fc8
jmp 0xe3aa
leaq 0x8f48(%rip), %rsi      # 0x1725d
movq %r14, %rdi
callq 0xf4c8
testb %al, %al
je 0xe3b7
movq 0x12f1c(%rip), %rax     # 0x21248
movslq %ebx, %rcx
movslq 0x4(%rax,%rcx,4), %r14
movl 0x8(%rax,%rcx,4), %ebx
leaq 0x8ee3(%rip), %rdi      # 0x17222
movl %ebx, %esi
movl %r14d, %edx
xorl %eax, %eax
callq 0xf138
movslq %ebx, %r15
leaq -0x50(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0xe222
shlq $0x2, %r14
addq 0x12ee0(%rip), %r14     # 0x21248
leaq 0x8b3f(%rip), %rsi      # 0x16eae
movq %r12, %rdi
callq 0xf4c8
testb %al, %al
je 0xe425
movq 0x12c42(%rip), %rdi     # 0x20fc8
jmp 0xe444
leaq 0x8b29(%rip), %rsi      # 0x16ebb
leaq -0x50(%rbp), %rdi
callq 0xf4c8
testb %al, %al
je 0xe5a1
movq 0x12c46(%rip), %rdi     # 0x20ff0
movl %r14d, %esi
callq 0x3300
jmp 0xe587
leaq 0x8ebf(%rip), %rsi      # 0x1727d
movq %r14, %rdi
callq 0xf4c8
testb %al, %al
je 0xe451
movq 0x12e73(%rip), %rax     # 0x21248
movslq %ebx, %rcx
movl 0x4(%rax,%rcx,4), %edx
movl 0x8(%rax,%rcx,4), %ebx
leaq 0x8e3b(%rip), %rdi      # 0x17222
movl %ebx, %esi
xorl %eax, %eax
callq 0xf138
movslq %ebx, %r14
leaq -0x50(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xe222
leaq 0x8aa5(%rip), %rsi      # 0x16eae
movq %r15, %rdi
callq 0xf4c8
testb %al, %al
je 0xe567
movq 0x12ba8(%rip), %rdi     # 0x20fc8
jmp 0xe582
leaq 0x8a8f(%rip), %rsi      # 0x16ebb
leaq -0x50(%rbp), %rdi
callq 0xf4c8
testb %al, %al
je 0xe5c0
movq 0x12bac(%rip), %rdi     # 0x20ff0
movq %r14, %rsi
callq 0x31c0
jmp 0xe587
leaq 0x8e45(%rip), %rsi      # 0x1729d
movq %r14, %rdi
callq 0xf4c8
testb %al, %al
je 0xe5df
movslq %ebx, %rax
movq 0x12dd6(%rip), %rcx     # 0x21248
movl 0x4(%rcx,%rax,4), %r12d
addl %r12d, %eax
incl %eax
movl %eax, -0x2c(%rbp)
cltq
movslq 0x4(%rcx,%rax,4), %rax
leaq (%rcx,%rax,4), %r15
leaq 0x7de8(%rip), %r14      # 0x16279
xorl %ebx, %ebx
xorl %r13d, %r13d
movzbl (%r15), %eax
cmpl $0x25, %eax
je 0xe4b9
testl %eax, %eax
je 0xe590
movsbl %al, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x3030
jmp 0xe555
movsbl 0x1(%r15), %esi
incq %r15
leal -0x63(%rsi), %eax
cmpb $0x1, %al
ja 0xe4fa
cmpl %r12d, %r13d
jge 0xe544
cmpb $0x64, %sil
movq %r14, %rdi
leaq 0x7d74(%rip), %rax      # 0x1624f
cmoveq %rax, %rdi
movl -0x2c(%rbp), %eax
subl %r13d, %eax
cltq
movq 0x12d5a(%rip), %rcx     # 0x21248
movl (%rcx,%rax,4), %esi
xorl %eax, %eax
callq 0x3030
jmp 0xe552
cmpb $0x73, %sil
je 0xe509
movzbl %sil, %eax
cmpl $0x70, %eax
jne 0xe55f
cmpl %r12d, %r13d
jge 0xe544
cmpb $0x73, %sil
leaq 0x8da6(%rip), %rdi      # 0x172bf
leaq 0x7ed9(%rip), %rax      # 0x163f9
cmoveq %rax, %rdi
movl -0x2c(%rbp), %eax
subl %r13d, %eax
cltq
movq 0x12d15(%rip), %rcx     # 0x21248
movslq (%rcx,%rax,4), %rax
leaq (%rcx,%rax,4), %rsi
xorl %eax, %eax
callq 0x3030
jmp 0xe552
leaq 0x8d6a(%rip), %rdi      # 0x172b5
xorl %eax, %eax
callq 0x3030
incl %r13d
addl %eax, %ebx
incq %r15
jmp 0xe496
movq %r14, %rdi
jmp 0xe4ad
leaq 0x894d(%rip), %rsi      # 0x16ebb
leaq -0x50(%rbp), %rdi
callq 0xf4c8
testb %al, %al
je 0xe5f2
movq 0x12a6e(%rip), %rdi     # 0x20ff0
callq 0x3110
leaq -0x50(%rbp), %rdi
callq 0x3368
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x12ca0(%rip), %rax     # 0x21248
movl (%rax,%r15,4), %esi
movq -0x50(%rbp), %rdx
leaq 0x8c81(%rip), %rdi      # 0x17238
xorl %eax, %eax
callq 0xf410
jmp 0xe60f
movq 0x12c81(%rip), %rax     # 0x21248
movl (%rax,%r15,4), %esi
movq -0x50(%rbp), %rdx
leaq 0x8c62(%rip), %rdi      # 0x17238
xorl %eax, %eax
callq 0xf410
jmp 0xe60f
movq (%r14), %rsi
leaq 0x8cd9(%rip), %rdi      # 0x172c2
xorl %eax, %eax
callq 0xf410
jmp 0xe60f
movq 0x12c4f(%rip), %rax     # 0x21248
movl (%rax,%r14,4), %esi
movq -0x50(%rbp), %rdx
leaq 0x8c30(%rip), %rdi      # 0x17238
xorl %eax, %eax
callq 0xf410
pushq $0x1
popq %rdi
callq 0x3220
jmp 0xe61b
jmp 0xe61b
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x3368
movq %rbx, %rdi
callq 0x3310