#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 *);
int 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) {
  int c;
  char *devpath;
  char *sysfs_path;
  char *sysfs_data;
  struct stat sysfs_stat;
  int fd;
  char *host_str;
  int host_pos;
  size_t host_len;
  char *host_next_str;
  int host_next_pos;
  size_t host_next_len;
  char *target_str;
  int target_pos;
  size_t 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    $0x150,%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    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1283 <main+0x73>
mov    -0x14(%rbp),%eax
sub    $0x68,%eax
jne    1270 <main+0x60>
jmp    1265 <main+0x55>
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    0x2d5e(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     12a3 <main+0x93>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   10e0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x2d3a(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    0x2d2c(%rip),%rdx
mov    %esi,(%rdx)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12e2 <main+0xd2>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   10e0 <usage@plt>
lea    0xd1f(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,-0xb4(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0xb4(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xcec(%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    1397 <main+0x187>
mov    0x2c8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0xc0(%rbp)
mov    0x2c6a(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0xc4(%rbp),%edi
mov    -0xc0(%rbp),%rdx
mov    %rax,%rcx
lea    0xc89(%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    13b5 <main+0x1a5>
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    0xc5a(%rip),%rsi
call   1130 <strstr@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    13e9 <main+0x1d9>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0xc8(%rbp)
mov    -0x48(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xc8(%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    0xc05(%rip),%rsi
call   1130 <strstr@plt>
mov    %rax,-0x60(%rbp)
cmp    $0x0,%rax
jne    1444 <main+0x234>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0xcc(%rbp)
mov    -0x60(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xcc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x64(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xbb7(%rip),%rsi
call   1130 <strstr@plt>
mov    %rax,-0x78(%rbp)
cmp    $0x0,%rax
jne    1494 <main+0x284>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0xdc(%rbp)
mov    -0x78(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xdc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x7c(%rbp)
mov    -0x64(%rbp),%eax
sub    -0x4c(%rbp),%eax
cltq
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0xd8(%rbp)
lea    0xb4c(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xd8(%rbp),%rax
movslq %ecx,%rcx
cmp    %rcx,%rax
ja     14fe <main+0x2ee>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x20(%rbp),%rdi
movslq -0x64(%rbp),%rax
add    %rax,%rdi
call   1060 <strlen@plt>
cltq
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
mov    %rax,-0xe8(%rbp)
lea    0xb03(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xe8(%rbp),%rax
movslq %ecx,%rcx
cmp    %rcx,%rax
ja     154d <main+0x33d>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x20(%rbp),%rdi
movslq -0x7c(%rbp),%rax
add    %rax,%rdi
call   1060 <strlen@plt>
cltq
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rax
mov    %rax,-0xf0(%rbp)
lea    0xab0(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xf0(%rbp),%rax
movslq %ecx,%rcx
cmp    %rcx,%rax
ja     15a2 <main+0x392>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
lea    0xa5f(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x104(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x104(%rbp),%eax
add    %ecx,%eax
cltq
sub    -0x70(%rbp),%rax
mov    %rax,-0x100(%rbp)
lea    0xa58(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x100(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    -0x58(%rbp),%rax
mov    %rax,-0xf8(%rbp)
lea    0xa3d(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xf8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0x9d9(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x64(%rbp),%edx
call   1090 <strncat@plt>
mov    -0x28(%rbp),%rdi
lea    0x9e4(%rip),%rsi
call   1110 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x58(%rbp),%rax
mov    %eax,%edx
call   1090 <strncat@plt>
mov    -0x28(%rbp),%rdi
lea    0x9cc(%rip),%rsi
call   1110 <strcat@plt>
mov    -0x20(%rbp),%rdi
movslq -0x7c(%rbp),%rax
add    %rax,%rdi
lea    0x9bb(%rip),%rsi
call   1130 <strstr@plt>
mov    %rax,-0x90(%rbp)
cmp    $0x0,%rax
jne    16ac <main+0x49c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x20(%rbp),%rdi
movslq -0x7c(%rbp),%rax
add    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,-0x108(%rbp)
mov    -0x90(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x108(%rbp),%eax
sub    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x7c(%rbp),%eax
add    -0x94(%rbp),%eax
cltq
add    %rax,%rdi
lea    0x94a(%rip),%rsi
call   1130 <strstr@plt>
mov    %rax,-0xa0(%rbp)
cmp    $0x0,%rax
jne    171d <main+0x50d>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x20(%rbp),%rdi
mov    -0x7c(%rbp),%eax
add    -0x94(%rbp),%eax
cltq
add    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,-0x10c(%rbp)
mov    -0xa0(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x10c(%rbp),%eax
sub    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x7c(%rbp),%eax
add    -0x94(%rbp),%eax
add    -0xa4(%rbp),%eax
cltq
add    %rax,%rdi
lea    0x8b1(%rip),%rsi
call   1130 <strstr@plt>
mov    %rax,-0xb0(%rbp)
cmp    $0x0,%rax
jne    179b <main+0x58b>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x20(%rbp),%rdi
mov    -0x7c(%rbp),%eax
add    -0x94(%rbp),%eax
cltq
add    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,-0x110(%rbp)
mov    -0xa0(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x110(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x98(%rbp)
cmpl   $0x1,-0x98(%rbp)
jge    17ee <main+0x5de>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x20(%rbp),%rdi
mov    -0x7c(%rbp),%eax
add    -0x94(%rbp),%eax
add    -0xa4(%rbp),%eax
cltq
add    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,-0x114(%rbp)
mov    -0xb0(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x114(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xa8(%rbp)
cmpl   $0x1,-0xa8(%rbp)
jge    1847 <main+0x637>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <invalid@plt>
mov    -0x98(%rbp),%eax
mov    %eax,-0x11c(%rbp)
lea    0x7ec(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x11c(%rbp),%eax
add    %ecx,%eax
add    -0xa8(%rbp),%eax
mov    %eax,-0x118(%rbp)
lea    0x7cc(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x118(%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    -0x7c(%rbp),%eax
add    -0x94(%rbp),%eax
cltq
add    %rax,%rsi
mov    -0x98(%rbp),%edx
call   1090 <strncat@plt>
mov    -0x30(%rbp),%rdi
lea    0x77e(%rip),%rsi
call   1110 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x7c(%rbp),%eax
add    -0x94(%rbp),%eax
add    -0xa4(%rbp),%eax
cltq
add    %rax,%rsi
mov    -0xa8(%rbp),%edx
call   1090 <strncat@plt>
mov    -0x30(%rbp),%rdi
lea    0x749(%rip),%rsi
call   1110 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    0x26b1(%rip),%rax
mov    (%rax),%esi
call   1100 <open@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
jge    1974 <main+0x764>
mov    0x26af(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x12c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    0x268d(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x12c(%rbp),%edi
mov    -0x128(%rbp),%rdx
mov    %rax,%rcx
lea    0x6ea(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   10e0 <usage@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x13c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x13c(%rbp),%edi
mov    -0x138(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    $0x0,%rax
jge    1a01 <main+0x7f1>
mov    0x2622(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    0x2600(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x14c(%rbp),%edi
mov    -0x148(%rbp),%rdx
mov    %rax,%rcx
lea    0x673(%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    $0x150,%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,%eax
je     1250 <main+0x30>
cmp    $0xffffffff,%eax
jne    125a <main+0x3a>
mov    0x2d5d(%rip),%rbx
mov    (%rbx),%eax
cmp    %ebp,%eax
jl     12a0 <main+0x80>
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    12bd <main+0x9d>
mov    %r12,%rdi
mov    $0x1,%esi
call   10f0 <usage@plt>
lea    0xd44(%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    1344 <main+0x124>
mov    0x2cc5(%rip),%rax
mov    (%rax),%ebx
mov    0x2cb4(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xce3(%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    135c <main+0x13c>
mov    %r12,%rdi
mov    %r13,%rsi
call   1100 <invalid@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
lea    0xcb8(%rip),%rsi
mov    %r13,%rdi
call   1140 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1386 <main+0x166>
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    13ca <main+0x1aa>
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    0xc44(%rip),%rsi
mov    %r13,%rdi
call   1140 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1402 <main+0x1e2>
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    0xbff(%rip),%rdi
call   1060 <strlen@plt>
mov    %r14d,0x24(%rsp)
cmp    %eax,%r14d
ja     143e <main+0x21e>
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    0xbd5(%rip),%rdi
call   1060 <strlen@plt>
mov    %ebx,0x20(%rsp)
cmp    %eax,%ebx
ja     146c <main+0x24c>
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    0xba3(%rip),%rdi
call   1060 <strlen@plt>
cmp    %eax,%ebx
ja     149c <main+0x27c>
mov    %r12,%rdi
mov    %r13,%rsi
call   1100 <invalid@plt>
lea    0xb65(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,0x1c(%rsp)
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
lea    0xb76(%rip),%rdi
call   1060 <strlen@plt>
mov    %r13,(%rsp)
mov    %eax,%r13d
lea    0xb6e(%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    0xb02(%rip),%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    0x10(%rsp),%edx
call   10a0 <strncat@plt>
mov    %rbx,%rdi
lea    0xb0f(%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    0xaf6(%rip),%rsi
call   1120 <strcat@plt>
mov    %r14,%rdi
mov    $0x3a,%esi
call   1080 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    156d <main+0x34d>
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    15ae <main+0x38e>
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    15f2 <main+0x3d2>
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     1618 <main+0x3f8>
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     163c <main+0x41c>
mov    %r12,%rdi
mov    (%rsp),%rsi
call   1100 <invalid@plt>
lea    0xa01(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
lea    0x9f5(%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    0x9bd(%rip),%rsi
call   1120 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   10a0 <strncat@plt>
mov    %rbp,%rdi
lea    0x9a2(%rip),%rsi
call   1120 <strcat@plt>
mov    0x2910(%rip),%rax
mov    (%rax),%esi
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1110 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    1700 <main+0x4e0>
mov    0x290b(%rip),%rax
mov    (%rax),%r15d
mov    0x28f9(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0x964(%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    1754 <main+0x534>
mov    0x28b7(%rip),%rax
mov    (%rax),%r15d
mov    0x28a5(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0x926(%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 i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.stat
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i64
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i64
%18 = alloca i8*
%19 = alloca i32
%20 = alloca i64
%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 = %41, %2
%29 = load i32, i32* %4
%30 = load i8**, i8*** %5
%31 = call i32 @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 i32 %31, i32* %6
%32 = icmp ne i32 %31, -1
br i1 %32, label %33, label %42
33: ; preds = %28
%34 = load i32, i32* %6
switch i32 %34, label %38 [
i32 104, label %35
]
35: ; preds = %33
%36 = load i8**, i8*** %5
%37 = call i32 @usage(i8** %36, i32 0)
br label %38
38: ; preds = %33, %35
%39 = load i8**, i8*** %5
%40 = call i32 @usage(i8** %39, i32 1)
br label %41
41: ; preds = %38
br label %28
42: ; preds = %28
%43 = load i32, i32* @optind
%44 = load i32, i32* %4
%45 = icmp sge i32 %43, %44
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = load i8**, i8*** %5
%48 = call i32 @usage(i8** %47, i32 1)
br label %49
49: ; preds = %46, %42
%50 = load i8**, i8*** %5
%51 = load i32, i32* @optind
%52 = add nsw i32 %51, 1
store i32 %52, i32* @optind
%53 = sext i32 %51 to i64
%54 = getelementptr inbounds i8*, i8** %50, i64 %53
%55 = load i8*, i8** %54
store i8* %55, i8** %7
%56 = load i8*, i8** %7
%57 = icmp eq i8* %56, null
br i1 %57, label %58, label %61
58: ; preds = %49
%59 = load i8**, i8*** %5
%60 = call i32 @usage(i8** %59, i32 1)
br label %61
61: ; preds = %58, %49
%62 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%63 = load i8*, i8** %7
%64 = call i32 @strlen(i8* %63)
%65 = add nsw i32 %62, %64
%66 = add nsw i32 %65, 1
%67 = call i8* @malloc(i32 %66)
store i8* %67, i8** %8
%68 = load i8*, i8** %8
%69 = call i32 @strcpy(i8* %68, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%70 = load i8*, i8** %8
%71 = load i8*, i8** %7
%72 = call i32 @strcat(i8* %70, i8* %71)
%73 = load i8*, i8** %8
%74 = call i64 @stat(i8* %73, %struct.stat* %10)
%75 = icmp slt i64 %74, 0
br i1 %75, label %76, label %84
76: ; preds = %61
%77 = load i32, i32* @stderr
%78 = load i8*, i8** %8
%79 = load i32, i32* @errno
%80 = call i8* @strerror(i32 %79)
%81 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %78, i8* %80)
%82 = load i8**, i8*** %5
%83 = call i32 @usage(i8** %82, i32 1)
br label %84
84: ; preds = %76, %61
%85 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%86 = load i32, i32* %85
%87 = call i32 @S_ISDIR(i32 %86)
%88 = icmp ne i32 %87, 0
br i1 %88, label %93, label %89
89: ; preds = %84
%90 = load i8**, i8*** %5
%91 = load i8*, i8** %7
%92 = call i32 @invalid(i8** %90, i8* %91)
br label %93
93: ; preds = %89, %84
%94 = load i8*, i8** %8
%95 = call i32 @free(i8* %94)
%96 = load i8*, i8** %7
%97 = call i8* @strstr(i8* %96, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i8* %97, i8** %12
%98 = icmp eq i8* %97, null
br i1 %98, label %99, label %103
99: ; preds = %93
%100 = load i8**, i8*** %5
%101 = load i8*, i8** %7
%102 = call i32 @invalid(i8** %100, i8* %101)
br label %103
103: ; preds = %99, %93
%104 = load i8*, i8** %7
%105 = call i32 @strlen(i8* %104)
%106 = load i8*, i8** %12
%107 = call i32 @strlen(i8* %106)
%108 = sub nsw i32 %105, %107
store i32 %108, i32* %13
%109 = load i8*, i8** %7
%110 = load i32, i32* %13
%111 = add nsw i32 %110, 1
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds i8, i8* %109, i64 %112
%114 = call i8* @strstr(i8* %113, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %114, i8** %15
%115 = icmp eq i8* %114, null
br i1 %115, label %116, label %120
116: ; preds = %103
%117 = load i8**, i8*** %5
%118 = load i8*, i8** %7
%119 = call i32 @invalid(i8** %117, i8* %118)
br label %120
120: ; preds = %116, %103
%121 = load i8*, i8** %7
%122 = call i32 @strlen(i8* %121)
%123 = load i8*, i8** %15
%124 = call i32 @strlen(i8* %123)
%125 = sub nsw i32 %122, %124
store i32 %125, i32* %16
%126 = load i8*, i8** %7
%127 = call i8* @strstr(i8* %126, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
store i8* %127, i8** %18
%128 = icmp eq i8* %127, null
br i1 %128, label %129, label %133
129: ; preds = %120
%130 = load i8**, i8*** %5
%131 = load i8*, i8** %7
%132 = call i32 @invalid(i8** %130, i8* %131)
br label %133
133: ; preds = %129, %120
%134 = load i8*, i8** %7
%135 = call i32 @strlen(i8* %134)
%136 = load i8*, i8** %18
%137 = call i32 @strlen(i8* %136)
%138 = sub nsw i32 %135, %137
store i32 %138, i32* %19
%139 = load i32, i32* %16
%140 = load i32, i32* %13
%141 = sub nsw i32 %139, %140
%142 = sext i32 %141 to i64
store i64 %142, i64* %14
%143 = load i64, i64* %14
%144 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%145 = sext i32 %144 to i64
%146 = icmp ule i64 %143, %145
br i1 %146, label %147, label %151
147: ; preds = %133
%148 = load i8**, i8*** %5
%149 = load i8*, i8** %7
%150 = call i32 @invalid(i8** %148, i8* %149)
br label %151
151: ; preds = %147, %133
%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)
%157 = sext i32 %156 to i64
store i64 %157, i64* %17
%158 = load i64, i64* %17
%159 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%160 = sext i32 %159 to i64
%161 = icmp ule i64 %158, %160
br i1 %161, label %162, label %166
162: ; preds = %151
%163 = load i8**, i8*** %5
%164 = load i8*, i8** %7
%165 = call i32 @invalid(i8** %163, i8* %164)
br label %166
166: ; preds = %162, %151
%167 = load i8*, i8** %7
%168 = load i32, i32* %19
%169 = sext i32 %168 to i64
%170 = getelementptr inbounds i8, i8* %167, i64 %169
%171 = call i32 @strlen(i8* %170)
%172 = sext i32 %171 to i64
store i64 %172, i64* %20
%173 = load i64, i64* %20
%174 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%175 = sext i32 %174 to i64
%176 = icmp ule i64 %173, %175
br i1 %176, label %177, label %181
177: ; preds = %166
%178 = load i8**, i8*** %5
%179 = load i8*, i8** %7
%180 = call i32 @invalid(i8** %178, i8* %179)
br label %181
181: ; preds = %177, %166
%182 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%183 = load i8*, i8** %7
%184 = call i32 @strlen(i8* %183)
%185 = add nsw i32 %182, %184
%186 = sext i32 %185 to i64
%187 = load i64, i64* %17
%188 = sub i64 %186, %187
%189 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%190 = sext i32 %189 to i64
%191 = add i64 %188, %190
%192 = load i64, i64* %14
%193 = add i64 %191, %192
%194 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%195 = sext i32 %194 to i64
%196 = add i64 %193, %195
%197 = add i64 %196, 1
%198 = trunc i64 %197 to i32
%199 = call i8* @malloc(i32 %198)
store i8* %199, i8** %8
%200 = load i8*, i8** %8
%201 = call i32 @strcpy(i8* %200, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%202 = load i8*, i8** %8
%203 = load i8*, i8** %7
%204 = load i32, i32* %16
%205 = call i32 @strncat(i8* %202, i8* %203, i32 %204)
%206 = load i8*, i8** %8
%207 = call i32 @strcat(i8* %206, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%208 = load i8*, i8** %8
%209 = load i8*, i8** %12
%210 = load i64, i64* %14
%211 = trunc i64 %210 to i32
%212 = call i32 @strncat(i8* %208, i8* %209, i32 %211)
%213 = load i8*, i8** %8
%214 = call i32 @strcat(i8* %213, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%215 = load i8*, i8** %7
%216 = load i32, i32* %19
%217 = sext i32 %216 to i64
%218 = getelementptr inbounds i8, i8* %215, i64 %217
%219 = call i8* @strstr(i8* %218, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i8* %219, i8** %21
%220 = icmp eq i8* %219, null
br i1 %220, label %221, label %225
221: ; preds = %181
%222 = load i8**, i8*** %5
%223 = load i8*, i8** %7
%224 = call i32 @invalid(i8** %222, i8* %223)
br label %225
225: ; preds = %221, %181
%226 = load i8*, i8** %7
%227 = load i32, i32* %19
%228 = sext i32 %227 to i64
%229 = getelementptr inbounds i8, i8* %226, i64 %228
%230 = call i32 @strlen(i8* %229)
%231 = load i8*, i8** %21
%232 = call i32 @strlen(i8* %231)
%233 = sub nsw i32 %230, %232
%234 = add nsw i32 %233, 1
store i32 %234, i32* %22
%235 = load i8*, i8** %7
%236 = load i32, i32* %19
%237 = load i32, i32* %22
%238 = add nsw i32 %236, %237
%239 = sext i32 %238 to i64
%240 = getelementptr inbounds i8, i8* %235, i64 %239
%241 = call i8* @strstr(i8* %240, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i8* %241, i8** %24
%242 = icmp eq i8* %241, null
br i1 %242, label %243, label %247
243: ; preds = %225
%244 = load i8**, i8*** %5
%245 = load i8*, i8** %7
%246 = call i32 @invalid(i8** %244, i8* %245)
br label %247
247: ; preds = %243, %225
%248 = load i8*, i8** %7
%249 = load i32, i32* %19
%250 = load i32, i32* %22
%251 = add nsw i32 %249, %250
%252 = sext i32 %251 to i64
%253 = getelementptr inbounds i8, i8* %248, i64 %252
%254 = call i32 @strlen(i8* %253)
%255 = load i8*, i8** %24
%256 = call i32 @strlen(i8* %255)
%257 = sub nsw i32 %254, %256
%258 = add nsw i32 %257, 1
store i32 %258, i32* %25
%259 = load i8*, i8** %7
%260 = load i32, i32* %19
%261 = load i32, i32* %22
%262 = add nsw i32 %260, %261
%263 = load i32, i32* %25
%264 = add nsw i32 %262, %263
%265 = sext i32 %264 to i64
%266 = getelementptr inbounds i8, i8* %259, i64 %265
%267 = call i8* @strstr(i8* %266, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %267, i8** %27
%268 = icmp eq i8* %267, null
br i1 %268, label %269, label %273
269: ; preds = %247
%270 = load i8**, i8*** %5
%271 = load i8*, i8** %7
%272 = call i32 @invalid(i8** %270, i8* %271)
br label %273
273: ; preds = %269, %247
%274 = load i8*, i8** %7
%275 = load i32, i32* %19
%276 = load i32, i32* %22
%277 = add nsw i32 %275, %276
%278 = sext i32 %277 to i64
%279 = getelementptr inbounds i8, i8* %274, i64 %278
%280 = call i32 @strlen(i8* %279)
%281 = load i8*, i8** %24
%282 = call i32 @strlen(i8* %281)
%283 = sub nsw i32 %280, %282
store i32 %283, i32* %23
%284 = load i32, i32* %23
%285 = icmp slt i32 %284, 1
br i1 %285, label %286, label %290
286: ; preds = %273
%287 = load i8**, i8*** %5
%288 = load i8*, i8** %7
%289 = call i32 @invalid(i8** %287, i8* %288)
br label %290
290: ; preds = %286, %273
%291 = load i8*, i8** %7
%292 = load i32, i32* %19
%293 = load i32, i32* %22
%294 = add nsw i32 %292, %293
%295 = load i32, i32* %25
%296 = add nsw i32 %294, %295
%297 = sext i32 %296 to i64
%298 = getelementptr inbounds i8, i8* %291, i64 %297
%299 = call i32 @strlen(i8* %298)
%300 = load i8*, i8** %27
%301 = call i32 @strlen(i8* %300)
%302 = sub nsw i32 %299, %301
store i32 %302, i32* %26
%303 = load i32, i32* %26
%304 = icmp slt i32 %303, 1
br i1 %304, label %305, label %309
305: ; preds = %290
%306 = load i8**, i8*** %5
%307 = load i8*, i8** %7
%308 = call i32 @invalid(i8** %306, i8* %307)
br label %309
309: ; preds = %305, %290
%310 = load i32, i32* %23
%311 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%312 = add nsw i32 %310, %311
%313 = load i32, i32* %26
%314 = add nsw i32 %312, %313
%315 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%316 = add nsw i32 %314, %315
%317 = add nsw i32 %316, 1
%318 = call i8* @malloc(i32 %317)
store i8* %318, i8** %9
%319 = load i8*, i8** %9
%320 = getelementptr inbounds i8, i8* %319, i64 0
store i8 0, i8* %320
%321 = load i8*, i8** %9
%322 = load i8*, i8** %7
%323 = load i32, i32* %19
%324 = load i32, i32* %22
%325 = add nsw i32 %323, %324
%326 = sext i32 %325 to i64
%327 = getelementptr inbounds i8, i8* %322, i64 %326
%328 = load i32, i32* %23
%329 = call i32 @strncat(i8* %321, i8* %327, i32 %328)
%330 = load i8*, i8** %9
%331 = call i32 @strcat(i8* %330, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%332 = load i8*, i8** %9
%333 = load i8*, i8** %7
%334 = load i32, i32* %19
%335 = load i32, i32* %22
%336 = add nsw i32 %334, %335
%337 = load i32, i32* %25
%338 = add nsw i32 %336, %337
%339 = sext i32 %338 to i64
%340 = getelementptr inbounds i8, i8* %333, i64 %339
%341 = load i32, i32* %26
%342 = call i32 @strncat(i8* %332, i8* %340, i32 %341)
%343 = load i8*, i8** %9
%344 = call i32 @strcat(i8* %343, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%345 = load i8*, i8** %8
%346 = load i32, i32* @O_WRONLY
%347 = call i32 @open(i8* %345, i32 %346)
store i32 %347, i32* %11
%348 = icmp slt i32 %347, 0
br i1 %348, label %349, label %357
349: ; preds = %309
%350 = load i32, i32* @stderr
%351 = load i8*, i8** %8
%352 = load i32, i32* @errno
%353 = call i8* @strerror(i32 %352)
%354 = call i32 @fprintf(i32 %350, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i8* %351, i8* %353)
%355 = load i8**, i8*** %5
%356 = call i32 @usage(i8** %355, i32 1)
br label %357
357: ; preds = %349, %309
%358 = load i32, i32* %11
%359 = load i8*, i8** %9
%360 = load i8*, i8** %9
%361 = call i32 @strlen(i8* %360)
%362 = call i64 @write(i32 %358, i8* %359, i32 %361)
%363 = icmp slt i64 %362, 0
br i1 %363, label %364, label %372
364: ; preds = %357
%365 = load i32, i32* @stderr
%366 = load i8*, i8** %8
%367 = load i32, i32* @errno
%368 = call i8* @strerror(i32 %367)
%369 = call i32 @fprintf(i32 %365, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0), i8* %366, i8* %368)
%370 = load i8**, i8*** %5
%371 = call i32 @usage(i8** %370, i32 1)
br label %372
372: ; preds = %364, %357
%373 = load i32, i32* %11
%374 = call i32 @close(i32 %373)
%375 = load i8*, i8** %8
%376 = call i32 @free(i8* %375)
%377 = load i8*, i8** %9
%378 = call i32 @free(i8* %377)
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 i32 @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 i32 %6, label %9 [
i32 -1, label %11
i32 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 ugt 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 ugt 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 ugt 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
}