// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0x11ea
movq 0x2e32(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0xe2d(%rip), %rsi       # 0x2004
movb $0x0, %al
callq 0x1060
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x14dc
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x1050
movl %eax, -0xa4(%rbp)
cmpl $0x0, -0xa4(%rbp)
jge 0x1225
leaq 0xe02(%rip), %rdi       # 0x2016
callq 0x1080
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x14dc
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0xde8(%rip), %rdi       # 0x201c
xorl %eax, %eax
movb %al, -0xa9(%rbp)
callq 0x1040
movq -0xa0(%rbp), %rdi
callq 0x1070
movl %eax, %eax
movq %rax, -0xb8(%rbp)
movq -0xa0(%rbp), %rdi
callq 0x1090
movq -0xb8(%rbp), %rsi
movl %eax, %ecx
movb -0xa9(%rbp), %al
movl %ecx, %ecx
movl %ecx, %edx
leaq 0xdbe(%rip), %rdi       # 0x203a
callq 0x1040
movb -0xa9(%rbp), %al
leaq 0xdd1(%rip), %rdi       # 0x205f
callq 0x1040
movl -0x88(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
movl %eax, -0xa8(%rbp)
subl $0x1000, %eax           # imm = 0x1000
je 0x133b
jmp 0x12b1
movl -0xa8(%rbp), %eax
subl $0x2000, %eax           # imm = 0x2000
je 0x131b
jmp 0x12c0
movl -0xa8(%rbp), %eax
subl $0x4000, %eax           # imm = 0x4000
je 0x132b
jmp 0x12cf
movl -0xa8(%rbp), %eax
subl $0x6000, %eax           # imm = 0x6000
je 0x130b
jmp 0x12de
movl -0xa8(%rbp), %eax
subl $0x8000, %eax           # imm = 0x8000
je 0x135b
jmp 0x12ed
movl -0xa8(%rbp), %eax
subl $0xa000, %eax           # imm = 0xA000
je 0x134b
jmp 0x12fc
movl -0xa8(%rbp), %eax
subl $0xc000, %eax           # imm = 0xC000
je 0x136b
jmp 0x137b
leaq 0xd68(%rip), %rdi       # 0x207a
movb $0x0, %al
callq 0x1040
jmp 0x1389
leaq 0xd66(%rip), %rdi       # 0x2088
movb $0x0, %al
callq 0x1040
jmp 0x1389
leaq 0xd68(%rip), %rdi       # 0x209a
movb $0x0, %al
callq 0x1040
jmp 0x1389
leaq 0xd63(%rip), %rdi       # 0x20a5
movb $0x0, %al
callq 0x1040
jmp 0x1389
leaq 0xd5e(%rip), %rdi       # 0x20b0
movb $0x0, %al
callq 0x1040
jmp 0x1389
leaq 0xd57(%rip), %rdi       # 0x20b9
movb $0x0, %al
callq 0x1040
jmp 0x1389
leaq 0xd55(%rip), %rdi       # 0x20c7
movb $0x0, %al
callq 0x1040
jmp 0x1389
leaq 0xd4d(%rip), %rdi       # 0x20cf
movb $0x0, %al
callq 0x1040
movl -0x88(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x2000, %eax           # imm = 0x2000
je 0x13ad
movl -0x88(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x6000, %eax           # imm = 0x6000
jne 0x13e1
movq -0x78(%rbp), %rdi
callq 0x1070
movl %eax, %eax
movq %rax, -0xc0(%rbp)
movq -0x78(%rbp), %rdi
callq 0x1090
movq -0xc0(%rbp), %rsi
movl %eax, %eax
movl %eax, %edx
leaq 0xcff(%rip), %rdi       # 0x20d9
movb $0x0, %al
callq 0x1040
movq -0x98(%rbp), %rsi
leaq 0xd0f(%rip), %rdi       # 0x20fe
movb $0x0, %al
callq 0x1040
movl -0x88(%rbp), %eax
movl %eax, %esi
leaq 0xd18(%rip), %rdi       # 0x211d
movb $0x0, %al
callq 0x1040
movq -0x90(%rbp), %rsi
leaq 0xd2a(%rip), %rdi       # 0x2144
movb $0x0, %al
callq 0x1040
movl -0x84(%rbp), %eax
movl %eax, %esi
movl -0x80(%rbp), %eax
movl %eax, %edx
leaq 0xd2e(%rip), %rdi       # 0x2163
movb $0x0, %al
callq 0x1040
movq -0x68(%rbp), %rsi
leaq 0xd47(%rip), %rdi       # 0x218e
movb $0x0, %al
callq 0x1040
movq -0x70(%rbp), %rsi
leaq 0xd5a(%rip), %rdi       # 0x21b3
movb $0x0, %al
callq 0x1040
movq -0x60(%rbp), %rsi
leaq 0xd6e(%rip), %rdi       # 0x21d9
movb $0x0, %al
callq 0x1040
leaq -0xa0(%rbp), %rdi
addq $0x68, %rdi
callq 0x1030
movq %rax, %rsi
leaq 0xd6d(%rip), %rdi       # 0x21f9
movb $0x0, %al
callq 0x1040
leaq -0xa0(%rbp), %rdi
addq $0x48, %rdi
callq 0x1030
movq %rax, %rsi
leaq 0xd69(%rip), %rdi       # 0x2216
movb $0x0, %al
callq 0x1040
leaq -0xa0(%rbp), %rdi
addq $0x58, %rdi
callq 0x1030
movq %rax, %rsi
leaq 0xd65(%rip), %rdi       # 0x2233
movb $0x0, %al
callq 0x1040
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq