// File: /workspace/github_c_makefile_star2_O1/giometti[P]mastering_UNIX_programming/chapter_04/stat.c
// Function: main
int main(int argc, char *argv[])
{
	struct stat buf;
	int ret;

	if (argc < 2) {
		fprintf(stderr, "usage: %s <file>\n", argv[0]);
		return -1;
	}

	ret = lstat(argv[1], &buf);
	if (ret < 0) {
		perror("lstat");
		return -1;
	}

	printf("File name:                %s\n", argv[1]);

#ifdef major
        printf("ID of containing device:  [%lx,%lx]\n",
		(long) major(buf.st_dev), (long) minor(buf.st_dev));
#endif

	printf("File type:                ");
        switch (buf.st_mode & S_IFMT) {
        case S_IFBLK:  printf("block device\n");            break;
        case S_IFCHR:  printf("character device\n");        break;
        case S_IFDIR:  printf("directory\n");               break;
        case S_IFIFO:  printf("FIFO/pipe\n");               break;
        case S_IFLNK:  printf("symlink\n");                 break;
        case S_IFREG:  printf("regular file\n");            break;
        case S_IFSOCK: printf("socket\n");                  break;
        default:       printf("unknown?\n");
        }

#ifdef major
	if (S_ISCHR(buf.st_mode) || S_ISBLK(buf.st_mode))
		printf("special file major/minor: [%lu,%lu]\n",
			(long) major(buf.st_rdev),
			(long) minor(buf.st_rdev));
#endif

        printf("I-node number:            %ld\n", (long) buf.st_ino);
        printf("Mode:                     %lo (octal)\n",
					(unsigned long) buf.st_mode);
        printf("Link count:               %ld\n", (long) buf.st_nlink);
        printf("Ownership:                UID=%ld GID=%ld\n",
		(long) buf.st_uid, (long) buf.st_gid);
	printf("Preferred I/O block size: %ld bytes\n",
					(long) buf.st_blksize);
	printf("File size:                %lld bytes\n",
					(long long) buf.st_size);
	printf("Blocks allocated:         %lld\n",
					(long long) buf.st_blocks);

	printf("Last status change:       %s", ctime(&buf.st_ctime));
	printf("Last file access:         %s", ctime(&buf.st_atime));
	printf("Last file modification:   %s", ctime(&buf.st_mtime));

	return 0;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x98, %rsp
movq %rsi, %rbx
cmpl $0x1, %edi
jle 0x139c
movq 0x8(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0x1060
testl %eax, %eax
js 0x13a6
movq 0x8(%rbx), %rsi
leaq 0xe19(%rip), %rdi       # 0x201c
xorl %eax, %eax
callq 0x1050
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x1080
movl %eax, %r14d
movq %rbx, %rdi
callq 0x10a0
movl %eax, %edx
leaq 0xe0f(%rip), %rdi       # 0x203a
movq %r14, %rsi
xorl %eax, %eax
callq 0x1050
leaq 0xe23(%rip), %rdi       # 0x205f
xorl %eax, %eax
callq 0x1050
movl $0xf000, %eax           # imm = 0xF000
andl 0x20(%rsp), %eax
addl $0xfffff000, %eax       # imm = 0xFFFFF000
cmpl $0xbfff, %eax           # imm = 0xBFFF
ja 0x126b
shrl $0xa, %eax
leaq 0xfe6(%rip), %rcx       # 0x2248
movslq (%rax,%rcx), %rdi
addq %rcx, %rdi
jmp 0x1272
leaq 0xfcd(%rip), %rdi       # 0x223f
callq 0x1030
movl $0xb000, %eax           # imm = 0xB000
andl 0x20(%rsp), %eax
orl $0x4000, %eax           # imm = 0x4000
cmpl $0x6000, %eax           # imm = 0x6000
jne 0x12b7
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x1080
movl %eax, %r14d
movq %rbx, %rdi
callq 0x10a0
movl %eax, %edx
leaq 0xdcd(%rip), %rdi       # 0x207a
movq %r14, %rsi
xorl %eax, %eax
callq 0x1050
leaq 0x70(%rsp), %r14
movq -0x60(%r14), %rsi
leaq 0xdd8(%rip), %rdi       # 0x209f
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1050
movl -0x50(%r14), %esi
leaq 0xde3(%rip), %rdi       # 0x20be
xorl %eax, %eax
callq 0x1050
movq -0x58(%r14), %rsi
leaq 0xdf8(%rip), %rdi       # 0x20e5
xorl %eax, %eax
callq 0x1050
movl -0x4c(%r14), %esi
movl -0x48(%r14), %edx
leaq 0xe01(%rip), %rdi       # 0x2104
xorl %eax, %eax
callq 0x1050
movq -0x30(%r14), %rsi
leaq 0xe1a(%rip), %rdi       # 0x212f
xorl %eax, %eax
callq 0x1050
movq -0x38(%r14), %rsi
leaq 0xe2d(%rip), %rdi       # 0x2154
xorl %eax, %eax
callq 0x1050
movq -0x28(%r14), %rsi
leaq 0xe41(%rip), %rdi       # 0x217a
xorl %eax, %eax
callq 0x1050
movq %r14, %rdi
callq 0x1040
leaq 0xe4b(%rip), %rdi       # 0x219a
movq %rax, %rsi
xorl %eax, %eax
callq 0x1050
leaq 0x50(%rsp), %rdi
callq 0x1040
leaq 0xe4d(%rip), %rdi       # 0x21b7
movq %rax, %rsi
xorl %eax, %eax
callq 0x1050
leaq 0x60(%rsp), %rdi
callq 0x1040
leaq 0xe4f(%rip), %rdi       # 0x21d4
movq %rax, %rsi
xorl %eax, %eax
callq 0x1050
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r14
retq
movq %rbx, %rdi
callq 0x10c0
jmp 0x13b2
leaq 0xc69(%rip), %rdi       # 0x2016
callq 0x1090
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x138f