// File: /workspace/github_c_makefile_star2_O3/albertito[P]libjio/libjio/journal.c
// Function: journal_new
struct journal_op *journal_new(struct jfs *fs, unsigned int flags)
{
	int fd, id;
	ssize_t rv;
	char *name = NULL;
	struct journal_op *jop = NULL;
	struct on_disk_hdr hdr;
	struct iovec iov[1];

	if (is_broken(fs))
		goto error;

	jop = malloc(sizeof(struct journal_op));
	if (jop == NULL)
		goto error;

	name = (char *) malloc(PATH_MAX);
	if (name == NULL)
		goto error;

	id = get_tid(fs);
	if (id == 0)
		goto error;

	/* open the transaction file */
	get_jtfile(fs, id, name);
	fd = open(name, O_RDWR | O_CREAT | O_TRUNC, 0600);
	if (fd < 0)
		goto error;

	if (plockf(fd, F_LOCKW, 0, 0) != 0)
		goto unlink_error;

	jop->id = id;
	jop->fd = fd;
	jop->numops = 0;
	jop->name = name;
	jop->csum = 0;
	jop->fs = fs;

	fiu_exit_on("jio/commit/created_tf");

	/* save the header */
	hdr.ver = 1;
	hdr.trans_id = id;
	hdr.flags = flags;
	hdr_hton(&hdr);

	iov[0].iov_base = (void *) &hdr;
	iov[0].iov_len = sizeof(hdr);
	rv = swritev(fd, iov, 1);
	if (rv != sizeof(hdr))
		goto unlink_error;

	jop->csum = checksum_buf(jop->csum, (unsigned char *) &hdr,
			sizeof(hdr));

	fiu_exit_on("jio/commit/tf_header");

	return jop;

unlink_error:
	unlink(name);
	free_tid(fs, id);
	close(fd);

error:
	free(name);
	free(jop);

	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1018, %rsp           # imm = 0x1018
movl %esi, %ebp
movq %rdi, %r15
movq 0x10(%rdi), %rcx
leaq 0x1519(%rip), %rdx      # 0x543e
xorl %r14d, %r14d
leaq 0x10(%rsp), %rbx
movl $0x1000, %esi           # imm = 0x1000
movq %rbx, %rdi
xorl %eax, %eax
callq 0x21b0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x24c0
testl %eax, %eax
je 0x3fa3
movl $0x28, %edi
callq 0x2390
testq %rax, %rax
je 0x3fa0
movq %rax, %rbx
movl $0x1000, %edi           # imm = 0x1000
callq 0x2390
testq %rax, %rax
je 0x3fcc
movq %rax, %r14
movl 0x1c(%r15), %edi
movl $0x110, %esi            # imm = 0x110
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2480
movq 0x20(%r15), %rax
movl (%rax), %r12d
incl %r12d
jne 0x3fd1
movl 0x1c(%r15), %edi
movl $0x10000, %esi          # imm = 0x10000
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2480
jmp 0x3fa5
xorl %r14d, %r14d
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x2040
movq %rbx, %rdi
callq 0x2040
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
jmp 0x3fa5
movl %r12d, (%rax)
movl 0x1c(%r15), %edi
movl $0x10000, %esi          # imm = 0x10000
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2480
movq %r15, %rdi
movl %r12d, %esi
movq %r14, %rdx
callq 0x22c0
movq %r14, %rdi
movl $0x242, %esi            # imm = 0x242
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0x24b0
testl %eax, %eax
js 0x3fa5
movl %eax, %r13d
movl %eax, %edi
movl $0x110, %esi            # imm = 0x110
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2480
testq %rax, %rax
jne 0x4091
movl %r12d, (%rbx)
movl %r13d, 0x4(%rbx)
xorl %eax, %eax
movl %eax, 0x8(%rbx)
movq %r14, 0x10(%rbx)
movl %eax, 0x18(%rbx)
movq %r15, 0x20(%rbx)
leaq 0x8(%rsp), %rax
rolw $0x8, %bp
movw $0x100, (%rax)          # imm = 0x100
movw %bp, 0x2(%rax)
movl %r12d, %ecx
bswapl %ecx
movl %ecx, 0x4(%rax)
leaq 0x10(%rsp), %rsi
movq %rax, (%rsi)
movq $0x8, 0x8(%rsi)
movl %r13d, %edi
movl $0x1, %edx
callq 0x2420
cmpq $0x8, %rax
jne 0x4091
leaq 0x8(%rsp), %rsi
movl $0x8, %edx
xorl %edi, %edi
callq 0x2230
movl %eax, 0x18(%rbx)
jmp 0x3fb7
movq %r14, %rdi
callq 0x2090
movq %r15, %rdi
movl %r12d, %esi
callq 0x40b1
movl %r13d, %edi
callq 0x2220
jmp 0x3fa5