// File: /workspace/github_c_makefile_star2_O0/albinoloverats[P]hide/src/tiff.c
// Function: write_tiff
static int write_tiff(image_info_t image_info, void (*progress_update)(uint64_t, uint64_t))
{
	errno = EXIT_SUCCESS;

	TIFF *tif = TIFFOpen(image_info.file, "w");
	if (!tif)
		return errno;

	TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, image_info.width);
	TIFFSetField(tif, TIFFTAG_IMAGELENGTH, image_info.height);
	TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, image_info.bpp);
	TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_LZW);

	TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
	TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_CENTIMETER);
	TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
	TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
	TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);

	TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif, image_info.width * image_info.bpp));

	for (uint64_t y = 0; y < image_info.height; y++)
	{
		TIFFWriteScanline(tif, image_info.buffer[y], y, 0);
		free(image_info.buffer[y]);
		if (progress_update)
			progress_update(y, image_info.height);
	}
	free(image_info.buffer);

	TIFFClose(tif);

	return errno;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
leaq 0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq %rdi, -0x10(%rbp)
callq 0x1040
movq %rax, %rcx
movq -0x28(%rbp), %rax
movl $0x0, (%rcx)
movq (%rax), %rdi
leaq 0xbe7(%rip), %rsi       # 0x2007
callq 0x1050
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x143f
callq 0x1040
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x15cf
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rdi
movq 0x30(%rax), %rdx
movl $0x100, %esi            # imm = 0x100
movb $0x0, %al
callq 0x1080
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rdi
movq 0x28(%rax), %rdx
movl $0x101, %esi            # imm = 0x101
movb $0x0, %al
callq 0x1080
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rdi
movzwl 0x38(%rax), %edx
movl $0x115, %esi            # imm = 0x115
movb $0x0, %al
callq 0x1080
movq -0x18(%rbp), %rdi
movl $0x103, %esi            # imm = 0x103
movl $0x5, %edx
movb $0x0, %al
callq 0x1080
movq -0x18(%rbp), %rdi
movl $0x102, %esi            # imm = 0x102
movl $0x8, %edx
movb $0x0, %al
callq 0x1080
movq -0x18(%rbp), %rdi
movl $0x128, %esi            # imm = 0x128
movl $0x3, %edx
movb $0x0, %al
callq 0x1080
movq -0x18(%rbp), %rdi
movl $0x112, %esi            # imm = 0x112
movl $0x1, %edx
movb $0x0, %al
callq 0x1080
movq -0x18(%rbp), %rdi
movl $0x11c, %esi            # imm = 0x11C
movl $0x1, %edx
movb $0x0, %al
callq 0x1080
movq -0x18(%rbp), %rdi
movl $0x106, %esi            # imm = 0x106
movl $0x2, %edx
movb $0x0, %al
callq 0x1080
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
movq 0x30(%rcx), %rax
movzwl 0x38(%rcx), %ecx
imulq %rcx, %rax
movl %eax, %esi
callq 0x1060
movq -0x30(%rbp), %rdi
movl %eax, %edx
movl $0x116, %esi            # imm = 0x116
movb $0x0, %al
callq 0x1080
movq $0x0, -0x20(%rbp)
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
cmpq 0x28(%rcx), %rax
jae 0x15af
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rdi
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x20(%rbp), %rax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x10c0
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1030
cmpq $0x0, -0x10(%rbp)
je 0x159f
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rdi
movq 0x28(%rcx), %rsi
callq *%rax
jmp 0x15a1
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x1542
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x1030
movq -0x18(%rbp), %rdi
callq 0x10d0
callq 0x1040
movl (%rax), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)