// File: /workspace/github_c_makefile_star2_O0/dasJ[P]sd-zfs/src/zfs-generator.c
// Function: generateCacheUnit
int generateCacheUnit(char *directory, const char *targetName, const char *unitName, char *forceParam, char *poolName) {
	char *unitpath;
	char *targetpath;
	FILE *fp;

	// Build paths
	targetpath = malloc((strlen(directory) + strlen(targetName) + strlen(unitName) + 3) * sizeof(char));
	strcpy(targetpath, directory);
	strcat(targetpath, "/");
	strcat(targetpath, targetName);
	unitpath = malloc((strlen(directory) + strlen(unitName) + 2) * sizeof(char));
	strcpy(unitpath, directory);
	strcat(unitpath, "/");
	strcat(unitpath, unitName);
	// Make wants directory
	if (mkdir(targetpath, 0775) < 0 && errno != EEXIST) {
		perror("Can not create unit directory\n");
		free(targetpath);
		free(unitpath);
		return(1);
	}
	// Make symlink
	strcat(targetpath, "/");
	strcat(targetpath, unitName);
	symlink(unitName, targetpath);
	// Check if unit already exists
	if (access(unitpath, R_OK) != -1) {
		free(unitpath);
		free(targetpath);
		printf("Caching unit file already exists\n");
		return 0;
	}
	// Write
	fp = fopen(unitpath, "w");
	if (fp == NULL) {
		perror("Cannot write to scanning unit file\n");
		free(unitpath);
		free(targetpath);
		return 1;
	}
	fprintf(fp, "# This file was generated by sd-zfs\n\
[Unit]\n\
Description=Import ZFS pools by cache file\n\
DefaultDependencies=no\n\
Requires=systemd-udev-settle.service\n\
After=systemd-udev-settle.service\n\
After=cryptsetup.target\n\
Before=sysroot.mount\n\
ConditionPathExists=/etc/zfs/zpool.cache\n\
\n\
[Service]\n\
Type=oneshot\n\
RemainAfterExit=yes\n\
ExecStart=/usr/bin/zpool import %s -N -c /etc/zfs/zpool.cache%s\n", poolName, forceParam);
	fclose(fp);
	free(unitpath);
	free(targetpath);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4010d8
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4010d8
movq %rax, %rcx
movq -0x60(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rdi
callq 0x4010d8
movq -0x58(%rbp), %rdi
addq %rax, %rdi
addq $0x3, %rdi
shlq $0x0, %rdi
callq 0x421010
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x401020
movq -0x40(%rbp), %rdi
leaq 0xa2be3(%rip), %rsi     # 0x4a48fc
callq 0x401058
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x401058
movq -0x10(%rbp), %rdi
callq 0x4010d8
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rdi
callq 0x4010d8
movq -0x50(%rbp), %rdi
addq %rax, %rdi
addq $0x2, %rdi
shlq $0x0, %rdi
callq 0x421010
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x401020
movq -0x38(%rbp), %rdi
leaq 0xa2b8b(%rip), %rsi     # 0x4a48fc
callq 0x401058
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x401058
movq -0x40(%rbp), %rdi
movl $0x1fd, %esi            # imm = 0x1FD
callq 0x455450
cmpl $0x0, %eax
jge 0x401dca
callq 0x405460
cmpl $0x11, (%rax)
je 0x401dca
leaq 0x9b3ff(%rip), %rdi     # 0x49d1a6
callq 0x40ca90
movq -0x40(%rbp), %rdi
callq 0x421350
movq -0x38(%rbp), %rdi
callq 0x421350
movl $0x1, -0x4(%rbp)
jmp 0x401eae
movq -0x40(%rbp), %rdi
leaq 0xa2b27(%rip), %rsi     # 0x4a48fc
callq 0x401058
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x401058
movq -0x20(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x456030
movq -0x38(%rbp), %rdi
movl $0x4, %esi
callq 0x455720
cmpl $-0x1, %eax
je 0x401e30
movq -0x38(%rbp), %rdi
callq 0x421350
movq -0x40(%rbp), %rdi
callq 0x421350
leaq 0x9b57d(%rip), %rdi     # 0x49d39d
movb $0x0, %al
callq 0x40c860
movl $0x0, -0x4(%rbp)
jmp 0x401eae
movq -0x38(%rbp), %rdi
leaq 0x9b241(%rip), %rsi     # 0x49d07c
callq 0x413660
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x401e72
leaq 0x9b56d(%rip), %rdi     # 0x49d3bf
callq 0x40ca90
movq -0x38(%rbp), %rdi
callq 0x421350
movq -0x40(%rbp), %rdi
callq 0x421350
movl $0x1, -0x4(%rbp)
jmp 0x401eae
movq -0x48(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x28(%rbp), %rcx
leaq 0x9b55e(%rip), %rsi     # 0x49d3e3
movb $0x0, %al
callq 0x40c7a0
movq -0x48(%rbp), %rdi
callq 0x412f30
movq -0x38(%rbp), %rdi
callq 0x421350
movq -0x40(%rbp), %rdi
callq 0x421350
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)