// File: /workspace/github_cpp_makefile_star2_O1/snesic[P]stochastic_thin_films/instabilities.cpp
// Function: main
int main(int argc, char * const argv[])
{   int L, i_sim_0, j_time;
    double b, ugao;     // L System size; dx, dt - Time and Space lattice distances. b - Precursor layer.
    
    time_t vreme;
    string dir;
    stringstream check_dir, krajnje_vreme;
    struct stat sb;
    long int *inic = new long int;
    double dx, dt, sigma;
    double t, t0, jdt, jdt_no;
    
    if(argc<3){ dir = "test_dir"; }
    else {dir = argv[2];}
    
    i_sim_0 = atoi(argv[1]);
    check_dir << dir << "/" << i_sim_0;
    
    if (stat(check_dir.str().c_str(), &sb) == 0 && S_ISDIR(sb.st_mode))
    { cout<< check_dir.str()<< " exists... The folowing simulation will be preformed:" << endl; }            // The simulation starts only if there is a directory!
    else {cout<< "This simulations is canceled as there is no directory to write down results!"<<endl; return 1;}
    
    
    L=3*266+1;
    dx=0.01;
    dt=1e-5;
    t0=0;
    t=7;
    b=0.01;
    ugao=50;
    sigma=1e-4;
    
    *inic=45; // time(NULL)+i_sim_0*500;
    vreme=time(NULL);
    
    
//    print_initial_parameters(sigma, dt, dx, L, b, A, a_min, t, t0, ugao, i_sim_0);

    film droplet(L, dx, dt, b, ugao, sigma);
    initial_condition_sin(droplet.h,L,dx,b);
    
    
    jdt=t0;
    j_time=0;
    jdt_no=t0+dt;

    do
    {   droplet.simulation(jdt_no, jdt, inic);
        cout << "Time step: " << jdt << " dt " << dt << " max:  " << droplet.h[266] << endl;
        write_in_File(droplet.h, L, dx, j_time, check_dir.str());
        jdt=jdt_no;
        if(jdt_no<1) jdt_no=jdt_no*10; else jdt_no=trunc(jdt+1);
        j_time++;
    }while(j_time<t);
    

    
    vreme=time(NULL)-vreme;
    krajnje_vreme.str("");
    krajnje_vreme << trunc(vreme/3600) << " hours and " << trunc(fmod(vreme,3600)/60) << " min.";
    cout << "Calculation time is: " << vreme << endl;
    cout << "which is " << krajnje_vreme.str() << endl;
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4d8, %rsp            # imm = 0x4D8
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x138(%rsp), %r13
movq %r13, %rdi
callq 0x2120
leaq 0x2c0(%rsp), %rdi
callq 0x2120
movl $0x8, %edi
callq 0x21d0
movq %rax, 0x30(%rsp)
cmpl $0x2, %ebp
jg 0x25c6
leaq 0x38(%rsp), %rdi
movq 0x8(%rdi), %rdx
leaq 0x4a89(%rip), %rcx      # 0x7040
movl $0x8, %r8d
xorl %esi, %esi
callq 0x22a0
jmp 0x25ee
movq 0x10(%rbx), %r14
leaq 0x38(%rsp), %r15
movq 0x8(%r15), %r12
movq %r14, %rdi
callq 0x20b0
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %r14, %rcx
movq %rax, %r8
callq 0x22a0
movq 0x8(%rbx), %rdi
callq 0x22b0
movl %eax, %ebx
leaq 0x148(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0x2200
movq %rax, %r14
leaq 0x4a2f(%rip), %rsi      # 0x7049
movl $0x1, %edx
movq %rax, %rdi
callq 0x2200
movq %r14, %rdi
movl %ebx, %esi
callq 0x22f0
leaq 0x150(%rsp), %rsi
leaq 0x80(%rsp), %rdi
callq 0x22c0
leaq 0x90(%rsp), %r14
movq -0x10(%r14), %rdi
leaq 0x448(%rsp), %rbx
movq %rbx, %rsi
callq 0x2190
movl 0x18(%rbx), %ecx
andl $0xf000, %ecx           # imm = 0xF000
xorl $0x4000, %ecx           # imm = 0x4000
orl %eax, %ecx
sete %bl
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x268f
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x21e0
testb %bl, %bl
je 0x2ac8
leaq 0x80(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x22c0
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq 0x8915(%rip), %rdi      # 0xafd8
callq 0x2200
movq %rax, %rbx
leaq 0x4979(%rip), %rsi      # 0x704b
movl $0x35, %edx
movq %rax, %rdi
callq 0x2200
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2110
movq 0x80(%rsp), %rdi
cmpq %r14, %rdi
je 0x2723
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x21e0
movq 0x30(%rsp), %rax
movq $0x2d, (%rax)
xorl %edi, %edi
callq 0x21a0
movq %rax, 0x58(%rsp)
leaq 0x80(%rsp), %rdi
movsd 0x48bd(%rip), %xmm1     # 0x7008
movsd 0x48bd(%rip), %xmm0     # 0x7010
movsd 0x48bd(%rip), %xmm3     # 0x7018
movl $0x31f, %esi            # imm = 0x31F
movapd %xmm0, %xmm2
movl $0x32, %edx
callq 0x2cec
movq 0x80(%rsp), %rdi
movsd 0x4892(%rip), %xmm0     # 0x7010
movl $0x31f, %esi            # imm = 0x31F
movapd %xmm0, %xmm1
callq 0x3d5a
leaq 0x8(%rsp), %rax
movq $0x0, (%rax)
xorl %r13d, %r13d
movq 0x8836(%rip), %r14      # 0xafd8
leaq 0x63d9(%rip), %r15      # 0x8b82
leaq 0x492a(%rip), %rbx      # 0x70da
leaq 0x60(%rsp), %r12
movsd 0x484b(%rip), %xmm0     # 0x7008
movsd %xmm0, (%rsp)
leaq 0x80(%rsp), %rdi
movsd (%rsp), %xmm0
leaq 0x8(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0x32ea
movl $0xb, %edx
movq %r14, %rdi
leaq 0x48e1(%rip), %rsi      # 0x70ce
callq 0x2200
movsd 0x8(%rsp), %xmm0
movq %r14, %rdi
callq 0x22d0
movq %rax, %rbp
movl $0x4, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2200
movq %rbp, %rdi
movsd 0x47ea(%rip), %xmm0     # 0x7008
callq 0x22d0
movq %rax, %rbp
movl $0x7, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2200
movq 0x80(%rsp), %rax
movsd 0x850(%rax), %xmm0
movq %rbp, %rdi
callq 0x22d0
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbp, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2110
movq 0x80(%rsp), %rbp
movq %r12, %rdi
leaq 0x150(%rsp), %rsi
callq 0x22c0
movq %rbp, %rdi
movl $0x31f, %esi            # imm = 0x31F
movsd 0x4770(%rip), %xmm0     # 0x7010
movl %r13d, %edx
movq %r12, %rcx
callq 0x5a91
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x28c7
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x21e0
movsd (%rsp), %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x4746(%rip), %xmm0     # 0x7020
ucomisd %xmm1, %xmm0
jbe 0x28ef
mulsd 0x4740(%rip), %xmm1     # 0x7028
movsd %xmm1, (%rsp)
jmp 0x2901
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
callq 0x20d0
movsd %xmm0, (%rsp)
incl %r13d
cmpl $0x7, %r13d
jne 0x27c2
xorl %edi, %edi
callq 0x21a0
movq %rax, %r14
leaq 0x20(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x6300(%rip), %rdx      # 0x8c29
leaq 0x10(%rsp), %rdi
movq %rdx, %rsi
callq 0x2c5a
leaq 0x2d8(%rsp), %rbx
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x2280
leaq 0x138(%rsp), %r13
subq 0x58(%rsp), %r14
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x296f
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21e0
movabsq $0x48d159e26af37c05, %rcx # imm = 0x48D159E26AF37C05
movq %r14, %rax
imulq %rcx
leaq 0x2d0(%rsp), %rdi
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0xa, %rdx
addq %rax, %rdx
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
callq 0x22d0
movq %rax, %r15
leaq 0x4736(%rip), %rsi      # 0x70e2
movl $0xb, %edx
movq %rax, %rdi
callq 0x2200
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
movsd 0x4667(%rip), %xmm1     # 0x7030
callq 0x2240
divsd 0x4662(%rip), %xmm0     # 0x7038
callq 0x20d0
movq %r15, %rdi
callq 0x22d0
leaq 0x4704(%rip), %rsi      # 0x70ee
movl $0x5, %edx
movq %rax, %rdi
callq 0x2200
movq 0x85da(%rip), %rdi      # 0xafd8
leaq 0x46ef(%rip), %rsi      # 0x70f4
movl $0x15, %edx
callq 0x2200
movq 0x85c2(%rip), %rdi      # 0xafd8
movq %r14, %rsi
callq 0x21b0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2110
movq 0x8589(%rip), %rdi      # 0xafd8
leaq 0x46b4(%rip), %rsi      # 0x710a
movl $0x9, %edx
callq 0x2200
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x22c0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x855a(%rip), %rdi      # 0xafd8
callq 0x2200
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2110
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x2ac4
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21e0
xorl %ebx, %ebx
jmp 0x2b13
movq 0x8509(%rip), %rbx      # 0xafd8
leaq 0x45ab(%rip), %rsi      # 0x7081
movl $0x4c, %edx
movq %rbx, %rdi
callq 0x2200
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x84d7(%rip), %rdi      # 0xafd8
callq 0x2040
movl $0x1, %ebx
movq %rax, %rdi
callq 0x2110
movq 0x849e(%rip), %r14      # 0xafb8
leaq 0x2c0(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x2140
movl $0x80, %r15d
addq %r15, %r12
movq %r12, %rdi
callq 0x2090
movq %r13, %rdi
movq %r14, %rsi
callq 0x2140
addq %r15, %r13
movq %r13, %rdi
callq 0x2090
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x2b70
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x21e0
movl %ebx, %eax
addq $0x4d8, %rsp            # imm = 0x4D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2bf0
jmp 0x2b9d
jmp 0x2bf0
jmp 0x2bf0
jmp 0x2bf0
jmp 0x2bf0
movq %rax, %rbx
jmp 0x2c14
movq %rax, %rbx
jmp 0x2c35
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x2bf3
movq 0x20(%rsp), %rsi
jmp 0x2be6
movq %rax, %rbx
movq 0x80(%rsp), %rdi
cmpq %r14, %rdi
je 0x2bf3
movq 0x90(%rsp), %rsi
jmp 0x2be6
jmp 0x2bf0
jmp 0x2bf0
movq %rax, %rbx
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x2bf3
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x21e0
jmp 0x2bf3
movq %rax, %rbx
movq 0x83be(%rip), %rsi      # 0xafb8
leaq 0x2c0(%rsp), %rdi
callq 0x2140
leaq 0x340(%rsp), %rdi
callq 0x2090
movq 0x839d(%rip), %rsi      # 0xafb8
leaq 0x138(%rsp), %rdi
callq 0x2140
leaq 0x1b8(%rsp), %rdi
callq 0x2090
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x2c51
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x21e0
movq %rbx, %rdi
callq 0x2310
nop