// File: /workspace/github_c_makefile_star2_O0/giometti[P]mastering_UNIX_programming/chapter_07/fgets.c
// Function: main
int main(int argc, char *argv[])
{
	size_t size = BUFSIZ;
	char buf[MAX_SIZE];
	char *ptr;
	int ret;

        if (argc > 1)
		size = atoi(argv[1]);
	if ((size <= 1) || (size > MAX_SIZE)) {
                fprintf(stderr, "invalid size, must be in [2,%d]\n",
			MAX_SIZE);
                return -1;
	}
	fprintf(stderr, "set buffer size to %ld\n", size);

	ret = setvbuf(stdin, NULL, _IOFBF, size);
	if (ret) {
		fprintf(stderr, "setvbuf error for stdin\n");
		return -1;
	}
	ret = setvbuf(stdout, NULL, _IOFBF, size);
	if (ret) {
		fprintf(stderr, "setvbuf error for stdout\n");
		return -1;
	}

	while (!feof(stdin)) {
		/* Read data from input file */
		ptr = fgets(buf, size, stdin);
		if (ptr == NULL) {
			if (ferror(stdin)) {
				fprintf(stderr, "error in reading\n");
				return -1;
			}
			break;
		}

		/* Write data to output file */
		ret = fputs(buf, stdout);
		if (ret == EOF) {
			if (ferror(stdout)) {
				fprintf(stderr, "error in writing\n");
				return -1;
			}
			break;
		}
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40030, %rsp          # imm = 0x40030
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x2000, -0x18(%rbp)    # imm = 0x2000
cmpl $0x1, -0x8(%rbp)
jle 0x11da
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x1090
cltq
movq %rax, -0x18(%rbp)
cmpq $0x1, -0x18(%rbp)
jbe 0x11eb
cmpq $0x40000, -0x18(%rbp)   # imm = 0x40000
jbe 0x1214
movq 0x2e06(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xe08(%rip), %rsi       # 0x2004
movl $0x40000, %edx          # imm = 0x40000
movb $0x0, %al
callq 0x1060
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x13b6
movq 0x2ddd(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0xdfc(%rip), %rsi       # 0x2025
movb $0x0, %al
callq 0x1060
movq 0x2da1(%rip), %rax      # 0x3fd8
movq (%rax), %rdi
movq -0x18(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1080
movl %eax, -0x4002c(%rbp)
cmpl $0x0, -0x4002c(%rbp)
je 0x127c
movq 0x2d99(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xdd4(%rip), %rsi       # 0x203d
movb $0x0, %al
callq 0x1060
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x13b6
movq 0x2d4d(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
movq -0x18(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1080
movl %eax, -0x4002c(%rbp)
cmpl $0x0, -0x4002c(%rbp)
je 0x12c8
movq 0x2d4d(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xda1(%rip), %rsi       # 0x2056
movb $0x0, %al
callq 0x1060
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x13b6
jmp 0x12ca
movq 0x2d07(%rip), %rax      # 0x3fd8
movq (%rax), %rdi
callq 0x1070
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x12ea
jmp 0x13af
leaq -0x40020(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %esi
movq 0x2cda(%rip), %rax      # 0x3fd8
movq (%rax), %rdx
callq 0x1050
movq %rax, -0x40028(%rbp)
cmpq $0x0, -0x40028(%rbp)
jne 0x134e
movq 0x2cba(%rip), %rax      # 0x3fd8
movq (%rax), %rdi
callq 0x1030
cmpl $0x0, %eax
je 0x134c
movq 0x2cc6(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xd34(%rip), %rsi       # 0x2070
movb $0x0, %al
callq 0x1060
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x13b6
jmp 0x13af
leaq -0x40020(%rbp), %rdi
movq 0x2c74(%rip), %rax      # 0x3fd0
movq (%rax), %rsi
callq 0x1040
movl %eax, -0x4002c(%rbp)
cmpl $-0x1, -0x4002c(%rbp)
jne 0x13aa
movq 0x2c56(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
callq 0x1030
cmpl $0x0, %eax
je 0x13a8
movq 0x2c6a(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xcea(%rip), %rsi       # 0x2082
movb $0x0, %al
callq 0x1060
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x13b6
jmp 0x13af
jmp 0x12ca
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40030, %rsp          # imm = 0x40030
popq %rbp
retq