// File: /workspace/github_c_makefile_star2_O0/darwin-on-arm[P]darwin-sdk/image3maker/image3maker.c
// Function: create_image
static void create_image(void)
{
    printf("Creating image of type \'%s\' (0x%08x)...\n", imageTag, image3core.imageType);
    
    assert((image3core.rootHeader = malloc(sizeof(Image3RootHeader))));
    
    image3core.rootHeader->header.magic = kImage3Magic;
    image3core.rootHeader->shshExtension.imageType = image3core.imageType;
    
    image3core.rootHeader->header.dataSize = image3core.rootHeader->header.size =
        image3core.rootHeader->shshExtension.shshOffset = 0;
    
    image3core.rootHeader->header.size = sizeof(Image3RootHeader);
    
    /* DATA/TYPE tags */
    uint32_t* type;
    void* data;
    
    type = image3_reserve_type(kImage3TagType, sizeof(uint32_t));
    *type = image3core.imageType;
    
    data = image3_reserve_data(kImage3TagData, image3core.backingDataSize);
    memcpy(data, image3core.backingData, image3core.backingDataSize);
    
    /* Other tags */
    if(imageVersion) {
        printf("Image Version:    %s\n", imageVersion);

        void* version;
        uint32_t *length;
        version = image3_reserve_version(kImage3TagVersion, (uint32_t)strlen(imageVersion) + 4);
        length = (uint32_t*)version;
        *(length) = (uint32_t)strlen(imageVersion);
        strncpy((char*)version + sizeof(uint32_t), imageVersion, strlen(imageVersion));
    }
    
    if(imageSecurityEpoch) {
        printf("Security Epoch:    0x%08x\n", image3core.imageSecurityEpoch);
        
        uint32_t *epoch = image3_reserve_tag(kImage3TagSecurityEpoch, sizeof(uint32_t));
        *epoch = image3core.imageSecurityEpoch;
    }
    
    
    if(hardwareEpoch) {
        printf("Chip Epoch:       0x%08x\n", image3core.imageHardwareEpoch);
        
        uint32_t *epoch = image3_reserve_tag(kImage3TagChipEpoch, sizeof(uint32_t));
        *epoch = image3core.imageHardwareEpoch;
    }
    
    if(imageDomain) {
        printf("Security Domain:  0x%08x\n", image3core.imageDomain);

        uint32_t *securityDomain = image3_reserve_tag(kImage3TagSecurityDomain, sizeof(uint32_t));
        *securityDomain = image3core.imageDomain;
    }
    
    if(imageProduction) {
        printf("Production Type:  0x%08x\n", image3core.imageProductionType);
        
        uint32_t *imageProd = image3_reserve_tag(kImage3TagProduct, sizeof(uint32_t));
        *imageProd = image3core.imageProductionType;
    }
    
    if(chipType) {
        printf("Chip Type:        0x%08x\n", image3core.imageChipType);
        
        uint32_t *chip = image3_reserve_tag(kImage3TagChip, sizeof(uint32_t));
        *chip = image3core.imageChipType;
    }
    
    if(boardType) {
        printf("Board Type:       0x%08x\n", image3core.imageBoardType);
        
        uint32_t *board = image3_reserve_tag(kImage3TagBoard, sizeof(uint32_t));
        *board = image3core.imageBoardType;
    }
    
    if(uniqueIdentifier) {
        printf("ECID:             0x%016llx\n", image3core.imageUniqueIdentifier);
        
        uint64_t *ecid = image3_reserve_ecid(kImage3TagECID, sizeof(uint64_t));
        *ecid = image3core.imageUniqueIdentifier;
    }
    
    /* AES stuff... TODO */
    printf("Total Size:       %d bytes\n", image3core.rootHeader->header.size);
    printf("Data Size:        %d bytes\n", image3core.rootHeader->header.dataSize);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x49c9(%rip), %rsi      # 0x6338
movl 0x4967(%rip), %edx      # 0x62dc
leaq 0x1f90(%rip), %rdi      # 0x390c
movb $0x0, %al
callq 0x1090
movl $0x14, %edi
callq 0x10f0
movq %rax, 0x4924(%rip)      # 0x62b8
cmpq $0x0, %rax
je 0x199c
jmp 0x19bb
leaq 0x1f92(%rip), %rdi      # 0x3935
leaq 0x1d5e(%rip), %rsi      # 0x3708
movl $0x175, %edx            # imm = 0x175
leaq 0x1fba(%rip), %rcx      # 0x3970
callq 0x10a0
movq 0x48f6(%rip), %rax      # 0x62b8
movl $0x496d6733, (%rax)     # imm = 0x496D6733
movl 0x490e(%rip), %ecx      # 0x62dc
movq 0x48e3(%rip), %rax      # 0x62b8
movl %ecx, 0x10(%rax)
movq 0x48d9(%rip), %rax      # 0x62b8
movl $0x0, 0xc(%rax)
movq 0x48cb(%rip), %rax      # 0x62b8
movl $0x0, 0x4(%rax)
movq 0x48bd(%rip), %rax      # 0x62b8
movl $0x0, 0x8(%rax)
movq 0x48af(%rip), %rax      # 0x62b8
movl $0x14, 0x4(%rax)
movl $0x54595045, %edi       # imm = 0x54595045
movl $0x4, %esi
callq 0x2020
movq %rax, -0x8(%rbp)
movl 0x48b3(%rip), %ecx      # 0x62dc
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
movl 0x4893(%rip), %esi      # 0x62c8
movl $0x44415441, %edi       # imm = 0x44415441
callq 0x20f0
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq 0x4872(%rip), %rsi      # 0x62c0
movslq 0x4873(%rip), %rdx      # 0x62c8
callq 0x10e0
cmpq $0x0, 0x48de(%rip)      # 0x6340
je 0x1aeb
movq 0x48d1(%rip), %rsi      # 0x6340
leaq 0x1f12(%rip), %rdi      # 0x3988
movb $0x0, %al
callq 0x1090
movq 0x48bc(%rip), %rdi      # 0x6340
callq 0x1070
movl %eax, %esi
addl $0x4, %esi
movl $0x56455253, %edi       # imm = 0x56455253
callq 0x2220
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq 0x4895(%rip), %rdi      # 0x6340
callq 0x1070
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x68(%rbp)
movq 0x4875(%rip), %rax      # 0x6340
movq %rax, -0x60(%rbp)
movq 0x486a(%rip), %rdi      # 0x6340
callq 0x1070
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq %rax, %rdx
callq 0x1040
cmpq $0x0, 0x4825(%rip)      # 0x6318
je 0x1b28
movl 0x47ed(%rip), %esi      # 0x62e8
leaq 0x1e9c(%rip), %rdi      # 0x399e
movb $0x0, %al
callq 0x1090
movl $0x5345504f, %edi       # imm = 0x5345504F
movl $0x4, %esi
callq 0x2360
movq %rax, -0x28(%rbp)
movl 0x47c6(%rip), %ecx      # 0x62e8
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, 0x4828(%rip)      # 0x6358
je 0x1b65
movl 0x47bc(%rip), %esi      # 0x62f4
leaq 0x1e7a(%rip), %rdi      # 0x39b9
movb $0x0, %al
callq 0x1090
movl $0x4345504f, %edi       # imm = 0x4345504F
movl $0x4, %esi
callq 0x2360
movq %rax, -0x30(%rbp)
movl 0x4795(%rip), %ecx      # 0x62f4
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, 0x47db(%rip)      # 0x6348
je 0x1ba2
movl 0x4777(%rip), %esi      # 0x62ec
leaq 0x1e57(%rip), %rdi      # 0x39d3
movb $0x0, %al
callq 0x1090
movl $0x53444f4d, %edi       # imm = 0x53444F4D
movl $0x4, %esi
callq 0x2360
movq %rax, -0x38(%rbp)
movl 0x4750(%rip), %ecx      # 0x62ec
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, 0x47a6(%rip)      # 0x6350
je 0x1bdf
movl 0x473e(%rip), %esi      # 0x62f0
leaq 0x1e34(%rip), %rdi      # 0x39ed
movb $0x0, %al
callq 0x1090
movl $0x50524f44, %edi       # imm = 0x50524F44
movl $0x4, %esi
callq 0x2360
movq %rax, -0x40(%rbp)
movl 0x4717(%rip), %ecx      # 0x62f0
movq -0x40(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, 0x4779(%rip)      # 0x6360
je 0x1c1c
movl 0x4709(%rip), %esi      # 0x62f8
leaq 0x1e11(%rip), %rdi      # 0x3a07
movb $0x0, %al
callq 0x1090
movl $0x43484950, %edi       # imm = 0x43484950
movl $0x4, %esi
callq 0x2360
movq %rax, -0x48(%rbp)
movl 0x46e2(%rip), %ecx      # 0x62f8
movq -0x48(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, 0x4744(%rip)      # 0x6368
je 0x1c59
movl 0x46d0(%rip), %esi      # 0x62fc
leaq 0x1dee(%rip), %rdi      # 0x3a21
movb $0x0, %al
callq 0x1090
movl $0x424f5244, %edi       # imm = 0x424F5244
movl $0x4, %esi
callq 0x2360
movq %rax, -0x50(%rbp)
movl 0x46a9(%rip), %ecx      # 0x62fc
movq -0x50(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, 0x470f(%rip)      # 0x6370
je 0x1c99
movq 0x4696(%rip), %rsi      # 0x6300
leaq 0x1dca(%rip), %rdi      # 0x3a3b
movb $0x0, %al
callq 0x1090
movl $0x45434944, %edi       # imm = 0x45434944
movl $0x8, %esi
callq 0x2440
movq %rax, -0x58(%rbp)
movq 0x466e(%rip), %rcx      # 0x6300
movq -0x58(%rbp), %rax
movq %rcx, (%rax)
movq 0x4618(%rip), %rax      # 0x62b8
movl 0x4(%rax), %esi
leaq 0x1dae(%rip), %rdi      # 0x3a58
movb $0x0, %al
callq 0x1090
movq 0x4600(%rip), %rax      # 0x62b8
movl 0x8(%rax), %esi
leaq 0x1db2(%rip), %rdi      # 0x3a74
movb $0x0, %al
callq 0x1090
addq $0x70, %rsp
popq %rbp
retq
nop