// File: /workspace/github_c_makefile_star2_O0/cirocosta[P]stress/src/write.c
// Function: thread_handler
void*
thread_handler(void* arg)
{
	thread_arg_t* targ = (thread_arg_t*)arg;
	char file_buffer[CHUNK_SIZE] = { 0 };
	unsigned long writes = targ->count * _STRESS_MB(1) / CHUNK_SIZE;
	int i = writes;
	char* filename;
	FILE* fp;

	_STRESS_MUST(
	  asprintf(&filename, "%s/file%d", targ->base_dir, targ->thread_num) >
	    0,
	  "Couldn't create name for file %d",
	  i);

	_STRESS_MUST(
	  (fp = fopen(filename, "w+")), "Couldn't create file %s", filename);

	int fd = fileno(fp);

	while (1) {
		memset(file_buffer, rand() % 255, CHUNK_SIZE);
		while (i-- > 0) {
			_STRESS_MUST(
			  write(fd, file_buffer, CHUNK_SIZE) != -1,
			  "Couldn't properly write chunk to file %s (fd=%d)",
			  filename,
			  fd);
		}
		_STRESS_MUST(
		  fsync(fd) != -1,
		  "Couldn't sync filedescriptor with disk (fname=%s)",
		  filename);
		_STRESS_MUST(lseek(fd, 0, SEEK_SET) != -1,
		             "Couldn't seek to init of file %s",
		             filename);
		i = writes;
	}

	return NULL;
}

