// File: 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
movq %rsp, %rbp
subq $0x690, %rsp            # imm = 0x690
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x3370
leaq -0x1e0(%rbp), %rdi
callq 0x31a0
jmp 0x3760
leaq -0x378(%rbp), %rdi
callq 0x31a0
jmp 0x376e
movl $0x8, %edi
callq 0x3280
movq %rax, -0x5b8(%rbp)
jmp 0x3781
movq -0x5b8(%rbp), %rax
movq %rax, -0x410(%rbp)
cmpl $0x3, -0x8(%rbp)
jge 0x37ee
leaq 0x6884(%rip), %rsi      # 0xa020
leaq -0x58(%rbp), %rdi
callq 0x3360
jmp 0x37a7
jmp 0x3803
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1e8(%rbp)
movl %eax, -0x1ec(%rbp)
jmp 0x3f69
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1e8(%rbp)
movl %eax, -0x1ec(%rbp)
jmp 0x3f5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1e8(%rbp)
movl %eax, -0x1ec(%rbp)
jmp 0x3f51
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
leaq -0x58(%rbp), %rdi
callq 0x3360
jmp 0x3801
jmp 0x3803
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x33c0
movl %eax, -0x18(%rbp)
leaq -0x1d0(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x3230
movq %rax, -0x5c0(%rbp)
jmp 0x382c
movq -0x5c0(%rbp), %rdi
leaq 0x67ef(%rip), %rsi      # 0xa029
callq 0x3270
movq %rax, -0x5c8(%rbp)
jmp 0x3848
movq -0x5c8(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x3400
jmp 0x3859
leaq -0x468(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x3260
jmp 0x386e
leaq -0x468(%rbp), %rdi
callq 0x30c0
movq %rax, %rdi
leaq -0x408(%rbp), %rsi
callq 0x3240
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x5c9(%rbp)
jne 0x38b1
movl -0x3f0(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x4000, %eax           # imm = 0x4000
sete %al
movb %al, -0x5c9(%rbp)
movb -0x5c9(%rbp), %al
movb %al, -0x5ca(%rbp)
leaq -0x468(%rbp), %rdi
callq 0x3140
movb -0x5ca(%rbp), %al
testb $0x1, %al
jne 0x38d8
jmp 0x396b
leaq -0x488(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x3260
jmp 0x38ed
movq 0xb6e4(%rip), %rdi      # 0xefd8
leaq -0x488(%rbp), %rsi
callq 0x3230
movq %rax, -0x5d8(%rbp)
jmp 0x3909
movq -0x5d8(%rbp), %rdi
leaq 0x6714(%rip), %rsi      # 0xa02b
callq 0x3270
movq %rax, -0x5e0(%rbp)
jmp 0x3925
movq -0x5e0(%rbp), %rdi
movq 0xb695(%rip), %rsi      # 0xefc8
callq 0x3290
jmp 0x393a
leaq -0x488(%rbp), %rdi
callq 0x3140
jmp 0x39b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1e8(%rbp)
movl %eax, -0x1ec(%rbp)
leaq -0x488(%rbp), %rdi
callq 0x3140
jmp 0x3f51
movq 0xb666(%rip), %rdi      # 0xefd8
leaq 0x66e8(%rip), %rsi      # 0xa061
callq 0x3270
movq %rax, -0x5e8(%rbp)
jmp 0x3987
movq -0x5e8(%rbp), %rdi
movq 0xb633(%rip), %rsi      # 0xefc8
callq 0x3290
jmp 0x399c
movl $0x1, -0x4(%rbp)
movl $0x1, -0x48c(%rbp)
jmp 0x3f24
movl $0x31f, -0x14(%rbp)     # imm = 0x31F
movabsq $0x3f847ae147ae147b, %rax # imm = 0x3F847AE147AE147B
movq %rax, -0x418(%rbp)
movabsq $0x3ee4f8b588e368f1, %rcx # imm = 0x3EE4F8B588E368F1
movq %rcx, -0x420(%rbp)
movq $0x0, -0x438(%rbp)
movabsq $0x401c000000000000, %rcx # imm = 0x401C000000000000
movq %rcx, -0x430(%rbp)
movq %rax, -0x28(%rbp)
movabsq $0x4049000000000000, %rax # imm = 0x4049000000000000
movq %rax, -0x30(%rbp)
movabsq $0x3f1a36e2eb1c432d, %rax # imm = 0x3F1A36E2EB1C432D
movq %rax, -0x428(%rbp)
movq -0x410(%rbp), %rax
movq $0x2d, (%rax)
xorl %eax, %eax
movl %eax, %edi
callq 0x3250
movq %rax, -0x38(%rbp)
movl -0x14(%rbp), %esi
movsd -0x418(%rbp), %xmm0
movsd -0x420(%rbp), %xmm1
movsd -0x28(%rbp), %xmm2
cvttsd2si -0x30(%rbp), %edx
movsd -0x428(%rbp), %xmm3
leaq -0x548(%rbp), %rdi
callq 0x4320
jmp 0x3a68
movq -0x548(%rbp), %rdi
movl -0x14(%rbp), %esi
movsd -0x418(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
callq 0x6890
jmp 0x3a86
movsd -0x438(%rbp), %xmm0
movsd %xmm0, -0x440(%rbp)
movl $0x0, -0x1c(%rbp)
movsd -0x438(%rbp), %xmm0
addsd -0x420(%rbp), %xmm0
movsd %xmm0, -0x448(%rbp)
movsd -0x448(%rbp), %xmm0
movq -0x410(%rbp), %rdx
leaq -0x548(%rbp), %rdi
leaq -0x440(%rbp), %rsi
callq 0x4ea0
jmp 0x3ad9
movq 0xb4f8(%rip), %rdi      # 0xefd8
leaq 0x65c7(%rip), %rsi      # 0xa0ae
callq 0x3270
movq %rax, -0x5f0(%rbp)
jmp 0x3af5
movq -0x5f0(%rbp), %rdi
movsd -0x440(%rbp), %xmm0
callq 0x34b0
movq %rax, -0x5f8(%rbp)
jmp 0x3b12
movq -0x5f8(%rbp), %rdi
leaq 0x817a(%rip), %rsi      # 0xbc9a
callq 0x3270
movq %rax, -0x600(%rbp)
jmp 0x3b2e
movq -0x600(%rbp), %rdi
movsd -0x420(%rbp), %xmm0
callq 0x34b0
movq %rax, -0x608(%rbp)
jmp 0x3b4b
movq -0x608(%rbp), %rdi
leaq 0x6561(%rip), %rsi      # 0xa0ba
callq 0x3270
movq %rax, -0x610(%rbp)
jmp 0x3b67
movq -0x610(%rbp), %rdi
movq -0x548(%rbp), %rax
movsd 0x850(%rax), %xmm0
callq 0x34b0
movq %rax, -0x618(%rbp)
jmp 0x3b8b
movq -0x618(%rbp), %rdi
movq 0xb42f(%rip), %rsi      # 0xefc8
callq 0x3290
jmp 0x3ba0
movq -0x548(%rbp), %rax
movq %rax, -0x638(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x62c(%rbp)
movsd -0x418(%rbp), %xmm0
movsd %xmm0, -0x628(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x61c(%rbp)
leaq -0x568(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x3260
jmp 0x3be5
movl -0x61c(%rbp), %edx
movsd -0x628(%rbp), %xmm0
movl -0x62c(%rbp), %esi
movq -0x638(%rbp), %rdi
leaq -0x568(%rbp), %rcx
callq 0x92e0
jmp 0x3c0e
leaq -0x568(%rbp), %rdi
callq 0x3140
movsd -0x448(%rbp), %xmm0
movsd %xmm0, -0x440(%rbp)
movsd 0x63d6(%rip), %xmm0     # 0xa008
ucomisd -0x448(%rbp), %xmm0
jbe 0x3c79
movsd 0x63cc(%rip), %xmm0     # 0xa010
mulsd -0x448(%rbp), %xmm0
movsd %xmm0, -0x448(%rbp)
jmp 0x3c96
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1e8(%rbp)
movl %eax, -0x1ec(%rbp)
leaq -0x568(%rbp), %rdi
callq 0x3140
jmp 0x3f51
movsd 0x6387(%rip), %xmm0     # 0xa008
addsd -0x440(%rbp), %xmm0
callq 0x3130
movsd %xmm0, -0x448(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
cvtsi2sdl -0x1c(%rbp), %xmm1
movsd -0x430(%rbp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x3ab5
xorl %eax, %eax
movl %eax, %edi
callq 0x3250
movq -0x38(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x38(%rbp)
leaq -0x589(%rbp), %rdi
movq %rdi, -0x640(%rbp)
callq 0x3430
movq -0x640(%rbp), %rdx
leaq 0x8056(%rip), %rsi      # 0xbd41
leaq -0x588(%rbp), %rdi
callq 0x3f80
jmp 0x3cf9
leaq -0x378(%rbp), %rdi
leaq -0x588(%rbp), %rsi
callq 0x32e0
jmp 0x3d0e
leaq -0x588(%rbp), %rdi
callq 0x3140
leaq -0x589(%rbp), %rdi
callq 0x32b0
leaq -0x368(%rbp), %rax
movq %rax, -0x650(%rbp)
movq -0x38(%rbp), %rax
movabsq $0x48d159e26af37c05, %rcx # imm = 0x48D159E26AF37C05
imulq %rcx
movq %rdx, %rdi
movq %rdi, %rdx
shrq $0x3f, %rdx
sarq $0xa, %rdi
addq %rdx, %rdi
callq 0x4030
movsd %xmm0, -0x648(%rbp)
jmp 0x3d65
movsd -0x648(%rbp), %xmm0
movq -0x650(%rbp), %rdi
callq 0x34b0
movq %rax, -0x658(%rbp)
jmp 0x3d82
movq -0x658(%rbp), %rdi
leaq 0x6332(%rip), %rsi      # 0xa0c2
callq 0x3270
movq %rax, -0x660(%rbp)
jmp 0x3d9e
movq -0x38(%rbp), %rdi
movl $0xe10, %esi            # imm = 0xE10
callq 0x4050
movsd %xmm0, -0x668(%rbp)
jmp 0x3db6
movsd -0x668(%rbp), %xmm0
movsd 0x6252(%rip), %xmm1     # 0xa018
divsd %xmm1, %xmm0
callq 0x3130
movq -0x660(%rbp), %rdi
callq 0x34b0
movq %rax, -0x670(%rbp)
jmp 0x3de4
movq -0x670(%rbp), %rdi
leaq 0x62dc(%rip), %rsi      # 0xa0ce
callq 0x3270
jmp 0x3df9
movq 0xb1d8(%rip), %rdi      # 0xefd8
leaq 0x62cd(%rip), %rsi      # 0xa0d4
callq 0x3270
movq %rax, -0x678(%rbp)
jmp 0x3e15
movq -0x678(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x3470
movq %rax, -0x680(%rbp)
jmp 0x3e2e
movq -0x680(%rbp), %rdi
movq 0xb18c(%rip), %rsi      # 0xefc8
callq 0x3290
jmp 0x3e43
movq 0xb18e(%rip), %rdi      # 0xefd8
leaq 0x6299(%rip), %rsi      # 0xa0ea
callq 0x3270
movq %rax, -0x688(%rbp)
jmp 0x3e5f
leaq -0x5b0(%rbp), %rdi
leaq -0x378(%rbp), %rsi
callq 0x3260
jmp 0x3e74
movq -0x688(%rbp), %rdi
leaq -0x5b0(%rbp), %rsi
callq 0x3230
movq %rax, -0x690(%rbp)
jmp 0x3e90
movq -0x690(%rbp), %rdi
movq 0xb12a(%rip), %rsi      # 0xefc8
callq 0x3290
jmp 0x3ea5
leaq -0x5b0(%rbp), %rdi
callq 0x3140
movl $0x0, -0x4(%rbp)
movl $0x1, -0x48c(%rbp)
jmp 0x3f24
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1e8(%rbp)
movl %eax, -0x1ec(%rbp)
jmp 0x3ef6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1e8(%rbp)
movl %eax, -0x1ec(%rbp)
leaq -0x588(%rbp), %rdi
callq 0x3140
leaq -0x589(%rbp), %rdi
callq 0x32b0
jmp 0x3f51
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1e8(%rbp)
movl %eax, -0x1ec(%rbp)
leaq -0x5b0(%rbp), %rdi
callq 0x3140
jmp 0x3f51
leaq -0x378(%rbp), %rdi
callq 0x31c0
leaq -0x1e0(%rbp), %rdi
callq 0x31c0
leaq -0x58(%rbp), %rdi
callq 0x3140
movl -0x4(%rbp), %eax
addq $0x690, %rsp            # imm = 0x690
popq %rbp
retq
leaq -0x378(%rbp), %rdi
callq 0x31c0
leaq -0x1e0(%rbp), %rdi
callq 0x31c0
leaq -0x58(%rbp), %rdi
callq 0x3140
movq -0x1e8(%rbp), %rdi
callq 0x3420
nop