// File: dacunni[P]stlloader/./stlloader.h
// Function: stlloader::write_stream(std::ostream&, stlloader::Mesh const&, stlloader::Format)
void write_stream(std::ostream & os, const Mesh & mesh, Format format)
{
    switch(format) {
        case Format::ascii:
            {
                std::string solid_name = mesh.name;
                if(solid_name.size() == 0) solid_name = mesh.header;
                if(solid_name.size() == 0) solid_name = "stlloader";
                os << "solid " << solid_name << '\n';
                for(auto & facet : mesh.facets) {
                    os << "facet " << "normal " << facet.normal << '\n';
                    os << "outer loop\n";
                    for(int vi = 0; vi < 3; ++vi) {
                        os << "vertex " << facet.vertices[vi] << '\n';
                    }
                    os << "endloop\n";
                    os << "endfacet\n";
                }
                os << "endsolid " << solid_name << '\n';
            }
            break;
        case Format::binary:
            {
                std::string padded_header = mesh.header;
                if(padded_header.size() == 0) padded_header = mesh.name;
                if(padded_header.size() == 0) padded_header = "stlloader";
                padded_header.resize(STL_BINARY_HDR_SIZE, '\0');
                os << padded_header;
                write_binary_value<uint32_t>(os, mesh.facets.size());
                for(auto & facet : mesh.facets) {
                    write_binary_value(os, facet.normal);
                    for(int vi = 0; vi < 3; ++vi) {
                        write_binary_value(os, facet.vertices[vi]);
                    }
                    write_binary_value(os, uint16_t(0));
                }
            }
            break;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0xc4(%rbp)
testl %eax, %eax
je 0x49b9
jmp 0x49a5
movl -0xc4(%rbp), %eax
subl $0x1, %eax
je 0x4c1e
jmp 0x4def
movq -0x10(%rbp), %rsi
addq $0x18, %rsi
leaq -0x38(%rbp), %rdi
callq 0x3120
leaq -0x38(%rbp), %rdi
callq 0x31d0
cmpq $0x0, %rax
jne 0x4a08
movq -0x10(%rbp), %rsi
addq $0x38, %rsi
leaq -0x38(%rbp), %rdi
callq 0x3030
jmp 0x49ec
jmp 0x4a08
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3190
jmp 0x4df8
leaq -0x38(%rbp), %rdi
callq 0x31d0
cmpq $0x0, %rax
jne 0x4a2b
leaq 0x265d(%rip), %rsi      # 0x707b
leaq -0x38(%rbp), %rdi
callq 0x3380
jmp 0x4a29
jmp 0x4a2b
movq -0x8(%rbp), %rdi
leaq 0x2688(%rip), %rsi      # 0x70be
callq 0x3270
movq %rax, -0xd0(%rbp)
jmp 0x4a44
movq -0xd0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3260
movq %rax, -0xd8(%rbp)
jmp 0x4a5d
movq -0xd8(%rbp), %rdi
movl $0xa, %esi
callq 0x3300
jmp 0x4a70
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x5120
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
callq 0x5150
movq %rax, -0x60(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x5180
testb $0x1, %al
jne 0x4aa8
jmp 0x4bcb
leaq -0x58(%rbp), %rdi
callq 0x51c0
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x25c5(%rip), %rsi      # 0x7085
callq 0x3270
movq %rax, -0xe0(%rbp)
jmp 0x4ace
movq -0xe0(%rbp), %rdi
leaq 0x25b0(%rip), %rsi      # 0x708c
callq 0x3270
movq %rax, -0xe8(%rbp)
jmp 0x4aea
movq -0xe8(%rbp), %rdi
movq -0x68(%rbp), %rsi
addq $0x24, %rsi
callq 0x4780
movq %rax, -0xf0(%rbp)
jmp 0x4b07
movq -0xf0(%rbp), %rdi
movl $0xa, %esi
callq 0x3300
jmp 0x4b1a
movq -0x8(%rbp), %rdi
leaq 0x256f(%rip), %rsi      # 0x7094
callq 0x3270
jmp 0x4b2c
movl $0x0, -0x6c(%rbp)
cmpl $0x3, -0x6c(%rbp)
jge 0x4b97
movq -0x8(%rbp), %rdi
leaq 0x255c(%rip), %rsi      # 0x70a0
callq 0x3270
movq %rax, -0xf8(%rbp)
jmp 0x4b52
movq -0xf8(%rbp), %rdi
movq -0x68(%rbp), %rax
movslq -0x6c(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,4), %rsi
callq 0x4710
movq %rax, -0x100(%rbp)
jmp 0x4b77
movq -0x100(%rbp), %rdi
movl $0xa, %esi
callq 0x3300
jmp 0x4b8a
jmp 0x4b8c
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x4b33
movq -0x8(%rbp), %rdi
leaq 0x2506(%rip), %rsi      # 0x70a8
callq 0x3270
jmp 0x4ba9
movq -0x8(%rbp), %rdi
leaq 0x24fd(%rip), %rsi      # 0x70b1
callq 0x3270
jmp 0x4bbb
jmp 0x4bbd
leaq -0x58(%rbp), %rdi
callq 0x51e0
jmp 0x4a92
movq -0x8(%rbp), %rdi
leaq 0x24e5(%rip), %rsi      # 0x70bb
callq 0x3270
movq %rax, -0x108(%rbp)
jmp 0x4be4
movq -0x108(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3260
movq %rax, -0x110(%rbp)
jmp 0x4bfd
movq -0x110(%rbp), %rdi
movl $0xa, %esi
callq 0x3300
jmp 0x4c10
leaq -0x38(%rbp), %rdi
callq 0x3190
jmp 0x4def
movq -0x10(%rbp), %rsi
addq $0x38, %rsi
leaq -0x90(%rbp), %rdi
callq 0x3120
leaq -0x90(%rbp), %rdi
callq 0x31d0
cmpq $0x0, %rax
jne 0x4c79
movq -0x10(%rbp), %rsi
addq $0x18, %rsi
leaq -0x90(%rbp), %rdi
callq 0x3030
jmp 0x4c5a
jmp 0x4c79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x3190
jmp 0x4df8
leaq -0x90(%rbp), %rdi
callq 0x31d0
cmpq $0x0, %rax
jne 0x4ca2
leaq 0x23e9(%rip), %rsi      # 0x707b
leaq -0x90(%rbp), %rdi
callq 0x3380
jmp 0x4ca0
jmp 0x4ca2
leaq -0x90(%rbp), %rdi
movl $0x50, %esi
xorl %edx, %edx
callq 0x30f0
jmp 0x4cb7
movq -0x8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x3260
jmp 0x4cc9
movq -0x8(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x10(%rbp), %rdi
callq 0x50f0
movq -0x118(%rbp), %rdi
movl %eax, -0x94(%rbp)
leaq -0x94(%rbp), %rsi
callq 0x4860
jmp 0x4cf8
movq -0x10(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rdi
callq 0x5120
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rdi
callq 0x5150
movq %rax, -0xb0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x5180
testb $0x1, %al
jne 0x4d45
jmp 0x4de3
leaq -0xa8(%rbp), %rdi
callq 0x51c0
movq %rax, -0xb8(%rbp)
movq -0x8(%rbp), %rdi
movq -0xb8(%rbp), %rsi
addq $0x24, %rsi
callq 0x4930
jmp 0x4d6e
movl $0x0, -0xbc(%rbp)
cmpl $0x3, -0xbc(%rbp)
jge 0x4db5
movq -0x8(%rbp), %rdi
movq -0xb8(%rbp), %rax
movslq -0xbc(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,4), %rsi
callq 0x48e0
jmp 0x4da2
jmp 0x4da4
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0x4d78
movq -0x8(%rbp), %rdi
movw $0x0, -0xbe(%rbp)
leaq -0xbe(%rbp), %rsi
callq 0x4820
jmp 0x4dd0
jmp 0x4dd2
leaq -0xa8(%rbp), %rdi
callq 0x51e0
jmp 0x4d29
leaq -0x90(%rbp), %rdi
callq 0x3190
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x3440
nopw %cs:(%rax,%rax)