// File: girdhari9[P]mTORRENT/CreateTorrentFile.cpp
// Function: mtorrentFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
string mtorrentFile(string SrcFileName, string TorrentFileName, string Tracker1IP, string Tracker1Port){

    struct stat fileStat; 
    int err = stat(SrcFileName.c_str(), &fileStat); 
    if (0 != err){
        string error = "Error occured in file";
        cout<<"Error occured in file";
        return error ;
    } 
    string l = to_string(fileStat.st_size);
    int mtorrentPtr = open(TorrentFileName.c_str(), O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);

    string Tracker1 = Tracker1IP + ":" + Tracker1Port + "\n";
    // string Tracker2 = "127.0.0.1:9001\n";
    write(mtorrentPtr,Tracker1.c_str(),strlen(Tracker1.c_str()));
    // write(mtorrentPtr,Tracker2.c_str(),strlen(Tracker2.c_str()));
    
    write(mtorrentPtr,SrcFileName.c_str(),strlen(SrcFileName.c_str()));
    write(mtorrentPtr,"\n",1);
    write(mtorrentPtr,l.c_str(),strlen(l.c_str()));
    write(mtorrentPtr,"\n",1);

    return CalculateSHA(SrcFileName,mtorrentPtr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movq %r8, -0x1a8(%rbp)
movq %rcx, -0x1a0(%rbp)
movq %rdx, -0x198(%rbp)
movq %rsi, -0x190(%rbp)
movq %rdi, %rax
movq -0x190(%rbp), %rdi
movq %rax, -0x188(%rbp)
movq %rax, %rsi
movq %rsi, -0x180(%rbp)
movq %rax, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
callq 0x41f0
movq %rax, %rdi
leaq -0xb8(%rbp), %rsi
callq 0x43d0
movl %eax, -0xbc(%rbp)
xorl %eax, %eax
cmpl -0xbc(%rbp), %eax
je 0x14abe
movb $0x0, -0xbd(%rbp)
leaq -0xbe(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0x4710
movq -0x188(%rbp), %rdi
movq -0x1b0(%rbp), %rdx
leaq 0x1d11(%rip), %rsi      # 0x1673e
callq 0x6d90
jmp 0x14a34
leaq -0xbe(%rbp), %rdi
callq 0x4450
movq 0xc581(%rip), %rdi      # 0x20fc8
leaq 0x1cf0(%rip), %rsi      # 0x1673e
callq 0x43f0
jmp 0x14a55
movb $0x1, -0xbd(%rbp)
testb $0x1, -0xbd(%rbp)
jne 0x14ab9
jmp 0x14aad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
leaq -0xbe(%rbp), %rdi
callq 0x4450
jmp 0x14d98
movq -0x188(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
callq 0x47e8
jmp 0x14d98
movq -0x188(%rbp), %rdi
callq 0x47e8
jmp 0x14d88
movq -0x88(%rbp), %rsi
leaq -0xf0(%rbp), %rdi
callq 0x150f0
movq -0x198(%rbp), %rdi
callq 0x41f0
movq %rax, %rdi
xorl %eax, %eax
movl $0x41, %esi
movl $0x180, %edx            # imm = 0x180
callq 0x4310
movl %eax, -0x1b4(%rbp)
jmp 0x14af9
movq -0x1a0(%rbp), %rsi
movl -0x1b4(%rbp), %eax
movl %eax, -0xf4(%rbp)
leaq 0x15c3(%rip), %rdx      # 0x160d6
leaq -0x158(%rbp), %rdi
callq 0x15220
jmp 0x14b21
movq -0x1a8(%rbp), %rdx
leaq -0x138(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x7330
jmp 0x14b3d
leaq 0x18fa(%rip), %rdx      # 0x1643e
leaq -0x118(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x72e0
jmp 0x14b59
leaq -0x138(%rbp), %rdi
callq 0x47e8
leaq -0x158(%rbp), %rdi
callq 0x47e8
movl -0xf4(%rbp), %eax
movl %eax, -0x1c4(%rbp)
leaq -0x118(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x41f0
movq -0x1d0(%rbp), %rdi
movq %rax, -0x1c0(%rbp)
callq 0x41f0
movq %rax, %rdi
callq 0x4210
movl -0x1c4(%rbp), %edi
movq -0x1c0(%rbp), %rsi
movq %rax, %rdx
callq 0x41b0
jmp 0x14bc2
movq -0x190(%rbp), %rdi
movl -0xf4(%rbp), %eax
movl %eax, -0x1dc(%rbp)
callq 0x41f0
movq -0x190(%rbp), %rdi
movq %rax, -0x1d8(%rbp)
callq 0x41f0
movq %rax, %rdi
callq 0x4210
movl -0x1dc(%rbp), %edi
movq -0x1d8(%rbp), %rsi
movq %rax, %rdx
callq 0x41b0
jmp 0x14c0c
movl -0xf4(%rbp), %edi
leaq 0x1825(%rip), %rsi      # 0x1643e
movl $0x1, %edx
callq 0x41b0
jmp 0x14c25
movl -0xf4(%rbp), %eax
movl %eax, -0x1ec(%rbp)
leaq -0xf0(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x41f0
movq -0x1f8(%rbp), %rdi
movq %rax, -0x1e8(%rbp)
callq 0x41f0
movq %rax, %rdi
callq 0x4210
movl -0x1ec(%rbp), %edi
movq -0x1e8(%rbp), %rsi
movq %rax, %rdx
callq 0x41b0
jmp 0x14c76
movl -0xf4(%rbp), %edi
leaq 0x17bb(%rip), %rsi      # 0x1643e
movl $0x1, %edx
callq 0x41b0
jmp 0x14c8f
movq -0x190(%rbp), %rsi
leaq -0x178(%rbp), %rdi
callq 0x4200
jmp 0x14ca4
movq -0x188(%rbp), %rdi
movl -0xf4(%rbp), %edx
leaq -0x178(%rbp), %rsi
callq 0x14db0
jmp 0x14cbf
leaq -0x178(%rbp), %rdi
callq 0x47e8
leaq -0x118(%rbp), %rdi
callq 0x47e8
leaq -0xf0(%rbp), %rdi
callq 0x47e8
jmp 0x14d88
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
jmp 0x14d7a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
jmp 0x14d2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x47e8
leaq -0x158(%rbp), %rdi
callq 0x47e8
jmp 0x14d7a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
jmp 0x14d6e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x47e8
leaq -0x118(%rbp), %rdi
callq 0x47e8
leaq -0xf0(%rbp), %rdi
callq 0x47e8
jmp 0x14d98
movq -0x180(%rbp), %rax
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
movq -0xc8(%rbp), %rdi
callq 0x4700
nopw %cs:(%rax,%rax)