// File: 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
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3110
movq %rax, %rsi
leaq 0x2117a(%rip), %rdi     # 0x3812f
movb $0x0, %al
callq 0x19760
movq -0x10(%rbp), %rdi
leaq 0x21183(%rip), %rsi     # 0x3814a
callq 0x1a9c0
testb $0x1, %al
jne 0x16fd5
jmp 0x1711f
movl -0x14(%rbp), %eax
incl %eax
movslq %eax, %rsi
leaq 0x394bc(%rip), %rdi     # 0x504a0
movq %rdi, -0xd8(%rbp)
callq 0x19cf0
movq -0xd8(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x19cf0
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %esi
movl -0x18(%rbp), %edx
leaq 0x21146(%rip), %rdi     # 0x38162
xorl %eax, %eax
callq 0x19760
movslq -0x1c(%rbp), %rsi
leaq -0x40(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x16ef0
movq -0xd0(%rbp), %rdi
leaq 0x20da9(%rip), %rsi     # 0x37dee
callq 0x1a9c0
movb %al, -0xc2(%rbp)
jmp 0x17052
movb -0xc2(%rbp), %al
testb $0x1, %al
jne 0x1705e
jmp 0x1708e
movl -0x18(%rbp), %esi
movq 0x38f60(%rip), %rdi     # 0x4ffc8
callq 0x3450
jmp 0x1706f
jmp 0x1710b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x34d8
jmp 0x17735
leaq 0x20d66(%rip), %rsi     # 0x37dfb
leaq -0x40(%rbp), %rdi
callq 0x1a9c0
movb %al, -0xd9(%rbp)
jmp 0x170a6
movb -0xd9(%rbp), %al
testb $0x1, %al
jne 0x170b2
jmp 0x170c5
movl -0x18(%rbp), %esi
movq 0x38f34(%rip), %rdi     # 0x4fff0
callq 0x3450
jmp 0x170c3
jmp 0x17109
movslq -0x1c(%rbp), %rsi
leaq 0x393d0(%rip), %rdi     # 0x504a0
callq 0x19cf0
movl (%rax), %eax
movl %eax, -0xe0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3110
movl -0xe0(%rbp), %esi
movq %rax, %rdx
leaq 0x21082(%rip), %rdi     # 0x38178
xorl %eax, %eax
callq 0x1a780
jmp 0x170ff
movl $0x1, %edi
callq 0x32f0
jmp 0x1710b
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x34d8
jmp 0x17729
movq -0x10(%rbp), %rdi
leaq 0x21073(%rip), %rsi     # 0x3819d
callq 0x1a9c0
testb $0x1, %al
jne 0x17138
jmp 0x17298
movl -0x14(%rbp), %eax
incl %eax
movslq %eax, %rsi
leaq 0x39359(%rip), %rdi     # 0x504a0
movq %rdi, -0xf8(%rbp)
callq 0x19cf0
movq -0xf8(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x50(%rbp)
movl -0x14(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x19cf0
movl (%rax), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %esi
movl -0x50(%rbp), %edx
leaq 0x20fe3(%rip), %rdi     # 0x38162
xorl %eax, %eax
callq 0x19760
movslq -0x54(%rbp), %rsi
leaq -0x78(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x16ef0
movq -0xf8(%rbp), %rdi
movslq -0x50(%rbp), %rsi
callq 0x19cf0
movq -0xf0(%rbp), %rdi
movq %rax, -0x80(%rbp)
leaq 0x20c32(%rip), %rsi     # 0x37dee
callq 0x1a9c0
movb %al, -0xe1(%rbp)
jmp 0x171c9
movb -0xe1(%rbp), %al
testb $0x1, %al
jne 0x171d5
jmp 0x17206
movq -0x80(%rbp), %rsi
movq 0x38de8(%rip), %rdi     # 0x4ffc8
callq 0x3250
jmp 0x171e7
jmp 0x17284
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x34d8
jmp 0x17735
leaq 0x20bee(%rip), %rsi     # 0x37dfb
leaq -0x78(%rbp), %rdi
callq 0x1a9c0
movb %al, -0xf9(%rbp)
jmp 0x1721e
movb -0xf9(%rbp), %al
testb $0x1, %al
jne 0x1722a
jmp 0x1723e
movq -0x80(%rbp), %rsi
movq 0x38dbb(%rip), %rdi     # 0x4fff0
callq 0x3250
jmp 0x1723c
jmp 0x17282
movslq -0x54(%rbp), %rsi
leaq 0x39257(%rip), %rdi     # 0x504a0
callq 0x19cf0
movl (%rax), %eax
movl %eax, -0x100(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x3110
movl -0x100(%rbp), %esi
movq %rax, %rdx
leaq 0x20f09(%rip), %rdi     # 0x38178
xorl %eax, %eax
callq 0x1a780
jmp 0x17278
movl $0x1, %edi
callq 0x32f0
jmp 0x17284
movl -0x54(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x34d8
jmp 0x17729
movq -0x10(%rbp), %rdi
leaq 0x20f1a(%rip), %rsi     # 0x381bd
callq 0x1a9c0
testb $0x1, %al
jne 0x172b1
jmp 0x17427
movl -0x14(%rbp), %eax
incl %eax
movslq %eax, %rsi
leaq 0x391e0(%rip), %rdi     # 0x504a0
movq %rdi, -0x118(%rbp)
callq 0x19cf0
movq -0x118(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x84(%rbp)
movl -0x14(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x19cf0
movl (%rax), %eax
movl %eax, -0x88(%rbp)
movl -0x88(%rbp), %esi
movl -0x84(%rbp), %edx
leaq 0x20e5e(%rip), %rdi     # 0x38162
xorl %eax, %eax
callq 0x19760
movslq -0x88(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x16ef0
movq -0x110(%rbp), %rdi
leaq 0x20abb(%rip), %rsi     # 0x37dee
callq 0x1a9c0
movb %al, -0x101(%rbp)
jmp 0x17340
movb -0x101(%rbp), %al
testb $0x1, %al
jne 0x1734c
jmp 0x17383
movq 0x38c75(%rip), %rdi     # 0x4ffc8
movq 0x38c56(%rip), %rsi     # 0x4ffb0
callq 0x3290
jmp 0x17361
jmp 0x1740d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x34d8
jmp 0x17735
leaq 0x20a71(%rip), %rsi     # 0x37dfb
leaq -0xa8(%rbp), %rdi
callq 0x1a9c0
movb %al, -0x119(%rbp)
jmp 0x1739e
movb -0x119(%rbp), %al
testb $0x1, %al
jne 0x173aa
jmp 0x173c1
movq 0x38c3f(%rip), %rdi     # 0x4fff0
movq 0x38bf8(%rip), %rsi     # 0x4ffb0
callq 0x3290
jmp 0x173bf
jmp 0x1740b
movslq -0x88(%rbp), %rsi
leaq 0x390d1(%rip), %rdi     # 0x504a0
callq 0x19cf0
movl (%rax), %eax
movl %eax, -0x120(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x3110
movl -0x120(%rbp), %esi
movq %rax, %rdx
leaq 0x20d80(%rip), %rdi     # 0x38178
xorl %eax, %eax
callq 0x1a780
jmp 0x17401
movl $0x1, %edi
callq 0x32f0
jmp 0x1740d
movl -0x88(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x34d8
jmp 0x17729
movq -0x10(%rbp), %rdi
leaq 0x20dab(%rip), %rsi     # 0x381dd
callq 0x1a9c0
testb $0x1, %al
jne 0x17440
jmp 0x17705
movl -0x14(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
leaq 0x39050(%rip), %rdi     # 0x504a0
callq 0x19cf0
movl (%rax), %eax
movl %eax, -0xac(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
addl -0xac(%rbp), %eax
movl %eax, -0xb0(%rbp)
movl -0xb0(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
leaq 0x3901e(%rip), %rdi     # 0x504a0
callq 0x19cf0
movslq (%rax), %rsi
leaq 0x3900f(%rip), %rdi     # 0x504a0
callq 0x19cf0
movq %rax, -0xb8(%rbp)
movl $0x0, -0xbc(%rbp)
movl $0x0, -0xc0(%rbp)
movq -0xb8(%rbp), %rax
cmpb $0x0, (%rax)
je 0x176fa
movq -0xb8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x25, %eax
jne 0x176bd
movq -0xb8(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0xb8(%rbp)
movb 0x1(%rax), %al
movb %al, -0xc1(%rbp)
movsbl -0xc1(%rbp), %eax
cmpl $0x64, %eax
je 0x1750e
movsbl -0xc1(%rbp), %eax
cmpl $0x63, %eax
jne 0x175bd
movl -0xc0(%rbp), %eax
cmpl -0xac(%rbp), %eax
jl 0x17538
leaq 0x20cd2(%rip), %rdi     # 0x381f5
movb $0x0, %al
callq 0x3040
addl -0xbc(%rbp), %eax
movl %eax, -0xbc(%rbp)
jmp 0x175a9
movsbl -0xc1(%rbp), %eax
cmpl $0x64, %eax
jne 0x17554
leaq 0x1fc44(%rip), %rax     # 0x3718f
movq %rax, -0x128(%rbp)
jmp 0x17564
leaq 0x1fc5e(%rip), %rax     # 0x371b9
movq %rax, -0x128(%rbp)
jmp 0x17564
movq -0x128(%rbp), %rax
movq %rax, -0x130(%rbp)
movl -0xb0(%rbp), %eax
subl -0xc0(%rbp), %eax
movslq %eax, %rsi
leaq 0x38f18(%rip), %rdi     # 0x504a0
callq 0x19cf0
movq -0x130(%rbp), %rdi
movl (%rax), %esi
movb $0x0, %al
callq 0x3040
addl -0xbc(%rbp), %eax
movl %eax, -0xbc(%rbp)
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x176bb
movsbl -0xc1(%rbp), %eax
cmpl $0x73, %eax
je 0x175d9
movsbl -0xc1(%rbp), %eax
cmpl $0x70, %eax
jne 0x17698
movl -0xc0(%rbp), %eax
cmpl -0xac(%rbp), %eax
jl 0x17606
leaq 0x20c07(%rip), %rdi     # 0x381f5
movb $0x0, %al
callq 0x3040
addl -0xbc(%rbp), %eax
movl %eax, -0xbc(%rbp)
jmp 0x17687
movsbl -0xc1(%rbp), %eax
cmpl $0x73, %eax
jne 0x17622
leaq 0x1fd20(%rip), %rax     # 0x37339
movq %rax, -0x138(%rbp)
jmp 0x17632
leaq 0x20bd6(%rip), %rax     # 0x381ff
movq %rax, -0x138(%rbp)
jmp 0x17632
movq -0x138(%rbp), %rax
movq %rax, -0x140(%rbp)
movl -0xb0(%rbp), %eax
subl -0xc0(%rbp), %eax
movslq %eax, %rsi
leaq 0x38e4a(%rip), %rdi     # 0x504a0
callq 0x19cf0
movslq (%rax), %rsi
leaq 0x38e3b(%rip), %rdi     # 0x504a0
callq 0x19cf0
movq -0x140(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x3040
addl -0xbc(%rbp), %eax
movl %eax, -0xbc(%rbp)
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x176b9
movsbl -0xc1(%rbp), %esi
leaq 0x1fb13(%rip), %rdi     # 0x371b9
movb $0x0, %al
callq 0x3040
addl -0xbc(%rbp), %eax
movl %eax, -0xbc(%rbp)
jmp 0x176bb
jmp 0x176e1
movq -0xb8(%rbp), %rax
movsbl (%rax), %esi
leaq 0x1faeb(%rip), %rdi     # 0x371b9
movb $0x0, %al
callq 0x3040
addl -0xbc(%rbp), %eax
movl %eax, -0xbc(%rbp)
jmp 0x176e3
movq -0xb8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xb8(%rbp)
jmp 0x174b1
movl -0xbc(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x17729
movq -0x10(%rbp), %rdi
callq 0x3110
movq %rax, %rsi
leaq 0x20aea(%rip), %rdi     # 0x38202
movb $0x0, %al
callq 0x1a780
movl $0x1, %edi
callq 0x32f0
movl -0x4(%rbp), %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x3460
nop