#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct stat {
  int st_mode;
  int st_uid;
  int st_gid;
  scalar_t__ st_size;
  scalar_t__ st_rdev;
  scalar_t__ st_ino;
  scalar_t__ st_dev;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ remip;
typedef int /*<<< orphan*/ locip;
typedef int /*<<< orphan*/ extra;

/* Variables and functions */
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
scalar_t__ S_ISBLK(int);
scalar_t__ S_ISCHR(int);
scalar_t__ S_ISDIR(int);
scalar_t__ S_ISFIFO(int);
scalar_t__ S_ISLNK(int);
scalar_t__ S_ISREG(int);
scalar_t__ S_ISSOCK(int);
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
scalar_t__ fstat(int, struct stat *);
int /*<<< orphan*/ getpeername(int, struct sockaddr *, unsigned int *);
int /*<<< orphan*/ getsockname(int, struct sockaddr *, unsigned int *);
scalar_t__ inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, char *, int, int, int, int, int, int,
                          char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, int, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *ttyname(int);
void cmd_lsfd(int argc, char *argv[]) {
  int fd;
  for (fd = 0; fd <= 1024; fd++) {
    struct stat st;
    char perm[10] = "---------";
    if (fstat(fd, &st) == 0) {
      char *type, *p;
      char extra[1024];
      memset(extra, 0, sizeof(extra));
      if (S_ISREG(st.st_mode))
        type = "file";
      if (S_ISDIR(st.st_mode))
        type = "directory";
      if (S_ISCHR(st.st_mode)) {
        type = "character";
        p = ttyname(fd);
        if (p != NULL)
          strncpy(extra, p, sizeof(extra));
      }
      if (S_ISBLK(st.st_mode))
        type = "block";
      if (S_ISFIFO(st.st_mode))
        type = "fifo";
      if (S_ISLNK(st.st_mode))
        type = "symlink";
      if (S_ISSOCK(st.st_mode)) {
        char locip[16], remip[16];
        struct sockaddr_in loc, rem;
        unsigned int slen = sizeof(struct sockaddr);
        memset(locip, 0, sizeof(locip));
        memset(remip, 0, sizeof(remip));
        getsockname(fd, (struct sockaddr *)&loc, &slen);
        getpeername(fd, (struct sockaddr *)&rem, &slen);
        strncpy(locip, (char *)inet_ntoa(loc.sin_addr), sizeof(locip));
        strncpy(remip, (char *)inet_ntoa(rem.sin_addr), sizeof(remip));
        snprintf(extra, sizeof(extra), "%s:%u -> %s:%u", locip,
                 ntohs(loc.sin_port), remip, ntohs(rem.sin_port));
        type = "socket";
      }
      if (st.st_mode & S_IRUSR)
        perm[0] = 'r';
      if (st.st_mode & S_IWUSR)
        perm[1] = 'w';
      if (st.st_mode & S_IXUSR)
        perm[2] = 'x';
      if (st.st_mode & S_IRGRP)
        perm[3] = 'r';
      if (st.st_mode & S_IWGRP)
        perm[4] = 'w';
      if (st.st_mode & S_IXGRP)
        perm[5] = 'x';
      if (st.st_mode & S_IROTH)
        perm[6] = 'r';
      if (st.st_mode & S_IWOTH)
        perm[7] = 'w';
      if (st.st_mode & S_IXOTH)
        perm[8] = 'x';
      printf("[%d] [%s] dev=%d ino=%d uid=%d gid=%d rdev=%d size=%d %s (%s)\n",
             fd, perm, (int)st.st_dev, (int)st.st_ino, st.st_uid, st.st_gid,
             (int)st.st_rdev, (int)st.st_size, type, extra);
    }
  }
}


