// File: /workspace/github_c_makefile_star2_O0/snow1eo[P]IPsec_IKEv2/ike.c
// Function: ike_init_resp
int ike_init_resp (void)
{
    acc_proposal = SA_recv.proposals;
    Ni = NONCE_recv;
    KEi = KE_recv;
    memcpy (SPIi, &HDR_recv.init_SPI, sizeof (uint64_t));
    SAr1.proposals = acc_proposal;
    SAr1.header.next_payload = PL_KE;
    SAr1.header.critical = 0;
    SAr1.header.payload_length = sizeof (generic_payload_header);
    uint32_t prop_num = 0;
    do SAr1.header.payload_length += SAr1.proposals[prop_num].proposal_length;
    while (SAr1.proposals[prop_num++].more != 0);

    dh_group = 0;
    for (int i = 0; i < acc_proposal->num_transforms; i++)
        if (acc_proposal->transforms[i].transform_type == DH_GR &&
            acc_proposal->transforms[i].transform_ID > dh_group)
            dh_group = acc_proposal->transforms[i].transform_ID;
    modp = get_modp (dh_group);

    KEr.header.next_payload = PL_NONCE;
    KEr.header.critical = 0;
    KEr.header.payload_length = sizeof (KEr.header) +
        sizeof (KEr.dh_group_num) + sizeof (KEr.reserved) + modp/8;
    KEr.dh_group_num = dh_group;
    KEr.reserved = 0;
    KEr.key_exchange_data = calloc (modp/8, 1);
    MEMCHECK (KEr.key_exchange_data);

    mpz_set (dh_b, dh_nsize_random (B_SIZE));
    dh_set_p (modp);
    mpz_powm_sec (dh_B, dh_g, dh_b, dh_p);
    size_t *count = (size_t*) calloc (1, sizeof (size_t));
    uint32_t size = mpz_sizeinbase (dh_B, 256);
    mpz_export (KEr.key_exchange_data + modp/8 - size, count, 0, sizeof (char), 1, 0, dh_B);
    free (count);

    Nr.header.next_payload = NO_NEXT_PL;
    Nr.header.critical = 0;
    Nr_len = 4*(4 + (rand() % 60));
    Nr.header.payload_length = sizeof (Nr.header) + Nr_len;
    Nr.nonce_data = calloc (1, Nr_len);
    for (int i = 0; i < Nr_len; i++)
        Nr.nonce_data[i] = rand ();

    ike_header HDR;
    HDR.init_SPI = HDR_recv.init_SPI;
    for (int i = 0; i < sizeof (HDR.resp_SPI); i++)
        SPIr[i] = *((char*)&HDR.resp_SPI + i) = rand ();
    HDR.next_payload = PL_SA;
    HDR.versions = VERSIONS;
    HDR.exchange_type = IKE_SA_INIT;
    HDR.flags = RXX;
    HDR.message_ID = HDR_recv.message_ID;
    HDR.length = ike_sa_init_resp_len = 
        sizeof (ike_header) + SAr1.header.payload_length +
        KEr.header.payload_length + Nr.header.payload_length;

    free (buff);
    buff = calloc (1, HDR.length);
    uint32_t offset = 0;
    offset += ike_hdr2char  (&HDR,  buff + offset);
    offset += sa_pl2char    (&SAr1, buff + offset);
    offset += ke_pl2char    (&KEr,  buff + offset);
    offset += nonce_pl2char (&Nr,   buff + offset);

    ike_sa_init_resp_len = HDR.length;
    ike_sa_init_resp = calloc (1, ike_sa_init_resp_len);
    memcpy (ike_sa_init_resp, buff, ike_sa_init_resp_len);
    return offset;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq 0xc431(%rip), %rax      # 0x12510
movq %rax, 0xc4c2(%rip)      # 0x125a8
movq 0xc4c3(%rip), %rax      # 0x125b0
movq %rax, 0xc3c4(%rip)      # 0x124b8
movl 0xc4be(%rip), %eax      # 0x125b8
movl %eax, 0xc3c0(%rip)      # 0x124c0
movq 0xc4b9(%rip), %rax      # 0x125c0
movq %rax, 0xc35a(%rip)      # 0x12468
movq 0xc4b3(%rip), %rax      # 0x125c8
movq %rax, 0xc354(%rip)      # 0x12470
movq 0xc2fd(%rip), %rax      # 0x12420
movq 0xc4a6(%rip), %rcx      # 0x125d0
movq %rcx, (%rax)
movq 0xc474(%rip), %rax      # 0x125a8
movq %rax, 0xc315(%rip)      # 0x12450
movb $0x22, 0xc30a(%rip)     # 0x1244c
movb $0x0, 0xc304(%rip)      # 0x1244d
movw $0x4, 0xc2fc(%rip)      # 0x1244e
movl $0x0, -0x4(%rbp)
movq 0xc2f0(%rip), %rax      # 0x12450
movl -0x4(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzwl 0x2(%rax), %ecx
movzwl 0xc2d9(%rip), %eax      # 0x1244e
addl %ecx, %eax
movw %ax, 0xc2d0(%rip)       # 0x1244e
movq 0xc2cb(%rip), %rax      # 0x12450
movl -0x4(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x4(%rbp)
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x6159
movw $0x0, 0xc3da(%rip)      # 0x12584
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
movq 0xc3ed(%rip), %rcx      # 0x125a8
movzbl 0x7(%rcx), %ecx
cmpl %ecx, %eax
jge 0x6238
movq 0xc3de(%rip), %rax      # 0x125a8
movq 0x10(%rax), %rax
movslq -0x8(%rbp), %rcx
imulq $0x12, %rcx, %rcx
addq %rcx, %rax
movzbl 0x4(%rax), %eax
cmpl $0x4, %eax
jne 0x6228
movq 0xc3bf(%rip), %rax      # 0x125a8
movq 0x10(%rax), %rax
movslq -0x8(%rbp), %rcx
imulq $0x12, %rcx, %rcx
addq %rcx, %rax
movzwl 0x6(%rax), %eax
movzwl 0xc381(%rip), %ecx      # 0x12584
cmpl %ecx, %eax
jle 0x6228
movq 0xc39a(%rip), %rax      # 0x125a8
movq 0x10(%rax), %rax
movslq -0x8(%rbp), %rcx
imulq $0x12, %rcx, %rcx
addq %rcx, %rax
movw 0x6(%rax), %ax
movw %ax, 0xc35c(%rip)       # 0x12584
jmp 0x622a
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x61b1
movzwl 0xc345(%rip), %edi      # 0x12584
callq 0x3210
movl %eax, 0xc33e(%rip)      # 0x12588
movb $0x28, 0xc227(%rip)     # 0x12478
movb $0x0, 0xc221(%rip)      # 0x12479
movl 0xc32a(%rip), %eax      # 0x12588
shrl $0x3, %eax
movl %eax, %eax
addq $0x8, %rax
movw %ax, 0xc20c(%rip)       # 0x1247a
movw 0xc30f(%rip), %ax       # 0x12584
movw %ax, 0xc200(%rip)       # 0x1247c
movw $0x0, 0xc1f9(%rip)      # 0x1247e
movl 0xc2fd(%rip), %eax      # 0x12588
shrl $0x3, %eax
movl %eax, %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x3250
movq %rax, 0xc1dd(%rip)      # 0x12480
cmpq $0x0, 0xc1d5(%rip)      # 0x12480
jne 0x62d6
movq 0xbd44(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x6dba(%rip), %rsi      # 0xd078
leaq 0x6db7(%rip), %rdx      # 0xd07c
movb $0x0, %al
callq 0x3270
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x34c0
movl $0x400, %edi            # imm = 0x400
callq 0x3580
movq %rax, %rsi
leaq 0xc0d6(%rip), %rdi      # 0x123c0
callq 0x3190
movl 0xc293(%rip), %edi      # 0x12588
callq 0x3260
leaq 0xc0ff(%rip), %rdi      # 0x12400
leaq 0xc0c8(%rip), %rsi      # 0x123d0
leaq 0xc0b1(%rip), %rdx      # 0x123c0
leaq 0xc0ca(%rip), %rcx      # 0x123e0
callq 0x3380
movl $0x1, %edi
movl $0x8, %esi
callq 0x3250
movq %rax, -0x10(%rbp)
leaq 0xc0cb(%rip), %rdi      # 0x12400
movl $0x100, %esi            # imm = 0x100
callq 0x3530
movl %eax, -0x14(%rbp)
movq 0xc137(%rip), %rdi      # 0x12480
movl 0xc239(%rip), %eax      # 0x12588
shrl $0x3, %eax
movl %eax, %eax
addq %rax, %rdi
movl -0x14(%rbp), %eax
movl %eax, %ecx
xorl %eax, %eax
subq %rcx, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rsi
xorl %edx, %edx
movl $0x1, %ecx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
leaq 0xc07f(%rip), %rax      # 0x12400
movq %rax, (%rsp)
callq 0x3500
movq -0x10(%rbp), %rdi
callq 0x3060
movb $0x0, 0xc12a(%rip)      # 0x124c4
movb $0x0, 0xc124(%rip)      # 0x124c5
callq 0x3600
movl $0x3c, %ecx
cltd
idivl %ecx
movl %edx, %eax
addl $0x4, %eax
shll $0x2, %eax
movl %eax, 0xc230(%rip)      # 0x125ec
movl 0xc22a(%rip), %eax      # 0x125ec
addq $0x4, %rax
movw %ax, 0xc0f9(%rip)       # 0x124c6
movl 0xc219(%rip), %eax      # 0x125ec
movl %eax, %esi
movl $0x1, %edi
callq 0x3250
movq %rax, 0xc0e2(%rip)      # 0x124c8
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl 0xc1f6(%rip), %eax      # 0x125ec
jae 0x6418
callq 0x3600
movb %al, %dl
movq 0xc0c2(%rip), %rax      # 0x124c8
movslq -0x18(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x63ed
movq 0xc1b1(%rip), %rax      # 0x125d0
movq %rax, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movslq -0x38(%rbp), %rax
cmpq $0x8, %rax
jae 0x645c
callq 0x3600
movb %al, %dl
movslq -0x38(%rbp), %rax
movb %dl, -0x2c(%rbp,%rax)
movq 0xbfde(%rip), %rax      # 0x12428
movslq -0x38(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x642a
movb $0x21, -0x24(%rbp)
movb $0x20, -0x23(%rbp)
movb $0x22, -0x22(%rbp)
movb $0x20, -0x21(%rbp)
movl 0xc172(%rip), %eax      # 0x125e4
movl %eax, -0x20(%rbp)
movzwl 0xbfd2(%rip), %eax      # 0x1244e
addq $0x1c, %rax
movzwl 0xbff3(%rip), %ecx      # 0x1247a
addq %rcx, %rax
movzwl 0xc035(%rip), %ecx      # 0x124c6
addq %rcx, %rax
movl %eax, 0xc156(%rip)      # 0x125f0
movl %eax, -0x1c(%rbp)
movq 0xc0fc(%rip), %rdi      # 0x125a0
callq 0x3060
movl -0x1c(%rbp), %eax
movl %eax, %esi
movl $0x1, %edi
callq 0x3250
movq %rax, 0xc0e1(%rip)      # 0x125a0
movl $0x0, -0x3c(%rbp)
movq 0xc0d3(%rip), %rsi      # 0x125a0
movl -0x3c(%rbp), %eax
addq %rax, %rsi
leaq -0x34(%rbp), %rdi
callq 0x3490
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq 0xc0b7(%rip), %rsi      # 0x125a0
movl -0x3c(%rbp), %eax
addq %rax, %rsi
leaq 0xbf56(%rip), %rdi      # 0x1244c
callq 0x33f0
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq 0xc098(%rip), %rsi      # 0x125a0
movl -0x3c(%rbp), %eax
addq %rax, %rsi
leaq 0xbf63(%rip), %rdi      # 0x12478
callq 0x3110
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq 0xc079(%rip), %rsi      # 0x125a0
movl -0x3c(%rbp), %eax
addq %rax, %rsi
leaq 0xbf90(%rip), %rdi      # 0x124c4
callq 0x3070
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, 0xc0a8(%rip)      # 0x125f0
movl 0xc0a2(%rip), %eax      # 0x125f0
movl %eax, %esi
movl $0x1, %edi
callq 0x3250
movq %rax, 0xc097(%rip)      # 0x125f8
movq 0xc090(%rip), %rdi      # 0x125f8
movq 0xc031(%rip), %rsi      # 0x125a0
movl 0xc07b(%rip), %eax      # 0x125f0
movl %eax, %edx
callq 0x32c0
movl -0x3c(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)