// Assembly:
subq $0x1048, %rsp           # imm = 0x1048
movq %rdi, 0x1040(%rsp)
movq 0x1040(%rsp), %rax
movq %rax, 0x1038(%rsp)
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x10b0
movq 0x1038(%rsp), %rax
movslq 0xc(%rax), %rax
shlq $0x14, %rax
shrq $0xc, %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movl %eax, 0x24(%rsp)
movq 0x1038(%rsp), %rax
movq (%rax), %rdx
movq 0x1038(%rsp), %rax
movl 0x8(%rax), %ecx
leaq 0x18(%rsp), %rdi
leaq 0x179c(%rip), %rsi      # 0x3120
movb $0x0, %al
callq 0x1110
cmpl $0x0, %eax
jg 0x1a6e
movq 0x365d(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1693(%rip), %rsi      # 0x3038
movb $0x0, %al
callq 0x10e0
movq 0x3645(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1681(%rip), %rsi      # 0x303e
movb $0x0, %al
callq 0x10e0
movq 0x362d(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movl 0x24(%rsp), %edx
leaq 0x1751(%rip), %rsi      # 0x312a
movb $0x0, %al
callq 0x10e0
movq 0x3611(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1674(%rip), %rsi      # 0x3065
movb $0x0, %al
callq 0x10e0
movq 0x35f9(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x165f(%rip), %rsi      # 0x3068
leaq 0x173b(%rip), %rdx      # 0x314b
movb $0x0, %al
callq 0x10e0
movq 0x35da(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x165c(%rip), %rsi      # 0x3084
movl $0x22, %edx
movb $0x0, %al
callq 0x10e0
movq 0x35bd(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1621(%rip), %rsi      # 0x3066
movb $0x0, %al
callq 0x10e0
movq 0x35a5(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1634(%rip), %rsi      # 0x3091
movb $0x0, %al
callq 0x10e0
movl $0x1, %edi
callq 0x1170
jmp 0x1a70
jmp 0x1a72
movq 0x18(%rsp), %rdi
leaq 0x16d9(%rip), %rsi      # 0x3157
callq 0x1140
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
jne 0x1b6d
movq 0x355f(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1595(%rip), %rsi      # 0x3038
movb $0x0, %al
callq 0x10e0
movq 0x3547(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1583(%rip), %rsi      # 0x303e
movb $0x0, %al
callq 0x10e0
movq 0x352f(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movq 0x18(%rsp), %rdx
leaq 0x1682(%rip), %rsi      # 0x315a
movb $0x0, %al
callq 0x10e0
movq 0x3512(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1575(%rip), %rsi      # 0x3065
movb $0x0, %al
callq 0x10e0
movq 0x34fa(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1560(%rip), %rsi      # 0x3068
leaq 0x163c(%rip), %rdx      # 0x314b
movb $0x0, %al
callq 0x10e0
movq 0x34db(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x155d(%rip), %rsi      # 0x3084
movl $0x25, %edx
movb $0x0, %al
callq 0x10e0
movq 0x34be(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1522(%rip), %rsi      # 0x3066
movb $0x0, %al
callq 0x10e0
movq 0x34a6(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1535(%rip), %rsi      # 0x3091
movb $0x0, %al
callq 0x10e0
movl $0x1, %edi
callq 0x1170
jmp 0x1b6f
movq 0x10(%rsp), %rdi
callq 0x1100
movl %eax, 0xc(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, (%rsp)
callq 0x11a0
movq (%rsp), %rdi
movl $0xff, %ecx
cltd
idivl %ecx
movb %dl, %al
movl $0x1000, %edx           # imm = 0x1000
movzbl %al, %esi
callq 0x10b0
movl 0x24(%rsp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, 0x24(%rsp)
cmpl $0x0, %eax
jle 0x1cc1
jmp 0x1bbe
movl 0xc(%rsp), %edi
leaq 0x30(%rsp), %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x1060
cmpq $-0x1, %rax
jne 0x1cba
movq 0x3416(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x144c(%rip), %rsi      # 0x3038
movb $0x0, %al
callq 0x10e0
movq 0x33fe(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x143a(%rip), %rsi      # 0x303e
movb $0x0, %al
callq 0x10e0
movq 0x33e6(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movq 0x18(%rsp), %rdx
movl 0xc(%rsp), %ecx
leaq 0x154d(%rip), %rsi      # 0x3172
movb $0x0, %al
callq 0x10e0
movq 0x33c5(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1428(%rip), %rsi      # 0x3065
movb $0x0, %al
callq 0x10e0
movq 0x33ad(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1413(%rip), %rsi      # 0x3068
leaq 0x14ef(%rip), %rdx      # 0x314b
movb $0x0, %al
callq 0x10e0
movq 0x338e(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1410(%rip), %rsi      # 0x3084
movl $0x30, %edx
movb $0x0, %al
callq 0x10e0
movq 0x3371(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x13d5(%rip), %rsi      # 0x3066
movb $0x0, %al
callq 0x10e0
movq 0x3359(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x13e8(%rip), %rsi      # 0x3091
movb $0x0, %al
callq 0x10e0
movl $0x1, %edi
callq 0x1170
jmp 0x1cbc
jmp 0x1ba6
jmp 0x1cc3
movl 0xc(%rsp), %edi
callq 0x1130
cmpl $-0x1, %eax
jne 0x1db0
movq 0x331c(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1352(%rip), %rsi      # 0x3038
movb $0x0, %al
callq 0x10e0
movq 0x3304(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1340(%rip), %rsi      # 0x303e
movb $0x0, %al
callq 0x10e0
movq 0x32ec(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movq 0x18(%rsp), %rdx
leaq 0x1488(%rip), %rsi      # 0x31a3
movb $0x0, %al
callq 0x10e0
movq 0x32cf(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1332(%rip), %rsi      # 0x3065
movb $0x0, %al
callq 0x10e0
movq 0x32b7(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x131d(%rip), %rsi      # 0x3068
leaq 0x13f9(%rip), %rdx      # 0x314b
movb $0x0, %al
callq 0x10e0
movq 0x3298(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x131a(%rip), %rsi      # 0x3084
movl $0x35, %edx
movb $0x0, %al
callq 0x10e0
movq 0x327b(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x12df(%rip), %rsi      # 0x3066
movb $0x0, %al
callq 0x10e0
movq 0x3263(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x12f2(%rip), %rsi      # 0x3091
movb $0x0, %al
callq 0x10e0
movl $0x1, %edi
callq 0x1170
jmp 0x1db2
jmp 0x1db4
movl 0xc(%rsp), %edi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x10a0
cmpq $-0x1, %rax
jne 0x1ea8
movq 0x3224(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x125a(%rip), %rsi      # 0x3038
movb $0x0, %al
callq 0x10e0
movq 0x320c(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1248(%rip), %rsi      # 0x303e
movb $0x0, %al
callq 0x10e0
movq 0x31f4(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movq 0x18(%rsp), %rdx
leaq 0x13c2(%rip), %rsi      # 0x31d5
movb $0x0, %al
callq 0x10e0
movq 0x31d7(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x123a(%rip), %rsi      # 0x3065
movb $0x0, %al
callq 0x10e0
movq 0x31bf(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1225(%rip), %rsi      # 0x3068
leaq 0x1301(%rip), %rdx      # 0x314b
movb $0x0, %al
callq 0x10e0
movq 0x31a0(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1222(%rip), %rsi      # 0x3084
movl $0x38, %edx
movb $0x0, %al
callq 0x10e0
movq 0x3183(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x11e7(%rip), %rsi      # 0x3066
movb $0x0, %al
callq 0x10e0
movq 0x316b(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x11fa(%rip), %rsi      # 0x3091
movb $0x0, %al
callq 0x10e0
movl $0x1, %edi
callq 0x1170
jmp 0x1eaa
movq 0x28(%rsp), %rax
movl %eax, 0x24(%rsp)
jmp 0x1b7d
nopl (%rax,%rax)