x86 assembly (clang, -O0):
<cmd_lsfd>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x500,%rsp
mov    %edi,-0x14(%rbp)
mov    %rsi,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x400,-0x24(%rbp)
jg     15eb <cmd_lsfd+0x3db>
mov    0xdc0(%rip),%rax
mov    %rax,-0x62(%rbp)
mov    0xdbd(%rip),%ax
mov    %ax,-0x5a(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x58(%rbp),%rsi
call   1130 <fstat@plt>
cmp    $0x0,%rax
jne    15d8 <cmd_lsfd+0x3c8>
lea    -0x480(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   10c0 <memset@plt>
mov    -0x58(%rbp),%edi
call   10d0 <S_ISREG@plt>
cmp    $0x0,%rax
je     1295 <cmd_lsfd+0x85>
lea    0xd79(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    -0x58(%rbp),%edi
call   10a0 <S_ISDIR@plt>
cmp    $0x0,%rax
je     12b2 <cmd_lsfd+0xa2>
lea    0xd61(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    -0x58(%rbp),%edi
call   10e0 <S_ISCHR@plt>
cmp    $0x0,%rax
je     1300 <cmd_lsfd+0xf0>
lea    0xd4e(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    -0x24(%rbp),%edi
call   1100 <ttyname@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     12fb <cmd_lsfd+0xeb>
lea    -0x480(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    $0x400,%edx
call   1030 <strncpy@plt>
jmp    1300 <cmd_lsfd+0xf0>
mov    -0x58(%rbp),%edi
call   10f0 <S_ISBLK@plt>
cmp    $0x0,%rax
je     131d <cmd_lsfd+0x10d>
lea    0xd0a(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    -0x58(%rbp),%edi
call   1070 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     133a <cmd_lsfd+0x12a>
lea    0xcf3(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    -0x58(%rbp),%edi
call   1040 <S_ISLNK@plt>
cmp    $0x0,%rax
je     1357 <cmd_lsfd+0x147>
lea    0xcdb(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    -0x58(%rbp),%edi
call   1080 <S_ISSOCK@plt>
cmp    $0x0,%rax
je     14a0 <cmd_lsfd+0x290>
movl   $0x4,-0x4b4(%rbp)
lea    -0x490(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10c0 <memset@plt>
lea    -0x4a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10c0 <memset@plt>
mov    -0x24(%rbp),%edi
lea    -0x4a8(%rbp),%rsi
lea    -0x4b4(%rbp),%rdx
call   1120 <getsockname@plt>
mov    -0x24(%rbp),%edi
lea    -0x4b0(%rbp),%rsi
lea    -0x4b4(%rbp),%rdx
call   1060 <getpeername@plt>
lea    -0x490(%rbp),%rax
mov    %rax,-0x4e8(%rbp)
mov    -0x4a4(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    -0x4e8(%rbp),%rdi
mov    %rax,%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
lea    -0x4a0(%rbp),%rax
mov    %rax,-0x4e0(%rbp)
mov    -0x4ac(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    -0x4e0(%rbp),%rdi
mov    %rax,%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
lea    -0x480(%rbp),%rax
mov    %rax,-0x4d8(%rbp)
lea    -0x490(%rbp),%rax
mov    %rax,-0x4d0(%rbp)
mov    -0x4a8(%rbp),%edi
call   1110 <ntohs@plt>
mov    %eax,-0x4c4(%rbp)
lea    -0x4a0(%rbp),%rax
mov    %rax,-0x4c0(%rbp)
mov    -0x4b0(%rbp),%edi
call   1110 <ntohs@plt>
mov    -0x4d8(%rbp),%rdi
mov    -0x4d0(%rbp),%rcx
mov    -0x4c4(%rbp),%r8d
mov    -0x4c0(%rbp),%r9
mov    $0x400,%esi
lea    0xba9(%rip),%rdx
mov    %eax,(%rsp)
call   10b0 <snprintf@plt>
lea    0xba9(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    -0x58(%rbp),%eax
mov    0x2afe(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     14b9 <cmd_lsfd+0x2a9>
movb   $0x72,-0x62(%rbp)
mov    -0x58(%rbp),%eax
mov    0x2b0d(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     14d2 <cmd_lsfd+0x2c2>
movb   $0x77,-0x61(%rbp)
mov    -0x58(%rbp),%eax
mov    0x2b04(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     14eb <cmd_lsfd+0x2db>
movb   $0x78,-0x60(%rbp)
mov    -0x58(%rbp),%eax
mov    0x2ac3(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1504 <cmd_lsfd+0x2f4>
movb   $0x72,-0x5f(%rbp)
mov    -0x58(%rbp),%eax
mov    0x2aca(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     151d <cmd_lsfd+0x30d>
movb   $0x77,-0x5e(%rbp)
mov    -0x58(%rbp),%eax
mov    0x2aa1(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1536 <cmd_lsfd+0x326>
movb   $0x78,-0x5d(%rbp)
mov    -0x58(%rbp),%eax
mov    0x2a70(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     154f <cmd_lsfd+0x33f>
movb   $0x72,-0x5c(%rbp)
mov    -0x58(%rbp),%eax
mov    0x2a3f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1568 <cmd_lsfd+0x358>
movb   $0x77,-0x5b(%rbp)
mov    -0x58(%rbp),%eax
mov    0x2a76(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1581 <cmd_lsfd+0x371>
movb   $0x78,-0x5a(%rbp)
mov    -0x24(%rbp),%esi
lea    -0x62(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %eax,%r8d
mov    -0x54(%rbp),%r9d
mov    -0x50(%rbp),%r14d
mov    -0x40(%rbp),%rax
mov    %eax,%ebx
mov    -0x48(%rbp),%rax
mov    %eax,%r11d
mov    -0x70(%rbp),%r10
lea    -0x480(%rbp),%rax
lea    0xa90(%rip),%rdi
mov    %r14d,(%rsp)
mov    %ebx,0x8(%rsp)
mov    %r11d,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
call   1090 <printf@plt>
jmp    15dd <cmd_lsfd+0x3cd>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    122c <cmd_lsfd+0x1c>
add    $0x500,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_lsfd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x478,%rsp
xor    %ebx,%ebx
movabs $0x2d2d2d2d2d2d2d2d,%r12
2d 2d 2d
lea    0x20(%rsp),%r14
jmp    1294 <cmd_lsfd+0x84>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x48(%rsp),%ecx
mov    0x40(%rsp),%r8d
mov    0x24(%rsp),%r9d
mov    0x28(%rsp),%r10d
mov    0x38(%rsp),%r11d
mov    0x30(%rsp),%r15d
sub    $0x8,%rsp
lea    0xde4(%rip),%rdi
mov    %ebx,%esi
lea    0x8(%rsp),%rdx
lea    0x78(%rsp),%rax
push   %rax
push   %rbp
push   %r15
push   %r11
push   %r10
call   1090 <printf@plt>
add    $0x30,%rsp
add    $0x1,%ebx
cmp    $0x401,%ebx
je     14f0 <cmd_lsfd+0x2e0>
mov    %r12,(%rsp)
movw   $0x2d,0x8(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
call   1130 <fstat@plt>
test   %rax,%rax
jne    1285 <cmd_lsfd+0x75>
lea    0x70(%rsp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   10c0 <memset@plt>
mov    0x20(%rsp),%r13d
mov    %r13d,%edi
call   10d0 <S_ISREG@plt>
test   %rax,%rax
lea    0xd34(%rip),%rax
cmovne %rax,%rbp
mov    %r13d,%edi
call   10a0 <S_ISDIR@plt>
test   %rax,%rax
lea    0xd23(%rip),%rax
cmovne %rax,%rbp
mov    %r13d,%edi
call   10e0 <S_ISCHR@plt>
test   %rax,%rax
je     1329 <cmd_lsfd+0x119>
mov    %ebx,%edi
call   1100 <ttyname@plt>
lea    0xd0e(%rip),%rbp
test   %rax,%rax
je     1329 <cmd_lsfd+0x119>
lea    0x70(%rsp),%rdi
mov    %rax,%rsi
mov    $0x400,%edx
call   1030 <strncpy@plt>
lea    0xcf0(%rip),%rbp
mov    %r13d,%edi
call   10f0 <S_ISBLK@plt>
test   %rax,%rax
lea    0xce8(%rip),%rax
cmovne %rax,%rbp
mov    %r13d,%edi
call   1070 <S_ISFIFO@plt>
test   %rax,%rax
lea    0xcd8(%rip),%rax
cmovne %rax,%rbp
mov    %r13d,%edi
call   1040 <S_ISLNK@plt>
test   %rax,%rax
lea    0xcc7(%rip),%rax
cmovne %rax,%rbp
mov    %r13d,%edi
call   1080 <S_ISSOCK@plt>
test   %rax,%rax
je     144f <cmd_lsfd+0x23f>
movl   $0x4,0xc(%rsp)
mov    %r12,%r14
lea    0x60(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10c0 <memset@plt>
lea    0x50(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10c0 <memset@plt>
mov    %ebx,%edi
lea    0x18(%rsp),%rsi
lea    0xc(%rsp),%rbp
mov    %rbp,%rdx
call   1120 <getsockname@plt>
mov    %ebx,%edi
lea    0x10(%rsp),%rsi
mov    %rbp,%rdx
call   1060 <getpeername@plt>
mov    0x1c(%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %r12,%rdi
mov    %rax,%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
mov    0x14(%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %r15,%rdi
mov    %rax,%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
mov    0x18(%rsp),%edi
call   1110 <ntohs@plt>
mov    %eax,%ebp
mov    0x10(%rsp),%edi
call   1110 <ntohs@plt>
sub    $0x8,%rsp
lea    0x78(%rsp),%rdi
mov    $0x400,%esi
lea    0xc09(%rip),%rdx
mov    %r12,%rcx
mov    %r14,%r12
lea    0x28(%rsp),%r14
mov    %ebp,%r8d
mov    %r15,%r9
push   %rax
call   10b0 <snprintf@plt>
add    $0x10,%rsp
lea    0xbf6(%rip),%rbp
mov    0x2b52(%rip),%rax
test   %r13d,(%rax)
je     145f <cmd_lsfd+0x24f>
movb   $0x72,(%rsp)
mov    0x2b6a(%rip),%rax
test   %r13d,(%rax)
je     1470 <cmd_lsfd+0x260>
movb   $0x77,0x1(%rsp)
mov    0x2b69(%rip),%rax
test   %r13d,(%rax)
je     1481 <cmd_lsfd+0x271>
movb   $0x78,0x2(%rsp)
mov    0x2b30(%rip),%rax
test   %r13d,(%rax)
je     1492 <cmd_lsfd+0x282>
movb   $0x72,0x3(%rsp)
mov    0x2b3f(%rip),%rax
test   %r13d,(%rax)
je     14a3 <cmd_lsfd+0x293>
movb   $0x77,0x4(%rsp)
mov    0x2b1e(%rip),%rax
test   %r13d,(%rax)
je     14b4 <cmd_lsfd+0x2a4>
movb   $0x78,0x5(%rsp)
mov    0x2af5(%rip),%rax
test   %r13d,(%rax)
je     14c5 <cmd_lsfd+0x2b5>
movb   $0x72,0x6(%rsp)
mov    0x2acc(%rip),%rax
test   %r13d,(%rax)
je     14d6 <cmd_lsfd+0x2c6>
movb   $0x77,0x7(%rsp)
mov    0x2b0b(%rip),%rax
test   %r13d,(%rax)
je     1240 <cmd_lsfd+0x30>
movb   $0x78,0x8(%rsp)
jmp    1240 <cmd_lsfd+0x30>
add    $0x478,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32, i32, i64, i64, i64, i64 }
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@__const.cmd_lsfd.perm = [10 x i8] c"---------\00"
@.str = [5 x i8] c"file\00"
@.str.1 = [10 x i8] c"directory\00"
@.str.2 = [10 x i8] c"character\00"
@.str.3 = [6 x i8] c"block\00"
@.str.4 = [5 x i8] c"fifo\00"
@.str.5 = [8 x i8] c"symlink\00"
@.str.6 = [15 x i8] c"%s:%u -> %s:%u\00"
@.str.7 = [7 x i8] c"socket\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@S_IXOTH = global i32 0
@.str.8 = [63 x i8] c"[%d] [%s] dev=%d ino=%d uid=%d gid=%d rdev=%d size=%d %s (%s)\0A\00"
define void @cmd_lsfd(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca %struct.stat
%7 = alloca [10 x i8]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [1024 x i8]
%11 = alloca [16 x i8]
%12 = alloca [16 x i8]
%13 = alloca %struct.sockaddr_in
%14 = alloca %struct.sockaddr_in
%15 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 0, i32* %5
br label %16
16: ; preds = %204, %2
%17 = load i32, i32* %5
%18 = icmp sle i32 %17, 1024
br i1 %18, label %19, label %207
19: ; preds = %16
%20 = bitcast [10 x i8]* %7 to i8*
%21 = load i32, i32* %5
%22 = call i64 @fstat(i32 %21, %struct.stat* %6)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %203
24: ; preds = %19
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%26 = call i32 @memset(i8* %25, i32 0, i32 1024)
%27 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i64 @S_ISREG(i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %24
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %8
br label %32
32: ; preds = %31, %24
%33 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i64 @S_ISDIR(i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %38
38: ; preds = %37, %32
%39 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i64 @S_ISCHR(i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %53
43: ; preds = %38
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8** %8
%44 = load i32, i32* %5
%45 = call i8* @ttyname(i32 %44)
store i8* %45, i8** %9
%46 = load i8*, i8** %9
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %52
48: ; preds = %43
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%50 = load i8*, i8** %9
%51 = call i32 @strncpy(i8* %49, i8* %50, i32 1024)
br label %52
52: ; preds = %48, %43
br label %53
53: ; preds = %52, %38
%54 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%55 = load i32, i32* %54
%56 = call i64 @S_ISBLK(i32 %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %53
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8** %8
br label %59
59: ; preds = %58, %53
%60 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%61 = load i32, i32* %60
%62 = call i64 @S_ISFIFO(i32 %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %59
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** %8
br label %65
65: ; preds = %64, %59
%66 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%67 = load i32, i32* %66
%68 = call i64 @S_ISLNK(i32 %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %71
70: ; preds = %65
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %8
br label %71
71: ; preds = %70, %65
%72 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%73 = load i32, i32* %72
%74 = call i64 @S_ISSOCK(i32 %73)
%75 = icmp ne i64 %74, 0
br i1 %75, label %76, label %109
76: ; preds = %71
store i32 4, i32* %15
%77 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%78 = call i32 @memset(i8* %77, i32 0, i32 16)
%79 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%80 = call i32 @memset(i8* %79, i32 0, i32 16)
%81 = load i32, i32* %5
%82 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%83 = call i32 @getsockname(i32 %81, %struct.sockaddr* %82, i32* %15)
%84 = load i32, i32* %5
%85 = bitcast %struct.sockaddr_in* %14 to %struct.sockaddr*
%86 = call i32 @getpeername(i32 %84, %struct.sockaddr* %85, i32* %15)
%87 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%88 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
%89 = load i32, i32* %88
%90 = call i64 @inet_ntoa(i32 %89)
%91 = inttoptr i64 %90 to i8*
%92 = call i32 @strncpy(i8* %87, i8* %91, i32 16)
%93 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%94 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 1
%95 = load i32, i32* %94
%96 = call i64 @inet_ntoa(i32 %95)
%97 = inttoptr i64 %96 to i8*
%98 = call i32 @strncpy(i8* %93, i8* %97, i32 16)
%99 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%100 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%101 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
%102 = load i32, i32* %101
%103 = call i32 @ntohs(i32 %102)
%104 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%105 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 0
%106 = load i32, i32* %105
%107 = call i32 @ntohs(i32 %106)
%108 = call i32 @snprintf(i8* %99, i32 1024, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %100, i32 %103, i8* %104, i32 %107)
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8** %8
br label %109
109: ; preds = %76, %71
%110 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%111 = load i32, i32* %110
%112 = load i32, i32* @S_IRUSR
%113 = and i32 %111, %112
%114 = icmp ne i32 %113, 0
br i1 %114, label %115, label %117
115: ; preds = %109
%116 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
store i8 114, i8* %116
br label %117
117: ; preds = %115, %109
%118 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%119 = load i32, i32* %118
%120 = load i32, i32* @S_IWUSR
%121 = and i32 %119, %120
%122 = icmp ne i32 %121, 0
br i1 %122, label %123, label %125
123: ; preds = %117
%124 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 1
store i8 119, i8* %124
br label %125
125: ; preds = %123, %117
%126 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%127 = load i32, i32* %126
%128 = load i32, i32* @S_IXUSR
%129 = and i32 %127, %128
%130 = icmp ne i32 %129, 0
br i1 %130, label %131, label %133
131: ; preds = %125
%132 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 2
store i8 120, i8* %132
br label %133
133: ; preds = %131, %125
%134 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%135 = load i32, i32* %134
%136 = load i32, i32* @S_IRGRP
%137 = and i32 %135, %136
%138 = icmp ne i32 %137, 0
br i1 %138, label %139, label %141
139: ; preds = %133
%140 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 3
store i8 114, i8* %140
br label %141
141: ; preds = %139, %133
%142 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%143 = load i32, i32* %142
%144 = load i32, i32* @S_IWGRP
%145 = and i32 %143, %144
%146 = icmp ne i32 %145, 0
br i1 %146, label %147, label %149
147: ; preds = %141
%148 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 4
store i8 119, i8* %148
br label %149
149: ; preds = %147, %141
%150 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%151 = load i32, i32* %150
%152 = load i32, i32* @S_IXGRP
%153 = and i32 %151, %152
%154 = icmp ne i32 %153, 0
br i1 %154, label %155, label %157
155: ; preds = %149
%156 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 5
store i8 120, i8* %156
br label %157
157: ; preds = %155, %149
%158 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%159 = load i32, i32* %158
%160 = load i32, i32* @S_IROTH
%161 = and i32 %159, %160
%162 = icmp ne i32 %161, 0
br i1 %162, label %163, label %165
163: ; preds = %157
%164 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 6
store i8 114, i8* %164
br label %165
165: ; preds = %163, %157
%166 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%167 = load i32, i32* %166
%168 = load i32, i32* @S_IWOTH
%169 = and i32 %167, %168
%170 = icmp ne i32 %169, 0
br i1 %170, label %171, label %173
171: ; preds = %165
%172 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 7
store i8 119, i8* %172
br label %173
173: ; preds = %171, %165
%174 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%175 = load i32, i32* %174
%176 = load i32, i32* @S_IXOTH
%177 = and i32 %175, %176
%178 = icmp ne i32 %177, 0
br i1 %178, label %179, label %181
179: ; preds = %173
%180 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 8
store i8 120, i8* %180
br label %181
181: ; preds = %179, %173
%182 = load i32, i32* %5
%183 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%184 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 6
%185 = load i64, i64* %184
%186 = trunc i64 %185 to i32
%187 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 5
%188 = load i64, i64* %187
%189 = trunc i64 %188 to i32
%190 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%191 = load i32, i32* %190
%192 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 2
%193 = load i32, i32* %192
%194 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 4
%195 = load i64, i64* %194
%196 = trunc i64 %195 to i32
%197 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 3
%198 = load i64, i64* %197
%199 = trunc i64 %198 to i32
%200 = load i8*, i8** %8
%201 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%202 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.8, i64 0, i64 0), i32 %182, i8* %183, i32 %186, i32 %189, i32 %191, i32 %193, i32 %196, i32 %199, i8* %200, i8* %201)
br label %203
203: ; preds = %181, %19
br label %204
204: ; preds = %203
%205 = load i32, i32* %5
%206 = add nsw i32 %205, 1
store i32 %206, i32* %5
br label %16
207: ; preds = %16
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32, i64, i64, i64, i64 }
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@__const.cmd_lsfd.perm = [10 x i8] c"---------\00"
@.str = [5 x i8] c"file\00"
@.str.1 = [10 x i8] c"directory\00"
@.str.2 = [10 x i8] c"character\00"
@.str.3 = [6 x i8] c"block\00"
@.str.4 = [5 x i8] c"fifo\00"
@.str.5 = [8 x i8] c"symlink\00"
@.str.6 = [15 x i8] c"%s:%u -> %s:%u\00"
@.str.7 = [7 x i8] c"socket\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@S_IXOTH = global i32 0
@.str.8 = [63 x i8] c"[%d] [%s] dev=%d ino=%d uid=%d gid=%d rdev=%d size=%d %s (%s)\0A\00"
define void @cmd_lsfd(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.stat
%4 = alloca [10 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [16 x i8]
%7 = alloca [16 x i8]
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = bitcast %struct.stat* %3 to i8*
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%17 = bitcast %struct.sockaddr_in* %8 to i8*
%18 = bitcast %struct.sockaddr_in* %9 to i8*
%19 = bitcast i32* %10 to i8*
%20 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%21 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 1
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 1
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 0
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 0
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 1
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 2
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 3
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 4
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 5
%31 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 6
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 7
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 8
%34 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 6
%35 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 5
%36 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%37 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 2
%38 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 4
%39 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 3
br label %40
40: ; preds = %2, %150
%41 = phi i32 [ 0, %2 ], [ %152, %150 ]
%42 = phi i8* [ undef, %2 ], [ %151, %150 ]
%43 = call i64 @fstat(i32 %41, %struct.stat* %3)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %150
45: ; preds = %40
%46 = call i32 @memset(i8* %13, i32 0, i32 1024)
%47 = load i32, i32* %14
%48 = call i64 @S_ISREG(i32 %47)
%49 = icmp eq i64 %48, 0
%50 = select i1 %49, i8* %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0)
%51 = call i64 @S_ISDIR(i32 %47)
%52 = icmp eq i64 %51, 0
%53 = select i1 %52, i8* %50, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0)
%54 = call i64 @S_ISCHR(i32 %47)
%55 = icmp eq i64 %54, 0
br i1 %55, label %61, label %56
56: ; preds = %45
%57 = call i8* @ttyname(i32 %41)
%58 = icmp eq i8* %57, null
br i1 %58, label %61, label %59
59: ; preds = %56
%60 = call i32 @strncpy(i8* %13, i8* %57, i32 1024)
br label %61
61: ; preds = %56, %59, %45
%62 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %59 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %56 ], [ %53, %45 ]
%63 = call i64 @S_ISBLK(i32 %47)
%64 = icmp eq i64 %63, 0
%65 = select i1 %64, i8* %62, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%66 = call i64 @S_ISFIFO(i32 %47)
%67 = icmp eq i64 %66, 0
%68 = select i1 %67, i8* %65, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
%69 = call i64 @S_ISLNK(i32 %47)
%70 = icmp eq i64 %69, 0
%71 = select i1 %70, i8* %68, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0)
%72 = call i64 @S_ISSOCK(i32 %47)
%73 = icmp eq i64 %72, 0
br i1 %73, label %92, label %74
74: ; preds = %61
store i32 4, i32* %10
%75 = call i32 @memset(i8* %15, i32 0, i32 16)
%76 = call i32 @memset(i8* %16, i32 0, i32 16)
%77 = call i32 @getsockname(i32 %41, %struct.sockaddr* %20, i32* %10)
%78 = call i32 @getpeername(i32 %41, %struct.sockaddr* %21, i32* %10)
%79 = load i32, i32* %22
%80 = call i64 @inet_ntoa(i32 %79)
%81 = inttoptr i64 %80 to i8*
%82 = call i32 @strncpy(i8* %15, i8* %81, i32 16)
%83 = load i32, i32* %23
%84 = call i64 @inet_ntoa(i32 %83)
%85 = inttoptr i64 %84 to i8*
%86 = call i32 @strncpy(i8* %16, i8* %85, i32 16)
%87 = load i32, i32* %24
%88 = call i32 @ntohs(i32 %87)
%89 = load i32, i32* %25
%90 = call i32 @ntohs(i32 %89)
%91 = call i32 @snprintf(i8* %13, i32 1024, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %15, i32 %88, i8* %16, i32 %90)
br label %92
92: ; preds = %74, %61
%93 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), %74 ], [ %71, %61 ]
%94 = load i32, i32* @S_IRUSR
%95 = and i32 %94, %47
%96 = icmp eq i32 %95, 0
br i1 %96, label %98, label %97
97: ; preds = %92
store i8 114, i8* %12
br label %98
98: ; preds = %97, %92
%99 = load i32, i32* @S_IWUSR
%100 = and i32 %99, %47
%101 = icmp eq i32 %100, 0
br i1 %101, label %103, label %102
102: ; preds = %98
store i8 119, i8* %26
br label %103
103: ; preds = %102, %98
%104 = load i32, i32* @S_IXUSR
%105 = and i32 %104, %47
%106 = icmp eq i32 %105, 0
br i1 %106, label %108, label %107
107: ; preds = %103
store i8 120, i8* %27
br label %108
108: ; preds = %107, %103
%109 = load i32, i32* @S_IRGRP
%110 = and i32 %109, %47
%111 = icmp eq i32 %110, 0
br i1 %111, label %113, label %112
112: ; preds = %108
store i8 114, i8* %28
br label %113
113: ; preds = %112, %108
%114 = load i32, i32* @S_IWGRP
%115 = and i32 %114, %47
%116 = icmp eq i32 %115, 0
br i1 %116, label %118, label %117
117: ; preds = %113
store i8 119, i8* %29
br label %118
118: ; preds = %117, %113
%119 = load i32, i32* @S_IXGRP
%120 = and i32 %119, %47
%121 = icmp eq i32 %120, 0
br i1 %121, label %123, label %122
122: ; preds = %118
store i8 120, i8* %30
br label %123
123: ; preds = %122, %118
%124 = load i32, i32* @S_IROTH
%125 = and i32 %124, %47
%126 = icmp eq i32 %125, 0
br i1 %126, label %128, label %127
127: ; preds = %123
store i8 114, i8* %31
br label %128
128: ; preds = %127, %123
%129 = load i32, i32* @S_IWOTH
%130 = and i32 %129, %47
%131 = icmp eq i32 %130, 0
br i1 %131, label %133, label %132
132: ; preds = %128
store i8 119, i8* %32
br label %133
133: ; preds = %132, %128
%134 = load i32, i32* @S_IXOTH
%135 = and i32 %134, %47
%136 = icmp eq i32 %135, 0
br i1 %136, label %138, label %137
137: ; preds = %133
store i8 120, i8* %33
br label %138
138: ; preds = %137, %133
%139 = load i64, i64* %34
%140 = trunc i64 %139 to i32
%141 = load i64, i64* %35
%142 = trunc i64 %141 to i32
%143 = load i32, i32* %36
%144 = load i32, i32* %37
%145 = load i64, i64* %38
%146 = trunc i64 %145 to i32
%147 = load i64, i64* %39
%148 = trunc i64 %147 to i32
%149 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.8, i64 0, i64 0), i32 %41, i8* %12, i32 %140, i32 %142, i32 %143, i32 %144, i32 %146, i32 %148, i8* %93, i8* %13)
br label %150
150: ; preds = %138, %40
%151 = phi i8* [ %93, %138 ], [ %42, %40 ]
%152 = add nuw nsw i32 %41, 1
%153 = icmp eq i32 %152, 1025
br i1 %153, label %154, label %40
154: ; preds = %150
ret void
}