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

        if (argc > 1)
		size = atoi(argv[1]);
	if (size <= 1) {
                fprintf(stderr, "invalid size, must be greater than 1\n");
                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 */
		ret = fgetc(stdin);
		if (ret == EOF) {
			if (ferror(stdin)) {
				fprintf(stderr, "error in reading\n");
				return -1;
			}
			break;
		}
		c = (char) ret;

		/* Write data to output file */
		ret = fputc(c, 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 $0x20, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x2000, -0x18(%rbp)    # imm = 0x2000
cmpl $0x1, -0x8(%rbp)
jle 0x11d7
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x1090
cltq
movq %rax, -0x18(%rbp)
cmpq $0x1, -0x18(%rbp)
ja 0x1202
movq 0x2e13(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xe15(%rip), %rsi       # 0x2004
movb $0x0, %al
callq 0x1060
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1380
movq 0x2def(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0xe13(%rip), %rsi       # 0x202a
movb $0x0, %al
callq 0x1060
movq 0x2db3(%rip), %rax      # 0x3fd8
movq (%rax), %rdi
movq -0x18(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1080
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x1264
movq 0x2db1(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xdf1(%rip), %rsi       # 0x2042
movb $0x0, %al
callq 0x1060
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1380
movq 0x2d65(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
movq -0x18(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1080
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x12aa
movq 0x2d6b(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xdc4(%rip), %rsi       # 0x205b
movb $0x0, %al
callq 0x1060
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1380
jmp 0x12ac
movq 0x2d25(%rip), %rax      # 0x3fd8
movq (%rax), %rdi
callq 0x1070
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x12cc
jmp 0x1379
movq 0x2d05(%rip), %rax      # 0x3fd8
movq (%rax), %rdi
callq 0x1040
movl %eax, -0x20(%rbp)
cmpl $-0x1, -0x20(%rbp)
jne 0x131b
movq 0x2ced(%rip), %rax      # 0x3fd8
movq (%rax), %rdi
callq 0x1030
cmpl $0x0, %eax
je 0x1319
movq 0x2cf9(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xd6c(%rip), %rsi       # 0x2075
movb $0x0, %al
callq 0x1060
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1380
jmp 0x1379
movl -0x20(%rbp), %eax
movb %al, -0x19(%rbp)
movsbl -0x19(%rbp), %edi
movq 0x2ca4(%rip), %rax      # 0x3fd0
movq (%rax), %rsi
callq 0x1050
movl %eax, -0x20(%rbp)
cmpl $-0x1, -0x20(%rbp)
jne 0x1374
movq 0x2c8c(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
callq 0x1030
cmpl $0x0, %eax
je 0x1372
movq 0x2ca0(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xd25(%rip), %rsi       # 0x2087
movb $0x0, %al
callq 0x1060
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1380
jmp 0x1379
jmp 0x12ac
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq