#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 /*<<< orphan*/ st_mode;
};
struct option {
  char *member_0;
  char member_3;
  int /*<<< orphan*/ member_2;
  int /*<<< orphan*/ const member_1;
};

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ free(char *);
char getopt_long(int, char **, char *, struct option const *,
                 int /*<<< orphan*/ *);
int /*<<< orphan*/ invalid(char **, char *);
char *malloc(int);
#define no_argument 128
int open(char *, int /*<<< orphan*/);
int optind;
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
char *strstr(char *, char *);
int /*<<< orphan*/ usage(char **, int);
scalar_t__ write(int, char *, int);
int main(int argc, char **argv) {
  char c;
  char *devpath;
  char *sysfs_path;
  char *sysfs_data;
  struct stat sysfs_stat;
  int fd;
  char *host_str;
  int host_pos;
  int host_len;
  char *host_next_str;
  int host_next_pos;
  int host_next_len;
  char *target_str;
  int target_pos;
  int target_len;
  char *channel_str;
  int channel_pos;
  int channel_len;
  char *id_str;
  int id_pos;
  int id_len;
  char *dir_str;
  static const struct option longopts[] = {
      {"help", no_argument, 0, 'h'},
      {NULL, no_argument, 0, '0'},
  };
  while ((c = getopt_long(argc, argv, "rh", longopts, NULL)) != -1) {
    switch (c) {
    case 'h':
      usage(argv, 0);
    default:
      usage(argv, 1);
    }
  }
  if (optind >= argc) {
    usage(argv, 1);
  }
  devpath = argv[optind++];
  if (devpath == NULL) {
    usage(argv, 1);
  }
  sysfs_path = malloc(strlen("/sys") + strlen(devpath) + 1);
  strcpy(sysfs_path, "/sys");
  strcat(sysfs_path, devpath);
  if (stat(sysfs_path, &sysfs_stat) < 0) {
    fprintf(stderr, "Cannot stat '%s': %s\n", sysfs_path, strerror(errno));
    usage(argv, 1);
  }
  if (!S_ISDIR(sysfs_stat.st_mode))
    invalid(argv, devpath);
  free(sysfs_path);
  if ((host_str = strstr(devpath, "/host")) == NULL)
    invalid(argv, devpath);
  host_pos = strlen(devpath) - strlen(host_str);
  if ((host_next_str = strstr(&devpath[host_pos + 1], "/")) == NULL)
    invalid(argv, devpath);
  host_next_pos = strlen(devpath) - strlen(host_next_str);
  if ((target_str = strstr(devpath, "/target")) == NULL)
    invalid(argv, devpath);
  target_pos = strlen(devpath) - strlen(target_str);
  host_len = host_next_pos - host_pos;
  if (host_len <= strlen("/host"))
    invalid(argv, devpath);
  host_next_len = strlen(&devpath[host_next_pos]);
  if (host_next_len <= strlen("/"))
    invalid(argv, devpath);
  target_len = strlen(&devpath[target_pos]);
  if (target_len <= strlen("/target"))
    invalid(argv, devpath);
  sysfs_path = malloc(strlen("/sys") + strlen(devpath) - host_next_len +
                      strlen("/scsi_host") + host_len + strlen("/scan") + 1);
  strcpy(sysfs_path, "/sys");
  strncat(sysfs_path, devpath, host_next_pos);
  strcat(sysfs_path, "/scsi_host");
  strncat(sysfs_path, host_str, host_len);
  strcat(sysfs_path, "/scan");
  if ((channel_str = strstr(&devpath[target_pos], ":")) == NULL)
    invalid(argv, devpath);
  channel_pos = strlen(&devpath[target_pos]) - strlen(channel_str) + 1;
  if ((id_str = strstr(&devpath[target_pos + channel_pos], ":")) == NULL)
    invalid(argv, devpath);
  id_pos = strlen(&devpath[target_pos + channel_pos]) - strlen(id_str) + 1;
  if ((dir_str = strstr(&devpath[target_pos + channel_pos + id_pos], "/")) ==
      NULL)
    invalid(argv, devpath);
  channel_len = strlen(&devpath[target_pos + channel_pos]) - strlen(id_str);
  if (channel_len < 1)
    invalid(argv, devpath);
  id_len =
      strlen(&devpath[target_pos + channel_pos + id_pos]) - strlen(dir_str);
  if (id_len < 1)
    invalid(argv, devpath);
  sysfs_data = malloc(channel_len + strlen(" ") + id_len + strlen(" -") + 1);
  sysfs_data[0] = '\0';
  strncat(sysfs_data, &devpath[target_pos + channel_pos], channel_len);
  strcat(sysfs_data, " ");
  strncat(sysfs_data, &devpath[target_pos + channel_pos + id_pos], id_len);
  strcat(sysfs_data, " -");
  if ((fd = open(sysfs_path, O_WRONLY)) < 0) {
    fprintf(stderr, "Cannot open '%s': %s\n", sysfs_path, strerror(errno));
    usage(argv, 1);
  }
  if (write(fd, sysfs_data, strlen(sysfs_data)) < 0) {
    fprintf(stderr, "Cannot write '%s': %s\n", sysfs_path, strerror(errno));
    usage(argv, 1);
  }
  close(fd);
  free(sysfs_path);
  free(sysfs_data);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdce(%rip),%rdx
lea    0x2b92(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1070 <getopt_long@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     1285 <main+0x75>
mov    -0x11(%rbp),%al
sub    $0x68,%al
jne    1272 <main+0x62>
jmp    1267 <main+0x57>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   10e0 <usage@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   10e0 <usage@plt>
jmp    1229 <main+0x19>
mov    0x2d5c(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     12a5 <main+0x95>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   10e0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x2d38(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    0x2d2a(%rip),%rdx
mov    %esi,(%rdx)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12e4 <main+0xd4>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   10e0 <usage@plt>
lea    0xd1d(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x9c(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x9c(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xcea(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1110 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10c0 <stat@plt>
cmp    $0x0,%rax
jge    1399 <main+0x189>
mov    0x2c8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    0x2c68(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0xac(%rbp),%edi
mov    -0xa8(%rbp),%rdx
mov    %rax,%rcx
lea    0xc87(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   10e0 <usage@plt>
mov    -0x38(%rbp),%edi
call   1080 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    13b7 <main+0x1a7>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
lea    0xc58(%rip),%rsi
call   1130 <strstr@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    13eb <main+0x1db>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0xb0(%rbp)
mov    -0x48(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xb0(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
cltq
add    %rax,%rdi
lea    0xc03(%rip),%rsi
call   1130 <strstr@plt>
mov    %rax,-0x58(%rbp)
cmp    $0x0,%rax
jne    1446 <main+0x236>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0xb4(%rbp)
mov    -0x58(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xb4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xbb5(%rip),%rsi
call   1130 <strstr@plt>
mov    %rax,-0x68(%rbp)
cmp    $0x0,%rax
jne    1496 <main+0x286>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0xbc(%rbp)
mov    -0x68(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xbc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x6c(%rbp)
mov    -0x5c(%rbp),%eax
sub    -0x4c(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%eax
mov    %eax,-0xb8(%rbp)
lea    0xb4f(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xb8(%rbp),%eax
cmp    %ecx,%eax
jg     14f6 <main+0x2e6>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x20(%rbp),%rdi
movslq -0x5c(%rbp),%rax
add    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%eax
mov    %eax,-0xc0(%rbp)
lea    0xb10(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xc0(%rbp),%eax
cmp    %ecx,%eax
jg     153b <main+0x32b>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x20(%rbp),%rdi
movslq -0x6c(%rbp),%rax
add    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,-0x70(%rbp)
mov    -0x70(%rbp),%eax
mov    %eax,-0xc4(%rbp)
lea    0xacd(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xc4(%rbp),%eax
cmp    %ecx,%eax
jg     1580 <main+0x370>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
lea    0xa81(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,-0xd0(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xd0(%rbp),%eax
add    %ecx,%eax
sub    -0x60(%rbp),%eax
mov    %eax,-0xcc(%rbp)
lea    0xa7e(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xcc(%rbp),%eax
add    %ecx,%eax
add    -0x50(%rbp),%eax
mov    %eax,-0xc8(%rbp)
lea    0xa6a(%rip),%rdi
call   1060 <strlen@plt>
mov    -0xc8(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xa10(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x5c(%rbp),%edx
call   1090 <strncat@plt>
mov    -0x28(%rbp),%rdi
lea    0xa1b(%rip),%rsi
call   1110 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x50(%rbp),%edx
call   1090 <strncat@plt>
mov    -0x28(%rbp),%rdi
lea    0xa06(%rip),%rsi
call   1110 <strcat@plt>
mov    -0x20(%rbp),%rdi
movslq -0x6c(%rbp),%rax
add    %rax,%rdi
lea    0x9f5(%rip),%rsi
call   1130 <strstr@plt>
mov    %rax,-0x78(%rbp)
cmp    $0x0,%rax
jne    166f <main+0x45f>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x20(%rbp),%rdi
movslq -0x6c(%rbp),%rax
add    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,-0xd4(%rbp)
mov    -0x78(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xd4(%rbp),%eax
sub    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x6c(%rbp),%eax
add    -0x7c(%rbp),%eax
cltq
add    %rax,%rdi
lea    0x990(%rip),%rsi
call   1130 <strstr@plt>
mov    %rax,-0x88(%rbp)
cmp    $0x0,%rax
jne    16d7 <main+0x4c7>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x20(%rbp),%rdi
mov    -0x6c(%rbp),%eax
add    -0x7c(%rbp),%eax
cltq
add    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,-0xd8(%rbp)
mov    -0x88(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xd8(%rbp),%eax
sub    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x6c(%rbp),%eax
add    -0x7c(%rbp),%eax
add    -0x8c(%rbp),%eax
cltq
add    %rax,%rdi
lea    0x8fd(%rip),%rsi
call   1130 <strstr@plt>
mov    %rax,-0x98(%rbp)
cmp    $0x0,%rax
jne    174f <main+0x53f>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x20(%rbp),%rdi
mov    -0x6c(%rbp),%eax
add    -0x7c(%rbp),%eax
cltq
add    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,-0xdc(%rbp)
mov    -0x88(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xdc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x80(%rbp)
cmpl   $0x1,-0x80(%rbp)
jge    1799 <main+0x589>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x20(%rbp),%rdi
mov    -0x6c(%rbp),%eax
add    -0x7c(%rbp),%eax
add    -0x8c(%rbp),%eax
cltq
add    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,-0xe0(%rbp)
mov    -0x98(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xe0(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x90(%rbp)
cmpl   $0x1,-0x90(%rbp)
jge    17ef <main+0x5df>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x80(%rbp),%eax
mov    %eax,-0xe8(%rbp)
lea    0x847(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xe8(%rbp),%eax
add    %ecx,%eax
add    -0x90(%rbp),%eax
mov    %eax,-0xe4(%rbp)
lea    0x827(%rip),%rdi
call   1060 <strlen@plt>
mov    -0xe4(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x6c(%rbp),%eax
add    -0x7c(%rbp),%eax
cltq
add    %rax,%rsi
mov    -0x80(%rbp),%edx
call   1090 <strncat@plt>
mov    -0x30(%rbp),%rdi
lea    0x7df(%rip),%rsi
call   1110 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x6c(%rbp),%eax
add    -0x7c(%rbp),%eax
add    -0x8c(%rbp),%eax
cltq
add    %rax,%rsi
mov    -0x90(%rbp),%edx
call   1090 <strncat@plt>
mov    -0x30(%rbp),%rdi
lea    0x7ad(%rip),%rsi
call   1110 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    0x2715(%rip),%rax
mov    (%rax),%esi
call   1100 <open@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
jge    1910 <main+0x700>
mov    0x2713(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xf4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0xf0(%rbp)
mov    0x26f1(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0xf4(%rbp),%edi
mov    -0xf0(%rbp),%rdx
mov    %rax,%rcx
lea    0x74e(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   10e0 <usage@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x104(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x100(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x104(%rbp),%edi
mov    -0x100(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    $0x0,%rax
jge    199d <main+0x78d>
mov    0x2686(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x114(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x110(%rbp)
mov    0x2664(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x114(%rbp),%edi
mov    -0x110(%rbp),%rdx
mov    %rax,%rcx
lea    0x6d7(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   10e0 <usage@plt>
mov    -0x3c(%rbp),%edi
call   10a0 <close@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r12
mov    %edi,%ebp
lea    0xdcb(%rip),%r14
lea    0x2b8f(%rip),%rbx
jmp    1267 <main+0x47>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
xor    %esi,%esi
call   10f0 <usage@plt>
mov    %r12,%rdi
mov    $0x1,%esi
call   10f0 <usage@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1070 <getopt_long@plt>
cmp    $0x68,%al
je     1250 <main+0x30>
cmp    $0xff,%al
jne    125a <main+0x3a>
mov    0x2d5f(%rip),%rbx
mov    (%rbx),%eax
cmp    %ebp,%eax
jl     129e <main+0x7e>
mov    %r12,%rdi
mov    $0x1,%esi
call   10f0 <usage@plt>
mov    (%rbx),%eax
lea    0x1(%rax),%ecx
mov    %ecx,(%rbx)
cltq
mov    (%r12,%rax,8),%r13
test   %r13,%r13
jne    12bb <main+0x9b>
mov    %r12,%rdi
mov    $0x1,%esi
call   10f0 <usage@plt>
lea    0xd46(%rip),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1060 <strlen@plt>
lea    (%rax,%rbp,1),%edi
add    $0x1,%edi
call   10e0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1120 <strcat@plt>
lea    0x18(%rsp),%rsi
mov    %rbp,%rdi
call   10d0 <stat@plt>
test   %rax,%rax
jns    1342 <main+0x122>
mov    0x2cc7(%rip),%rax
mov    (%rax),%ebx
mov    0x2cb6(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xce5(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
call   10c0 <fprintf@plt>
mov    %r12,%rdi
mov    $0x1,%esi
call   10f0 <usage@plt>
mov    0x18(%rsp),%edi
call   1090 <S_ISDIR@plt>
test   %eax,%eax
jne    135a <main+0x13a>
mov    %r12,%rdi
mov    %r13,%rsi
call   1100 <invalid@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
lea    0xcba(%rip),%rsi
mov    %r13,%rdi
call   1140 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1384 <main+0x164>
mov    %r12,%rdi
mov    %r13,%rsi
call   1100 <invalid@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdi
call   1060 <strlen@plt>
sub    %eax,%ebp
mov    %ebp,(%rsp)
movslq %ebp,%rax
lea    (%rax,%r13,1),%rdi
add    $0x1,%rdi
mov    $0x2f,%esi
call   1080 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    13c8 <main+0x1a8>
mov    %r12,%rdi
mov    %r13,%rsi
call   1100 <invalid@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1060 <strlen@plt>
sub    %eax,%r15d
lea    0xc46(%rip),%rsi
mov    %r13,%rdi
call   1140 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1400 <main+0x1e0>
mov    %r12,%rdi
mov    %r13,%rsi
call   1100 <invalid@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
mov    %r15d,%r14d
sub    (%rsp),%r14d
lea    0xc01(%rip),%rdi
call   1060 <strlen@plt>
mov    %r14d,0x24(%rsp)
cmp    %eax,%r14d
jg     143c <main+0x21c>
mov    %r12,%rdi
mov    %r13,%rsi
call   1100 <invalid@plt>
sub    %ebx,%ebp
movslq %r15d,%rdi
add    %r13,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
lea    0xbd7(%rip),%rdi
call   1060 <strlen@plt>
mov    %ebx,0x20(%rsp)
cmp    %eax,%ebx
jg     146a <main+0x24a>
mov    %r12,%rdi
mov    %r13,%rsi
call   1100 <invalid@plt>
mov    %r15d,0x10(%rsp)
movslq %ebp,%r14
add    %r13,%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
lea    0xba5(%rip),%rdi
call   1060 <strlen@plt>
cmp    %eax,%ebx
jg     149a <main+0x27a>
mov    %r12,%rdi
mov    %r13,%rsi
call   1100 <invalid@plt>
lea    0xb67(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,0x1c(%rsp)
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
lea    0xb78(%rip),%rdi
call   1060 <strlen@plt>
mov    %r13,(%rsp)
mov    %eax,%r13d
lea    0xb70(%rip),%rdi
call   1060 <strlen@plt>
mov    0x24(%rsp),%r15d
mov    %r15d,%ecx
sub    0x20(%rsp),%ecx
add    0x1c(%rsp),%ecx
add    %ebx,%ecx
add    %r13d,%ecx
mov    (%rsp),%r13
lea    (%rax,%rcx,1),%edi
add    $0x1,%edi
call   10e0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
lea    0xb04(%rip),%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    0x10(%rsp),%edx
call   10a0 <strncat@plt>
mov    %rbx,%rdi
lea    0xb11(%rip),%rsi
call   1120 <strcat@plt>
mov    %rbx,%rdi
mov    0x8(%rsp),%rsi
mov    %r15d,%edx
call   10a0 <strncat@plt>
mov    %rbx,0x10(%rsp)
mov    %rbx,%rdi
lea    0xaf8(%rip),%rsi
call   1120 <strcat@plt>
mov    %r14,%rdi
mov    $0x3a,%esi
call   1080 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    156b <main+0x34b>
mov    %r12,%rdi
mov    %r13,%rsi
call   1100 <invalid@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1060 <strlen@plt>
add    %r14d,%ebp
sub    %eax,%ebp
add    $0x1,%ebp
movslq %ebp,%rbx
add    %r13,%rbx
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1080 <strchr@plt>
mov    %rax,%r14
test   %rax,%rax
jne    15ac <main+0x38c>
mov    %r12,%rdi
mov    %r13,%rsi
call   1100 <invalid@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %rbx,0x8(%rsp)
mov    %eax,%ebx
mov    %r14,%rdi
call   1060 <strlen@plt>
add    %ebx,%ebp
sub    %eax,%ebp
add    $0x1,%ebp
movslq %ebp,%r15
add    %r13,%r15
mov    %r15,%rdi
mov    $0x2f,%esi
call   1080 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    15f0 <main+0x3d0>
mov    %r12,%rdi
mov    %r13,%rsi
call   1100 <invalid@plt>
mov    0x8(%rsp),%rdi
call   1060 <strlen@plt>
mov    %eax,%r13d
mov    %r14,%rdi
call   1060 <strlen@plt>
sub    %eax,%r13d
jg     1616 <main+0x3f6>
mov    %r12,%rdi
mov    (%rsp),%rsi
call   1100 <invalid@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1060 <strlen@plt>
sub    %eax,%r14d
jg     163a <main+0x41a>
mov    %r12,%rdi
mov    (%rsp),%rsi
call   1100 <invalid@plt>
lea    0xa03(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
lea    0x9f7(%rip),%rdi
call   1060 <strlen@plt>
add    %r13d,%ebx
add    %r14d,%ebx
lea    (%rax,%rbx,1),%edi
add    $0x1,%edi
call   10e0 <malloc@plt>
mov    %rax,%rbp
movb   $0x0,(%rax)
mov    %rax,%rdi
mov    0x8(%rsp),%rsi
mov    %r13d,%edx
call   10a0 <strncat@plt>
mov    %rbp,%rdi
lea    0x9bf(%rip),%rsi
call   1120 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   10a0 <strncat@plt>
mov    %rbp,%rdi
lea    0x9a4(%rip),%rsi
call   1120 <strcat@plt>
mov    0x2912(%rip),%rax
mov    (%rax),%esi
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1110 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    16fe <main+0x4de>
mov    0x290d(%rip),%rax
mov    (%rax),%r15d
mov    0x28fb(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0x966(%rip),%rsi
mov    %r15d,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   10c0 <fprintf@plt>
mov    %r12,%rdi
mov    $0x1,%esi
call   10f0 <usage@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <write@plt>
test   %rax,%rax
jns    1752 <main+0x532>
mov    0x28b9(%rip),%rax
mov    (%rax),%r15d
mov    0x28a7(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0x928(%rip),%rsi
mov    %r15d,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   10c0 <fprintf@plt>
mov    %r12,%rdi
mov    $0x1,%esi
call   10f0 <usage@plt>
mov    %r14d,%edi
call   10b0 <close@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32, i32 }
%struct.stat = type { i32 }
@main.longopts = internal constant [2 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8 -128, i32 0, i32 104 }, %struct.option { i8* null, i8 -128, i32 0, i32 48 }]
@.str = [5 x i8] c"help\00"
@.str.1 = [3 x i8] c"rh\00"
@optind = global i32 0
@.str.2 = [5 x i8] c"/sys\00"
@stderr = global i32 0
@.str.3 = [22 x i8] c"Cannot stat '%s': %s\0A\00"
@errno = global i32 0
@.str.4 = [6 x i8] c"/host\00"
@.str.5 = [2 x i8] c"/\00"
@.str.6 = [8 x i8] c"/target\00"
@.str.7 = [11 x i8] c"/scsi_host\00"
@.str.8 = [6 x i8] c"/scan\00"
@.str.9 = [2 x i8] c":\00"
@.str.10 = [2 x i8] c" \00"
@.str.11 = [3 x i8] c" -\00"
@O_WRONLY = global i32 0
@.str.12 = [22 x i8] c"Cannot open '%s': %s\0A\00"
@.str.13 = [23 x i8] c"Cannot write '%s': %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.stat
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i8*
%19 = alloca i32
%20 = alloca i32
%21 = alloca i8*
%22 = alloca i32
%23 = alloca i32
%24 = alloca i8*
%25 = alloca i32
%26 = alloca i32
%27 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %28
28: ; preds = %43, %2
%29 = load i32, i32* %4
%30 = load i8**, i8*** %5
%31 = call signext i8 @getopt_long(i32 %29, i8** %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.option* getelementptr inbounds ([2 x %struct.option], [2 x %struct.option]* @main.longopts, i64 0, i64 0), i32* null)
store i8 %31, i8* %6
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, -1
br i1 %33, label %34, label %44
34: ; preds = %28
%35 = load i8, i8* %6
%36 = sext i8 %35 to i32
switch i32 %36, label %40 [
i32 104, label %37
]
37: ; preds = %34
%38 = load i8**, i8*** %5
%39 = call i32 @usage(i8** %38, i32 0)
br label %40
40: ; preds = %34, %37
%41 = load i8**, i8*** %5
%42 = call i32 @usage(i8** %41, i32 1)
br label %43
43: ; preds = %40
br label %28
44: ; preds = %28
%45 = load i32, i32* @optind
%46 = load i32, i32* %4
%47 = icmp sge i32 %45, %46
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = load i8**, i8*** %5
%50 = call i32 @usage(i8** %49, i32 1)
br label %51
51: ; preds = %48, %44
%52 = load i8**, i8*** %5
%53 = load i32, i32* @optind
%54 = add nsw i32 %53, 1
store i32 %54, i32* @optind
%55 = sext i32 %53 to i64
%56 = getelementptr inbounds i8*, i8** %52, i64 %55
%57 = load i8*, i8** %56
store i8* %57, i8** %7
%58 = load i8*, i8** %7
%59 = icmp eq i8* %58, null
br i1 %59, label %60, label %63
60: ; preds = %51
%61 = load i8**, i8*** %5
%62 = call i32 @usage(i8** %61, i32 1)
br label %63
63: ; preds = %60, %51
%64 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%65 = load i8*, i8** %7
%66 = call i32 @strlen(i8* %65)
%67 = add nsw i32 %64, %66
%68 = add nsw i32 %67, 1
%69 = call i8* @malloc(i32 %68)
store i8* %69, i8** %8
%70 = load i8*, i8** %8
%71 = call i32 @strcpy(i8* %70, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%72 = load i8*, i8** %8
%73 = load i8*, i8** %7
%74 = call i32 @strcat(i8* %72, i8* %73)
%75 = load i8*, i8** %8
%76 = call i64 @stat(i8* %75, %struct.stat* %10)
%77 = icmp slt i64 %76, 0
br i1 %77, label %78, label %86
78: ; preds = %63
%79 = load i32, i32* @stderr
%80 = load i8*, i8** %8
%81 = load i32, i32* @errno
%82 = call i8* @strerror(i32 %81)
%83 = call i32 @fprintf(i32 %79, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %80, i8* %82)
%84 = load i8**, i8*** %5
%85 = call i32 @usage(i8** %84, i32 1)
br label %86
86: ; preds = %78, %63
%87 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%88 = load i32, i32* %87
%89 = call i32 @S_ISDIR(i32 %88)
%90 = icmp ne i32 %89, 0
br i1 %90, label %95, label %91
91: ; preds = %86
%92 = load i8**, i8*** %5
%93 = load i8*, i8** %7
%94 = call i32 @invalid(i8** %92, i8* %93)
br label %95
95: ; preds = %91, %86
%96 = load i8*, i8** %8
%97 = call i32 @free(i8* %96)
%98 = load i8*, i8** %7
%99 = call i8* @strstr(i8* %98, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i8* %99, i8** %12
%100 = icmp eq i8* %99, null
br i1 %100, label %101, label %105
101: ; preds = %95
%102 = load i8**, i8*** %5
%103 = load i8*, i8** %7
%104 = call i32 @invalid(i8** %102, i8* %103)
br label %105
105: ; preds = %101, %95
%106 = load i8*, i8** %7
%107 = call i32 @strlen(i8* %106)
%108 = load i8*, i8** %12
%109 = call i32 @strlen(i8* %108)
%110 = sub nsw i32 %107, %109
store i32 %110, i32* %13
%111 = load i8*, i8** %7
%112 = load i32, i32* %13
%113 = add nsw i32 %112, 1
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds i8, i8* %111, i64 %114
%116 = call i8* @strstr(i8* %115, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %116, i8** %15
%117 = icmp eq i8* %116, null
br i1 %117, label %118, label %122
118: ; preds = %105
%119 = load i8**, i8*** %5
%120 = load i8*, i8** %7
%121 = call i32 @invalid(i8** %119, i8* %120)
br label %122
122: ; preds = %118, %105
%123 = load i8*, i8** %7
%124 = call i32 @strlen(i8* %123)
%125 = load i8*, i8** %15
%126 = call i32 @strlen(i8* %125)
%127 = sub nsw i32 %124, %126
store i32 %127, i32* %16
%128 = load i8*, i8** %7
%129 = call i8* @strstr(i8* %128, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
store i8* %129, i8** %18
%130 = icmp eq i8* %129, null
br i1 %130, label %131, label %135
131: ; preds = %122
%132 = load i8**, i8*** %5
%133 = load i8*, i8** %7
%134 = call i32 @invalid(i8** %132, i8* %133)
br label %135
135: ; preds = %131, %122
%136 = load i8*, i8** %7
%137 = call i32 @strlen(i8* %136)
%138 = load i8*, i8** %18
%139 = call i32 @strlen(i8* %138)
%140 = sub nsw i32 %137, %139
store i32 %140, i32* %19
%141 = load i32, i32* %16
%142 = load i32, i32* %13
%143 = sub nsw i32 %141, %142
store i32 %143, i32* %14
%144 = load i32, i32* %14
%145 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%146 = icmp sle i32 %144, %145
br i1 %146, label %147, label %151
147: ; preds = %135
%148 = load i8**, i8*** %5
%149 = load i8*, i8** %7
%150 = call i32 @invalid(i8** %148, i8* %149)
br label %151
151: ; preds = %147, %135
%152 = load i8*, i8** %7
%153 = load i32, i32* %16
%154 = sext i32 %153 to i64
%155 = getelementptr inbounds i8, i8* %152, i64 %154
%156 = call i32 @strlen(i8* %155)
store i32 %156, i32* %17
%157 = load i32, i32* %17
%158 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%159 = icmp sle i32 %157, %158
br i1 %159, label %160, label %164
160: ; preds = %151
%161 = load i8**, i8*** %5
%162 = load i8*, i8** %7
%163 = call i32 @invalid(i8** %161, i8* %162)
br label %164
164: ; preds = %160, %151
%165 = load i8*, i8** %7
%166 = load i32, i32* %19
%167 = sext i32 %166 to i64
%168 = getelementptr inbounds i8, i8* %165, i64 %167
%169 = call i32 @strlen(i8* %168)
store i32 %169, i32* %20
%170 = load i32, i32* %20
%171 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%172 = icmp sle i32 %170, %171
br i1 %172, label %173, label %177
173: ; preds = %164
%174 = load i8**, i8*** %5
%175 = load i8*, i8** %7
%176 = call i32 @invalid(i8** %174, i8* %175)
br label %177
177: ; preds = %173, %164
%178 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%179 = load i8*, i8** %7
%180 = call i32 @strlen(i8* %179)
%181 = add nsw i32 %178, %180
%182 = load i32, i32* %17
%183 = sub nsw i32 %181, %182
%184 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%185 = add nsw i32 %183, %184
%186 = load i32, i32* %14
%187 = add nsw i32 %185, %186
%188 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%189 = add nsw i32 %187, %188
%190 = add nsw i32 %189, 1
%191 = call i8* @malloc(i32 %190)
store i8* %191, i8** %8
%192 = load i8*, i8** %8
%193 = call i32 @strcpy(i8* %192, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%194 = load i8*, i8** %8
%195 = load i8*, i8** %7
%196 = load i32, i32* %16
%197 = call i32 @strncat(i8* %194, i8* %195, i32 %196)
%198 = load i8*, i8** %8
%199 = call i32 @strcat(i8* %198, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%200 = load i8*, i8** %8
%201 = load i8*, i8** %12
%202 = load i32, i32* %14
%203 = call i32 @strncat(i8* %200, i8* %201, i32 %202)
%204 = load i8*, i8** %8
%205 = call i32 @strcat(i8* %204, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%206 = load i8*, i8** %7
%207 = load i32, i32* %19
%208 = sext i32 %207 to i64
%209 = getelementptr inbounds i8, i8* %206, i64 %208
%210 = call i8* @strstr(i8* %209, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i8* %210, i8** %21
%211 = icmp eq i8* %210, null
br i1 %211, label %212, label %216
212: ; preds = %177
%213 = load i8**, i8*** %5
%214 = load i8*, i8** %7
%215 = call i32 @invalid(i8** %213, i8* %214)
br label %216
216: ; preds = %212, %177
%217 = load i8*, i8** %7
%218 = load i32, i32* %19
%219 = sext i32 %218 to i64
%220 = getelementptr inbounds i8, i8* %217, i64 %219
%221 = call i32 @strlen(i8* %220)
%222 = load i8*, i8** %21
%223 = call i32 @strlen(i8* %222)
%224 = sub nsw i32 %221, %223
%225 = add nsw i32 %224, 1
store i32 %225, i32* %22
%226 = load i8*, i8** %7
%227 = load i32, i32* %19
%228 = load i32, i32* %22
%229 = add nsw i32 %227, %228
%230 = sext i32 %229 to i64
%231 = getelementptr inbounds i8, i8* %226, i64 %230
%232 = call i8* @strstr(i8* %231, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i8* %232, i8** %24
%233 = icmp eq i8* %232, null
br i1 %233, label %234, label %238
234: ; preds = %216
%235 = load i8**, i8*** %5
%236 = load i8*, i8** %7
%237 = call i32 @invalid(i8** %235, i8* %236)
br label %238
238: ; preds = %234, %216
%239 = load i8*, i8** %7
%240 = load i32, i32* %19
%241 = load i32, i32* %22
%242 = add nsw i32 %240, %241
%243 = sext i32 %242 to i64
%244 = getelementptr inbounds i8, i8* %239, i64 %243
%245 = call i32 @strlen(i8* %244)
%246 = load i8*, i8** %24
%247 = call i32 @strlen(i8* %246)
%248 = sub nsw i32 %245, %247
%249 = add nsw i32 %248, 1
store i32 %249, i32* %25
%250 = load i8*, i8** %7
%251 = load i32, i32* %19
%252 = load i32, i32* %22
%253 = add nsw i32 %251, %252
%254 = load i32, i32* %25
%255 = add nsw i32 %253, %254
%256 = sext i32 %255 to i64
%257 = getelementptr inbounds i8, i8* %250, i64 %256
%258 = call i8* @strstr(i8* %257, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %258, i8** %27
%259 = icmp eq i8* %258, null
br i1 %259, label %260, label %264
260: ; preds = %238
%261 = load i8**, i8*** %5
%262 = load i8*, i8** %7
%263 = call i32 @invalid(i8** %261, i8* %262)
br label %264
264: ; preds = %260, %238
%265 = load i8*, i8** %7
%266 = load i32, i32* %19
%267 = load i32, i32* %22
%268 = add nsw i32 %266, %267
%269 = sext i32 %268 to i64
%270 = getelementptr inbounds i8, i8* %265, i64 %269
%271 = call i32 @strlen(i8* %270)
%272 = load i8*, i8** %24
%273 = call i32 @strlen(i8* %272)
%274 = sub nsw i32 %271, %273
store i32 %274, i32* %23
%275 = load i32, i32* %23
%276 = icmp slt i32 %275, 1
br i1 %276, label %277, label %281
277: ; preds = %264
%278 = load i8**, i8*** %5
%279 = load i8*, i8** %7
%280 = call i32 @invalid(i8** %278, i8* %279)
br label %281
281: ; preds = %277, %264
%282 = load i8*, i8** %7
%283 = load i32, i32* %19
%284 = load i32, i32* %22
%285 = add nsw i32 %283, %284
%286 = load i32, i32* %25
%287 = add nsw i32 %285, %286
%288 = sext i32 %287 to i64
%289 = getelementptr inbounds i8, i8* %282, i64 %288
%290 = call i32 @strlen(i8* %289)
%291 = load i8*, i8** %27
%292 = call i32 @strlen(i8* %291)
%293 = sub nsw i32 %290, %292
store i32 %293, i32* %26
%294 = load i32, i32* %26
%295 = icmp slt i32 %294, 1
br i1 %295, label %296, label %300
296: ; preds = %281
%297 = load i8**, i8*** %5
%298 = load i8*, i8** %7
%299 = call i32 @invalid(i8** %297, i8* %298)
br label %300
300: ; preds = %296, %281
%301 = load i32, i32* %23
%302 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%303 = add nsw i32 %301, %302
%304 = load i32, i32* %26
%305 = add nsw i32 %303, %304
%306 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%307 = add nsw i32 %305, %306
%308 = add nsw i32 %307, 1
%309 = call i8* @malloc(i32 %308)
store i8* %309, i8** %9
%310 = load i8*, i8** %9
%311 = getelementptr inbounds i8, i8* %310, i64 0
store i8 0, i8* %311
%312 = load i8*, i8** %9
%313 = load i8*, i8** %7
%314 = load i32, i32* %19
%315 = load i32, i32* %22
%316 = add nsw i32 %314, %315
%317 = sext i32 %316 to i64
%318 = getelementptr inbounds i8, i8* %313, i64 %317
%319 = load i32, i32* %23
%320 = call i32 @strncat(i8* %312, i8* %318, i32 %319)
%321 = load i8*, i8** %9
%322 = call i32 @strcat(i8* %321, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%323 = load i8*, i8** %9
%324 = load i8*, i8** %7
%325 = load i32, i32* %19
%326 = load i32, i32* %22
%327 = add nsw i32 %325, %326
%328 = load i32, i32* %25
%329 = add nsw i32 %327, %328
%330 = sext i32 %329 to i64
%331 = getelementptr inbounds i8, i8* %324, i64 %330
%332 = load i32, i32* %26
%333 = call i32 @strncat(i8* %323, i8* %331, i32 %332)
%334 = load i8*, i8** %9
%335 = call i32 @strcat(i8* %334, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%336 = load i8*, i8** %8
%337 = load i32, i32* @O_WRONLY
%338 = call i32 @open(i8* %336, i32 %337)
store i32 %338, i32* %11
%339 = icmp slt i32 %338, 0
br i1 %339, label %340, label %348
340: ; preds = %300
%341 = load i32, i32* @stderr
%342 = load i8*, i8** %8
%343 = load i32, i32* @errno
%344 = call i8* @strerror(i32 %343)
%345 = call i32 @fprintf(i32 %341, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i8* %342, i8* %344)
%346 = load i8**, i8*** %5
%347 = call i32 @usage(i8** %346, i32 1)
br label %348
348: ; preds = %340, %300
%349 = load i32, i32* %11
%350 = load i8*, i8** %9
%351 = load i8*, i8** %9
%352 = call i32 @strlen(i8* %351)
%353 = call i64 @write(i32 %349, i8* %350, i32 %352)
%354 = icmp slt i64 %353, 0
br i1 %354, label %355, label %363
355: ; preds = %348
%356 = load i32, i32* @stderr
%357 = load i8*, i8** %8
%358 = load i32, i32* @errno
%359 = call i8* @strerror(i32 %358)
%360 = call i32 @fprintf(i32 %356, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0), i8* %357, i8* %359)
%361 = load i8**, i8*** %5
%362 = call i32 @usage(i8** %361, i32 1)
br label %363
363: ; preds = %355, %348
%364 = load i32, i32* %11
%365 = call i32 @close(i32 %364)
%366 = load i8*, i8** %8
%367 = call i32 @free(i8* %366)
%368 = load i8*, i8** %9
%369 = call i32 @free(i8* %368)
ret i32 0
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32, i32 }
%struct.stat = type { i32 }
@main.longopts = internal constant [2 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8 -128, i32 0, i32 104 }, %struct.option { i8* null, i8 -128, i32 0, i32 48 }]
@.str = [5 x i8] c"help\00"
@.str.1 = [3 x i8] c"rh\00"
@optind = global i32 0
@.str.2 = [5 x i8] c"/sys\00"
@stderr = global i32 0
@.str.3 = [22 x i8] c"Cannot stat '%s': %s\0A\00"
@errno = global i32 0
@.str.4 = [6 x i8] c"/host\00"
@.str.5 = [2 x i8] c"/\00"
@.str.6 = [8 x i8] c"/target\00"
@.str.7 = [11 x i8] c"/scsi_host\00"
@.str.8 = [6 x i8] c"/scan\00"
@.str.10 = [2 x i8] c" \00"
@.str.11 = [3 x i8] c" -\00"
@O_WRONLY = global i32 0
@.str.12 = [22 x i8] c"Cannot open '%s': %s\0A\00"
@.str.13 = [23 x i8] c"Cannot write '%s': %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
br label %5
5: ; preds = %9, %2
%6 = tail call signext i8 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.option* getelementptr inbounds ([2 x %struct.option], [2 x %struct.option]* @main.longopts, i64 0, i64 0), i32* null)
switch i8 %6, label %9 [
i8 -1, label %11
i8 104, label %7
]
7: ; preds = %5
%8 = tail call i32 @usage(i8** %1, i32 0)
br label %9
9: ; preds = %5, %7
%10 = tail call i32 @usage(i8** %1, i32 1)
br label %5
11: ; preds = %5
%12 = load i32, i32* @optind
%13 = icmp slt i32 %12, %0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = tail call i32 @usage(i8** %1, i32 1)
%16 = load i32, i32* @optind
br label %17
17: ; preds = %14, %11
%18 = phi i32 [ %16, %14 ], [ %12, %11 ]
%19 = add nsw i32 %18, 1
store i32 %19, i32* @optind
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds i8*, i8** %1, i64 %20
%22 = load i8*, i8** %21
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = tail call i32 @usage(i8** %1, i32 1)
br label %26
26: ; preds = %24, %17
%27 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%28 = tail call i32 @strlen(i8* %22)
%29 = add i32 %27, 1
%30 = add i32 %29, %28
%31 = tail call i8* @malloc(i32 %30)
%32 = tail call i32 @strcpy(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%33 = tail call i32 @strcat(i8* %31, i8* %22)
%34 = call i64 @stat(i8* %31, %struct.stat* %3)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %26
%37 = load i32, i32* @stderr
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %31, i8* %39)
%41 = call i32 @usage(i8** %1, i32 1)
br label %42
42: ; preds = %36, %26
%43 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%44 = load i32, i32* %43
%45 = call i32 @S_ISDIR(i32 %44)
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = call i32 @invalid(i8** %1, i8* %22)
br label %49
49: ; preds = %47, %42
%50 = call i32 @free(i8* %31)
%51 = call i8* @strstr(i8* dereferenceable(1) %22, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%52 = icmp eq i8* %51, null
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 @invalid(i8** %1, i8* %22)
br label %55
55: ; preds = %53, %49
%56 = call i32 @strlen(i8* %22)
%57 = call i32 @strlen(i8* %51)
%58 = sub nsw i32 %56, %57
%59 = add nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %22, i64 %60
%62 = call i8* @strchr(i8* dereferenceable(1) %61, i32 47)
%63 = icmp eq i8* %62, null
br i1 %63, label %64, label %66
64: ; preds = %55
%65 = call i32 @invalid(i8** %1, i8* %22)
br label %66
66: ; preds = %64, %55
%67 = call i32 @strlen(i8* %22)
%68 = call i32 @strlen(i8* %62)
%69 = sub nsw i32 %67, %68
%70 = call i8* @strstr(i8* dereferenceable(1) %22, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%71 = icmp eq i8* %70, null
br i1 %71, label %72, label %74
72: ; preds = %66
%73 = call i32 @invalid(i8** %1, i8* %22)
br label %74
74: ; preds = %72, %66
%75 = call i32 @strlen(i8* %22)
%76 = call i32 @strlen(i8* %70)
%77 = sub nsw i32 %75, %76
%78 = sub nsw i32 %69, %58
%79 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%80 = icmp sgt i32 %78, %79
br i1 %80, label %83, label %81
81: ; preds = %74
%82 = call i32 @invalid(i8** %1, i8* %22)
br label %83
83: ; preds = %81, %74
%84 = sext i32 %69 to i64
%85 = getelementptr inbounds i8, i8* %22, i64 %84
%86 = call i32 @strlen(i8* %85)
%87 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%88 = icmp sgt i32 %86, %87
br i1 %88, label %91, label %89
89: ; preds = %83
%90 = call i32 @invalid(i8** %1, i8* %22)
br label %91
91: ; preds = %89, %83
%92 = sext i32 %77 to i64
%93 = getelementptr inbounds i8, i8* %22, i64 %92
%94 = call i32 @strlen(i8* %93)
%95 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%96 = icmp sgt i32 %94, %95
br i1 %96, label %99, label %97
97: ; preds = %91
%98 = call i32 @invalid(i8** %1, i8* %22)
br label %99
99: ; preds = %97, %91
%100 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%101 = call i32 @strlen(i8* %22)
%102 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%103 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%104 = add i32 %78, 1
%105 = sub i32 %104, %86
%106 = add i32 %105, %100
%107 = add i32 %106, %101
%108 = add i32 %107, %102
%109 = add i32 %108, %103
%110 = call i8* @malloc(i32 %109)
%111 = call i32 @strcpy(i8* %110, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%112 = call i32 @strncat(i8* %110, i8* %22, i32 %69)
%113 = call i32 @strcat(i8* %110, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%114 = call i32 @strncat(i8* %110, i8* %51, i32 %78)
%115 = call i32 @strcat(i8* %110, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%116 = call i8* @strchr(i8* dereferenceable(1) %93, i32 58)
%117 = icmp eq i8* %116, null
br i1 %117, label %118, label %120
118: ; preds = %99
%119 = call i32 @invalid(i8** %1, i8* %22)
br label %120
120: ; preds = %118, %99
%121 = call i32 @strlen(i8* %93)
%122 = call i32 @strlen(i8* %116)
%123 = add i32 %77, 1
%124 = add i32 %123, %121
%125 = sub i32 %124, %122
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds i8, i8* %22, i64 %126
%128 = call i8* @strchr(i8* dereferenceable(1) %127, i32 58)
%129 = icmp eq i8* %128, null
br i1 %129, label %130, label %132
130: ; preds = %120
%131 = call i32 @invalid(i8** %1, i8* %22)
br label %132
132: ; preds = %130, %120
%133 = call i32 @strlen(i8* %127)
%134 = call i32 @strlen(i8* %128)
%135 = add i32 %125, 1
%136 = add i32 %135, %133
%137 = sub i32 %136, %134
%138 = sext i32 %137 to i64
%139 = getelementptr inbounds i8, i8* %22, i64 %138
%140 = call i8* @strchr(i8* dereferenceable(1) %139, i32 47)
%141 = icmp eq i8* %140, null
br i1 %141, label %142, label %144
142: ; preds = %132
%143 = call i32 @invalid(i8** %1, i8* %22)
br label %144
144: ; preds = %142, %132
%145 = call i32 @strlen(i8* %127)
%146 = call i32 @strlen(i8* %128)
%147 = sub nsw i32 %145, %146
%148 = icmp slt i32 %147, 1
br i1 %148, label %149, label %151
149: ; preds = %144
%150 = call i32 @invalid(i8** %1, i8* %22)
br label %151
151: ; preds = %149, %144
%152 = call i32 @strlen(i8* %139)
%153 = call i32 @strlen(i8* %140)
%154 = sub nsw i32 %152, %153
%155 = icmp slt i32 %154, 1
br i1 %155, label %156, label %158
156: ; preds = %151
%157 = call i32 @invalid(i8** %1, i8* %22)
br label %158
158: ; preds = %156, %151
%159 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%160 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%161 = add i32 %147, 1
%162 = add i32 %161, %154
%163 = add i32 %162, %159
%164 = add i32 %163, %160
%165 = call i8* @malloc(i32 %164)
store i8 0, i8* %165
%166 = call i32 @strncat(i8* %165, i8* %127, i32 %147)
%167 = call i32 @strcat(i8* %165, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%168 = call i32 @strncat(i8* %165, i8* %139, i32 %154)
%169 = call i32 @strcat(i8* %165, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%170 = load i32, i32* @O_WRONLY
%171 = call i32 @open(i8* %110, i32 %170)
%172 = icmp slt i32 %171, 0
br i1 %172, label %173, label %179
173: ; preds = %158
%174 = load i32, i32* @stderr
%175 = load i32, i32* @errno
%176 = call i8* @strerror(i32 %175)
%177 = call i32 @fprintf(i32 %174, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i8* %110, i8* %176)
%178 = call i32 @usage(i8** %1, i32 1)
br label %179
179: ; preds = %173, %158
%180 = call i32 @strlen(i8* %165)
%181 = call i64 @write(i32 %171, i8* %165, i32 %180)
%182 = icmp slt i64 %181, 0
br i1 %182, label %183, label %189
183: ; preds = %179
%184 = load i32, i32* @stderr
%185 = load i32, i32* @errno
%186 = call i8* @strerror(i32 %185)
%187 = call i32 @fprintf(i32 %184, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0), i8* %110, i8* %186)
%188 = call i32 @usage(i8** %1, i32 1)
br label %189
189: ; preds = %183, %179
%190 = call i32 @close(i32 %171)
%191 = call i32 @free(i8* %110)
%192 = call i32 @free(i8* %165)
ret i32 0
}