// File: /workspace/github_cpp_makefile_star2_O2/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, %r14
movl %edi, %ebp
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x138(%rsp), %rdi
callq 0x2110
leaq 0x2c0(%rsp), %rdi
callq 0x2110
pushq $0x8
popq %rdi
callq 0x21c0
movq %rax, %rbx
cmpl $0x2, %ebp
jg 0x25c0
leaq 0x3a84(%rip), %rsi      # 0x6038
leaq 0x40(%rsp), %rdi
callq 0x2370
jmp 0x25ce
movq 0x10(%r14), %rsi
leaq 0x40(%rsp), %rdi
callq 0x2370
movq 0x8(%r14), %rdi
callq 0x2290
movl %eax, %ebp
leaq 0x148(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x2170
leaq 0x3a4f(%rip), %rsi      # 0x6041
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
movl %ebp, %esi
callq 0x22e0
leaq 0x150(%rsp), %rsi
leaq 0x80(%rsp), %rdi
callq 0x22a0
leaq 0x80(%rsp), %r14
movq (%r14), %rdi
leaq 0x448(%rsp), %r15
movq %r15, %rsi
callq 0x2180
movl %eax, %ebp
movl $0xf000, %r12d          # imm = 0xF000
andl 0x18(%r15), %r12d
movq %r14, %rdi
callq 0x2090
testl %ebp, %ebp
jne 0x2944
cmpl $0x4000, %r12d          # imm = 0x4000
jne 0x2944
leaq 0x80(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x22a0
movq 0x795f(%rip), %rdi      # 0x9fd8
leaq 0x80(%rsp), %rsi
callq 0x2170
leaq 0x39b6(%rip), %rsi      # 0x6043
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20a0
leaq 0x80(%rsp), %rdi
callq 0x2090
movq $0x2d, (%rbx)
xorl %edi, %edi
callq 0x2190
movq %rax, 0x10(%rsp)
leaq 0x80(%rsp), %rdi
movsd 0x393b(%rip), %xmm1     # 0x6008
movsd 0x393b(%rip), %xmm0     # 0x6010
pushq $0x32
popq %rdx
movsd 0x3938(%rip), %xmm3     # 0x6018
movl $0x31f, %esi            # imm = 0x31F
movapd %xmm0, %xmm2
callq 0x2aec
movq 0x80(%rsp), %rdi
movsd 0x3912(%rip), %xmm0     # 0x6010
movl $0x31f, %esi            # imm = 0x31F
movapd %xmm0, %xmm1
callq 0x3a34
leaq 0x8(%rsp), %rax
andq $0x0, (%rax)
xorl %ebp, %ebp
leaq 0x5524(%rip), %r13      # 0x7c42
leaq 0x39ad(%rip), %r15      # 0x60d2
leaq 0x60(%rsp), %r14
movsd 0x38d6(%rip), %xmm1     # 0x6008
leaq 0x80(%rsp), %rdi
movsd %xmm1, 0x18(%rsp)
movapd %xmm1, %xmm0
leaq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x309c
movq 0x7880(%rip), %rdi      # 0x9fd8
leaq 0x3967(%rip), %rsi      # 0x60c6
callq 0x21b0
movsd 0x8(%rsp), %xmm0
movq %rax, %rdi
callq 0x22c0
movq %rax, %rdi
movq %r13, %rsi
callq 0x21b0
movq %rax, %rdi
movsd 0x3880(%rip), %xmm0     # 0x6008
callq 0x22c0
movq %rax, %rdi
movq %r15, %rsi
callq 0x21b0
movq 0x80(%rsp), %rcx
movsd 0x850(%rcx), %xmm0
movq %rax, %rdi
callq 0x22c0
movq %rax, %rdi
callq 0x20a0
movq 0x80(%rsp), %r12
movq %r14, %rdi
leaq 0x150(%rsp), %rsi
callq 0x22a0
movq %r12, %rdi
movl $0x31f, %esi            # imm = 0x31F
movsd 0x3830(%rip), %xmm0     # 0x6010
movl %ebp, %edx
movq %r14, %rcx
callq 0x4fea
movq %r14, %rdi
callq 0x2090
movsd 0x18(%rsp), %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x381a(%rip), %xmm0     # 0x6020
ucomisd %xmm1, %xmm0
jbe 0x2816
mulsd 0x3814(%rip), %xmm1     # 0x6028
jmp 0x2827
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
callq 0x20c0
movapd %xmm0, %xmm1
incl %ebp
cmpl $0x7, %ebp
jne 0x2732
xorl %edi, %edi
callq 0x2190
movq %rax, %r14
leaq 0x54a6(%rip), %rsi      # 0x7ce9
leaq 0x20(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x2a0a
leaq 0x2d8(%rsp), %rbx
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x2270
subq 0x10(%rsp), %r14
leaq 0x20(%rsp), %rdi
callq 0x2090
leaq 0x2d0(%rsp), %rdi
movl $0xe10, %ecx            # imm = 0xE10
movq %r14, %rax
cqto
idivq %rcx
cvtsi2sd %rax, %xmm0
callq 0x22c0
leaq 0x383e(%rip), %rsi      # 0x60da
movq %rax, %rdi
callq 0x21b0
movq %rax, %r15
movq %r14, %rdi
movl $0xe10, %esi            # imm = 0xE10
callq 0x2a45
divsd 0x3774(%rip), %xmm0     # 0x6030
callq 0x20c0
movq %r15, %rdi
callq 0x22c0
leaq 0x3816(%rip), %rsi      # 0x60e6
movq %rax, %rdi
callq 0x21b0
movq 0x76f9(%rip), %rdi      # 0x9fd8
leaq 0x3806(%rip), %rsi      # 0x60ec
callq 0x21b0
movq %rax, %rdi
movq %r14, %rsi
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
movq 0x76d3(%rip), %rdi      # 0x9fd8
leaq 0x37f6(%rip), %rsi      # 0x6102
callq 0x21b0
movq %rax, %r14
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x22a0
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x2170
movq %rax, %rdi
callq 0x20a0
leaq 0x20(%rsp), %rdi
callq 0x2090
xorl %ebx, %ebx
jmp 0x2962
movq 0x768d(%rip), %rdi      # 0x9fd8
leaq 0x3727(%rip), %rsi      # 0x6079
callq 0x21b0
movq %rax, %rdi
callq 0x20a0
pushq $0x1
popq %rbx
leaq 0x2c0(%rsp), %rdi
callq 0x2130
leaq 0x138(%rsp), %rdi
callq 0x2130
leaq 0x40(%rsp), %rdi
callq 0x2090
movl %ebx, %eax
addq $0x4d8, %rsp            # imm = 0x4D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x29da
jmp 0x29a2
jmp 0x29da
jmp 0x29da
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
jmp 0x29d3
jmp 0x29da
jmp 0x29da
movq %rax, %rbx
jmp 0x29ea
movq %rax, %rbx
jmp 0x29f7
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
jmp 0x29d3
jmp 0x29da
jmp 0x29da
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x2090
jmp 0x29dd
movq %rax, %rbx
leaq 0x2c0(%rsp), %rdi
callq 0x2130
leaq 0x138(%rsp), %rdi
callq 0x2130
leaq 0x40(%rsp), %rdi
callq 0x2090
movq %rbx, %rdi
callq 0x2300
nop