#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;
int /*<<< orphan*/ snprintf(char *, size_t, char *, char *);
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");
  snprintf(sysfs_path + strlen(sysfs_path), host_len + 1, "%s", host_str);
  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    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdbe(%rip),%rdx
lea    0x2b82(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1070 <getopt_long@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1293 <main+0x73>
mov    -0x14(%rbp),%eax
sub    $0x68,%eax
jne    1280 <main+0x60>
jmp    1275 <main+0x55>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   10f0 <usage@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   10f0 <usage@plt>
jmp    1239 <main+0x19>
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     12b3 <main+0x93>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   10f0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x2d2a(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    0x2d1c(%rip),%rdx
mov    %esi,(%rdx)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12f2 <main+0xd2>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   10f0 <usage@plt>
lea    0xd0f(%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   10e0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xcdc(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1120 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10d0 <stat@plt>
cmp    $0x0,%rax
jge    13a7 <main+0x187>
mov    0x2c7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0xc0(%rbp)
mov    0x2c5a(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0xc4(%rbp),%edi
mov    -0xc0(%rbp),%rdx
mov    %rax,%rcx
lea    0xc79(%rip),%rsi
call   10c0 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   10f0 <usage@plt>
mov    -0x38(%rbp),%edi
call   1080 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    13c5 <main+0x1a5>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1100 <invalid@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
lea    0xc4a(%rip),%rsi
call   1140 <strstr@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    13f9 <main+0x1d9>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1100 <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    0xbf5(%rip),%rsi
call   1140 <strstr@plt>
mov    %rax,-0x60(%rbp)
cmp    $0x0,%rax
jne    1454 <main+0x234>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1100 <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    0xba7(%rip),%rsi
call   1140 <strstr@plt>
mov    %rax,-0x78(%rbp)
cmp    $0x0,%rax
jne    14a4 <main+0x284>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1100 <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    0xb3c(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xd8(%rbp),%rax
movslq %ecx,%rcx
cmp    %rcx,%rax
ja     150e <main+0x2ee>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1100 <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    0xaf3(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xe8(%rbp),%rax
movslq %ecx,%rcx
cmp    %rcx,%rax
ja     155d <main+0x33d>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1100 <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    0xaa0(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xf0(%rbp),%rax
movslq %ecx,%rcx
cmp    %rcx,%rax
ja     15b2 <main+0x392>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1100 <invalid@plt>
lea    0xa4f(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x10c(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x10c(%rbp),%eax
add    %ecx,%eax
cltq
sub    -0x70(%rbp),%rax
mov    %rax,-0x108(%rbp)
lea    0xa48(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x108(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    -0x58(%rbp),%rax
mov    %rax,-0x100(%rbp)
lea    0xa2d(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x100(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0x9c9(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x64(%rbp),%edx
call   10a0 <strncat@plt>
mov    -0x28(%rbp),%rdi
lea    0x9d4(%rip),%rsi
call   1120 <strcat@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0xf8(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x58(%rbp),%rsi
add    $0x1,%rsi
mov    -0x48(%rbp),%rcx
lea    0x9ad(%rip),%rdx
call   1090 <snprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0x997(%rip),%rsi
call   1120 <strcat@plt>
mov    -0x20(%rbp),%rdi
movslq -0x7c(%rbp),%rax
add    %rax,%rdi
lea    0x989(%rip),%rsi
call   1140 <strstr@plt>
mov    %rax,-0x90(%rbp)
cmp    $0x0,%rax
jne    16e1 <main+0x4c1>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1100 <invalid@plt>
mov    -0x20(%rbp),%rdi
movslq -0x7c(%rbp),%rax
add    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,-0x110(%rbp)
mov    -0x90(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x110(%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    0x918(%rip),%rsi
call   1140 <strstr@plt>
mov    %rax,-0xa0(%rbp)
cmp    $0x0,%rax
jne    1752 <main+0x532>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1100 <invalid@plt>
mov    -0x20(%rbp),%rdi
mov    -0x7c(%rbp),%eax
add    -0x94(%rbp),%eax
cltq
add    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,-0x114(%rbp)
mov    -0xa0(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x114(%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    0x87c(%rip),%rsi
call   1140 <strstr@plt>
mov    %rax,-0xb0(%rbp)
cmp    $0x0,%rax
jne    17d0 <main+0x5b0>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1100 <invalid@plt>
mov    -0x20(%rbp),%rdi
mov    -0x7c(%rbp),%eax
add    -0x94(%rbp),%eax
cltq
add    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,-0x118(%rbp)
mov    -0xa0(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x118(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x98(%rbp)
cmpl   $0x1,-0x98(%rbp)
jge    1823 <main+0x603>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1100 <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,-0x11c(%rbp)
mov    -0xb0(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x11c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xa8(%rbp)
cmpl   $0x1,-0xa8(%rbp)
jge    187c <main+0x65c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1100 <invalid@plt>
mov    -0x98(%rbp),%eax
mov    %eax,-0x124(%rbp)
lea    0x7ba(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x124(%rbp),%eax
add    %ecx,%eax
add    -0xa8(%rbp),%eax
mov    %eax,-0x120(%rbp)
lea    0x79a(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x120(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   10e0 <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   10a0 <strncat@plt>
mov    -0x30(%rbp),%rdi
lea    0x74c(%rip),%rsi
call   1120 <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   10a0 <strncat@plt>
mov    -0x30(%rbp),%rdi
lea    0x717(%rip),%rsi
call   1120 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    0x267c(%rip),%rax
mov    (%rax),%esi
call   1110 <open@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
jge    19a9 <main+0x789>
mov    0x267a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x134(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x130(%rbp)
mov    0x2658(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x134(%rbp),%edi
mov    -0x130(%rbp),%rdx
mov    %rax,%rcx
lea    0x6b8(%rip),%rsi
call   10c0 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   10f0 <usage@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x144(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x144(%rbp),%edi
mov    -0x140(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    $0x0,%rax
jge    1a36 <main+0x816>
mov    0x25ed(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x154(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x150(%rbp)
mov    0x25cb(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x154(%rbp),%edi
mov    -0x150(%rbp),%rdx
mov    %rax,%rcx
lea    0x641(%rip),%rsi
call   10c0 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   10f0 <usage@plt>
mov    -0x3c(%rbp),%edi
call   10b0 <close@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r12
mov    %edi,%ebp
lea    0xdbb(%rip),%r14
lea    0x2b7f(%rip),%rbx
jmp    1277 <main+0x47>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
xor    %esi,%esi
call   1100 <usage@plt>
mov    %r12,%rdi
mov    $0x1,%esi
call   1100 <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     1260 <main+0x30>
cmp    $0xffffffff,%eax
jne    126a <main+0x3a>
mov    0x2d4d(%rip),%rbx
mov    (%rbx),%eax
cmp    %ebp,%eax
jl     12b0 <main+0x80>
mov    %r12,%rdi
mov    $0x1,%esi
call   1100 <usage@plt>
mov    (%rbx),%eax
lea    0x1(%rax),%ecx
mov    %ecx,(%rbx)
cltq
mov    (%r12,%rax,8),%r13
test   %r13,%r13
jne    12cd <main+0x9d>
mov    %r12,%rdi
mov    $0x1,%esi
call   1100 <usage@plt>
lea    0xd34(%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   10f0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1130 <strcat@plt>
lea    0x20(%rsp),%rsi
mov    %rbp,%rdi
call   10e0 <stat@plt>
test   %rax,%rax
jns    1354 <main+0x124>
mov    0x2cb5(%rip),%rax
mov    (%rax),%ebx
mov    0x2ca4(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xcd3(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
call   10d0 <fprintf@plt>
mov    %r12,%rdi
mov    $0x1,%esi
call   1100 <usage@plt>
mov    0x20(%rsp),%edi
call   1090 <S_ISDIR@plt>
test   %eax,%eax
jne    136c <main+0x13c>
mov    %r12,%rdi
mov    %r13,%rsi
call   1110 <invalid@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
lea    0xca8(%rip),%rsi
mov    %r13,%rdi
call   1150 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1396 <main+0x166>
mov    %r12,%rdi
mov    %r13,%rsi
call   1110 <invalid@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %eax,%r15d
mov    %rbx,0x10(%rsp)
mov    %rbx,%rdi
call   1060 <strlen@plt>
sub    %eax,%r15d
movslq %r15d,%rax
lea    (%rax,%r13,1),%rdi
add    $0x1,%rdi
mov    $0x2f,%esi
call   1080 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    13d9 <main+0x1a9>
mov    %r12,%rdi
mov    %r13,%rsi
call   1110 <invalid@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1060 <strlen@plt>
sub    %eax,%r14d
lea    0xc35(%rip),%rsi
mov    %r13,%rdi
call   1150 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1411 <main+0x1e1>
mov    %r12,%rdi
mov    %r13,%rsi
call   1110 <invalid@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %eax,0x8(%rsp)
mov    %r14d,%ebx
sub    %r15d,%r14d
lea    0xbef(%rip),%rdi
call   1060 <strlen@plt>
cmp    %eax,%r14d
ja     1449 <main+0x219>
mov    %r12,%rdi
mov    %r13,%rsi
call   1110 <invalid@plt>
sub    0x8(%rsp),%ebp
mov    %ebx,0x18(%rsp)
movslq %ebx,%rdi
add    %r13,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
lea    0xbc4(%rip),%rdi
call   1060 <strlen@plt>
mov    %ebx,0x24(%rsp)
cmp    %eax,%ebx
ja     147d <main+0x24d>
mov    %r12,%rdi
mov    %r13,%rsi
call   1110 <invalid@plt>
movslq %r14d,%rax
mov    %rax,0x28(%rsp)
movslq %ebp,%rdi
add    %r13,%rdi
mov    %rdi,0x30(%rsp)
call   1060 <strlen@plt>
mov    %eax,%ebx
lea    0xb8d(%rip),%rdi
call   1060 <strlen@plt>
cmp    %eax,%ebx
ja     14b2 <main+0x282>
mov    %r12,%rdi
mov    %r13,%rsi
call   1110 <invalid@plt>
lea    0xb4f(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %eax,%r15d
lea    0xb61(%rip),%rdi
call   1060 <strlen@plt>
mov    %r13,0x8(%rsp)
mov    %eax,%r13d
lea    0xb58(%rip),%rdi
call   1060 <strlen@plt>
sub    0x24(%rsp),%r14d
add    %ebx,%r14d
add    %r15d,%r14d
add    %r13d,%r14d
mov    0x8(%rsp),%r15
lea    (%rax,%r14,1),%edi
add    $0x1,%edi
call   10f0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
lea    0xaf1(%rip),%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    0x18(%rsp),%edx
call   10b0 <strncat@plt>
mov    %rbx,%rdi
lea    0xafe(%rip),%rsi
call   1130 <strcat@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
mov    0x28(%rsp),%rsi
add    $0x1,%rsi
lea    0xaec(%rip),%rdx
mov    0x10(%rsp),%rcx
call   10a0 <snprintf@plt>
mov    %rbx,0x18(%rsp)
mov    %rbx,%rdi
lea    0xacd(%rip),%rsi
call   1130 <strcat@plt>
mov    0x30(%rsp),%r14
mov    %r14,%rdi
mov    $0x3a,%esi
call   1080 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    159b <main+0x36b>
mov    %r12,%rdi
mov    %r15,%rsi
call   1110 <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    %r15,%rbx
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1080 <strchr@plt>
mov    %rax,%r14
test   %rax,%rax
jne    15dc <main+0x3ac>
mov    %r12,%rdi
mov    %r15,%rsi
call   1110 <invalid@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %rbx,0x10(%rsp)
mov    %eax,%ebx
mov    %r14,%rdi
call   1060 <strlen@plt>
add    %ebx,%ebp
sub    %eax,%ebp
add    $0x1,%ebp
movslq %ebp,%r13
add    %r15,%r13
mov    %r13,%rdi
mov    $0x2f,%esi
call   1080 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1622 <main+0x3f2>
mov    %r12,%rdi
mov    0x8(%rsp),%rsi
call   1110 <invalid@plt>
mov    0x10(%rsp),%rdi
call   1060 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1060 <strlen@plt>
sub    %eax,%r15d
jg     1649 <main+0x419>
mov    %r12,%rdi
mov    0x8(%rsp),%rsi
call   1110 <invalid@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1060 <strlen@plt>
sub    %eax,%r14d
jg     166e <main+0x43e>
mov    %r12,%rdi
mov    0x8(%rsp),%rsi
call   1110 <invalid@plt>
lea    0x9d2(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
lea    0x9c6(%rip),%rdi
call   1060 <strlen@plt>
add    %r15d,%ebx
add    %r14d,%ebx
lea    (%rax,%rbx,1),%edi
add    $0x1,%edi
call   10f0 <malloc@plt>
mov    %rax,%rbp
movb   $0x0,(%rax)
mov    %rax,%rdi
mov    0x10(%rsp),%rsi
mov    %r15d,%edx
call   10b0 <strncat@plt>
mov    %rbp,%rdi
lea    0x98e(%rip),%rsi
call   1130 <strcat@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
call   10b0 <strncat@plt>
mov    %rbp,%rdi
lea    0x973(%rip),%rsi
call   1130 <strcat@plt>
mov    0x28de(%rip),%rax
mov    (%rax),%esi
mov    0x18(%rsp),%rbx
mov    %rbx,%rdi
call   1120 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    1732 <main+0x502>
mov    0x28d9(%rip),%rax
mov    (%rax),%r15d
mov    0x28c7(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0x935(%rip),%rsi
mov    %r15d,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   10d0 <fprintf@plt>
mov    %r12,%rdi
mov    $0x1,%esi
call   1100 <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    1786 <main+0x556>
mov    0x2885(%rip),%rax
mov    (%rax),%r15d
mov    0x2873(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0x8f7(%rip),%rsi
mov    %r15d,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   10d0 <fprintf@plt>
mov    %r12,%rdi
mov    $0x1,%esi
call   1100 <usage@plt>
mov    %r14d,%edi
call   10c0 <close@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x38,%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 = [3 x i8] c"%s\00"
@.str.10 = [2 x i8] c":\00"
@.str.11 = [2 x i8] c" \00"
@.str.12 = [3 x i8] c" -\00"
@O_WRONLY = global i32 0
@.str.13 = [22 x i8] c"Cannot open '%s': %s\0A\00"
@.str.14 = [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** %8
%210 = call i32 @strlen(i8* %209)
%211 = sext i32 %210 to i64
%212 = getelementptr inbounds i8, i8* %208, i64 %211
%213 = load i64, i64* %14
%214 = add i64 %213, 1
%215 = load i8*, i8** %12
%216 = call i32 @snprintf(i8* %212, i64 %214, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %215)
%217 = load i8*, i8** %8
%218 = call i32 @strcat(i8* %217, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%219 = load i8*, i8** %7
%220 = load i32, i32* %19
%221 = sext i32 %220 to i64
%222 = getelementptr inbounds i8, i8* %219, i64 %221
%223 = call i8* @strstr(i8* %222, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
store i8* %223, i8** %21
%224 = icmp eq i8* %223, null
br i1 %224, label %225, label %229
225: ; preds = %181
%226 = load i8**, i8*** %5
%227 = load i8*, i8** %7
%228 = call i32 @invalid(i8** %226, i8* %227)
br label %229
229: ; preds = %225, %181
%230 = load i8*, i8** %7
%231 = load i32, i32* %19
%232 = sext i32 %231 to i64
%233 = getelementptr inbounds i8, i8* %230, i64 %232
%234 = call i32 @strlen(i8* %233)
%235 = load i8*, i8** %21
%236 = call i32 @strlen(i8* %235)
%237 = sub nsw i32 %234, %236
%238 = add nsw i32 %237, 1
store i32 %238, i32* %22
%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 i8* @strstr(i8* %244, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
store i8* %245, i8** %24
%246 = icmp eq i8* %245, null
br i1 %246, label %247, label %251
247: ; preds = %229
%248 = load i8**, i8*** %5
%249 = load i8*, i8** %7
%250 = call i32 @invalid(i8** %248, i8* %249)
br label %251
251: ; preds = %247, %229
%252 = load i8*, i8** %7
%253 = load i32, i32* %19
%254 = load i32, i32* %22
%255 = add nsw i32 %253, %254
%256 = sext i32 %255 to i64
%257 = getelementptr inbounds i8, i8* %252, i64 %256
%258 = call i32 @strlen(i8* %257)
%259 = load i8*, i8** %24
%260 = call i32 @strlen(i8* %259)
%261 = sub nsw i32 %258, %260
%262 = add nsw i32 %261, 1
store i32 %262, i32* %25
%263 = load i8*, i8** %7
%264 = load i32, i32* %19
%265 = load i32, i32* %22
%266 = add nsw i32 %264, %265
%267 = load i32, i32* %25
%268 = add nsw i32 %266, %267
%269 = sext i32 %268 to i64
%270 = getelementptr inbounds i8, i8* %263, i64 %269
%271 = call i8* @strstr(i8* %270, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %271, i8** %27
%272 = icmp eq i8* %271, null
br i1 %272, label %273, label %277
273: ; preds = %251
%274 = load i8**, i8*** %5
%275 = load i8*, i8** %7
%276 = call i32 @invalid(i8** %274, i8* %275)
br label %277
277: ; preds = %273, %251
%278 = load i8*, i8** %7
%279 = load i32, i32* %19
%280 = load i32, i32* %22
%281 = add nsw i32 %279, %280
%282 = sext i32 %281 to i64
%283 = getelementptr inbounds i8, i8* %278, i64 %282
%284 = call i32 @strlen(i8* %283)
%285 = load i8*, i8** %24
%286 = call i32 @strlen(i8* %285)
%287 = sub nsw i32 %284, %286
store i32 %287, i32* %23
%288 = load i32, i32* %23
%289 = icmp slt i32 %288, 1
br i1 %289, label %290, label %294
290: ; preds = %277
%291 = load i8**, i8*** %5
%292 = load i8*, i8** %7
%293 = call i32 @invalid(i8** %291, i8* %292)
br label %294
294: ; preds = %290, %277
%295 = load i8*, i8** %7
%296 = load i32, i32* %19
%297 = load i32, i32* %22
%298 = add nsw i32 %296, %297
%299 = load i32, i32* %25
%300 = add nsw i32 %298, %299
%301 = sext i32 %300 to i64
%302 = getelementptr inbounds i8, i8* %295, i64 %301
%303 = call i32 @strlen(i8* %302)
%304 = load i8*, i8** %27
%305 = call i32 @strlen(i8* %304)
%306 = sub nsw i32 %303, %305
store i32 %306, i32* %26
%307 = load i32, i32* %26
%308 = icmp slt i32 %307, 1
br i1 %308, label %309, label %313
309: ; preds = %294
%310 = load i8**, i8*** %5
%311 = load i8*, i8** %7
%312 = call i32 @invalid(i8** %310, i8* %311)
br label %313
313: ; preds = %309, %294
%314 = load i32, i32* %23
%315 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%316 = add nsw i32 %314, %315
%317 = load i32, i32* %26
%318 = add nsw i32 %316, %317
%319 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%320 = add nsw i32 %318, %319
%321 = add nsw i32 %320, 1
%322 = call i8* @malloc(i32 %321)
store i8* %322, i8** %9
%323 = load i8*, i8** %9
%324 = getelementptr inbounds i8, i8* %323, i64 0
store i8 0, i8* %324
%325 = load i8*, i8** %9
%326 = load i8*, i8** %7
%327 = load i32, i32* %19
%328 = load i32, i32* %22
%329 = add nsw i32 %327, %328
%330 = sext i32 %329 to i64
%331 = getelementptr inbounds i8, i8* %326, i64 %330
%332 = load i32, i32* %23
%333 = call i32 @strncat(i8* %325, i8* %331, i32 %332)
%334 = load i8*, i8** %9
%335 = call i32 @strcat(i8* %334, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%336 = load i8*, i8** %9
%337 = load i8*, i8** %7
%338 = load i32, i32* %19
%339 = load i32, i32* %22
%340 = add nsw i32 %338, %339
%341 = load i32, i32* %25
%342 = add nsw i32 %340, %341
%343 = sext i32 %342 to i64
%344 = getelementptr inbounds i8, i8* %337, i64 %343
%345 = load i32, i32* %26
%346 = call i32 @strncat(i8* %336, i8* %344, i32 %345)
%347 = load i8*, i8** %9
%348 = call i32 @strcat(i8* %347, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%349 = load i8*, i8** %8
%350 = load i32, i32* @O_WRONLY
%351 = call i32 @open(i8* %349, i32 %350)
store i32 %351, i32* %11
%352 = icmp slt i32 %351, 0
br i1 %352, label %353, label %361
353: ; preds = %313
%354 = load i32, i32* @stderr
%355 = load i8*, i8** %8
%356 = load i32, i32* @errno
%357 = call i8* @strerror(i32 %356)
%358 = call i32 @fprintf(i32 %354, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.13, i64 0, i64 0), i8* %355, i8* %357)
%359 = load i8**, i8*** %5
%360 = call i32 @usage(i8** %359, i32 1)
br label %361
361: ; preds = %353, %313
%362 = load i32, i32* %11
%363 = load i8*, i8** %9
%364 = load i8*, i8** %9
%365 = call i32 @strlen(i8* %364)
%366 = call i64 @write(i32 %362, i8* %363, i32 %365)
%367 = icmp slt i64 %366, 0
br i1 %367, label %368, label %376
368: ; preds = %361
%369 = load i32, i32* @stderr
%370 = load i8*, i8** %8
%371 = load i32, i32* @errno
%372 = call i8* @strerror(i32 %371)
%373 = call i32 @fprintf(i32 %369, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i64 0, i64 0), i8* %370, i8* %372)
%374 = load i8**, i8*** %5
%375 = call i32 @usage(i8** %374, i32 1)
br label %376
376: ; preds = %368, %361
%377 = load i32, i32* %11
%378 = call i32 @close(i32 %377)
%379 = load i8*, i8** %8
%380 = call i32 @free(i8* %379)
%381 = load i8*, i8** %9
%382 = call i32 @free(i8* %381)
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.9 = [3 x i8] c"%s\00"
@.str.11 = [2 x i8] c" \00"
@.str.12 = [3 x i8] c" -\00"
@O_WRONLY = global i32 0
@.str.13 = [22 x i8] c"Cannot open '%s': %s\0A\00"
@.str.14 = [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 = sext i32 %78 to i64
%80 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%81 = icmp ugt i32 %78, %80
br i1 %81, label %84, label %82
82: ; preds = %74
%83 = call i32 @invalid(i8** %1, i8* %22)
br label %84
84: ; preds = %82, %74
%85 = sext i32 %69 to i64
%86 = getelementptr inbounds i8, i8* %22, i64 %85
%87 = call i32 @strlen(i8* %86)
%88 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%89 = icmp ugt i32 %87, %88
br i1 %89, label %92, label %90
90: ; preds = %84
%91 = call i32 @invalid(i8** %1, i8* %22)
br label %92
92: ; preds = %90, %84
%93 = sext i32 %77 to i64
%94 = getelementptr inbounds i8, i8* %22, i64 %93
%95 = call i32 @strlen(i8* %94)
%96 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%97 = icmp ugt i32 %95, %96
br i1 %97, label %100, label %98
98: ; preds = %92
%99 = call i32 @invalid(i8** %1, i8* %22)
br label %100
100: ; preds = %98, %92
%101 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%102 = call i32 @strlen(i8* %22)
%103 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%104 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%105 = add i32 %78, 1
%106 = sub i32 %105, %87
%107 = add i32 %106, %101
%108 = add i32 %107, %102
%109 = add i32 %108, %103
%110 = add i32 %109, %104
%111 = call i8* @malloc(i32 %110)
%112 = call i32 @strcpy(i8* %111, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%113 = call i32 @strncat(i8* %111, i8* %22, i32 %69)
%114 = call i32 @strcat(i8* %111, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%115 = call i32 @strlen(i8* %111)
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i8, i8* %111, i64 %116
%118 = add nsw i64 %79, 1
%119 = call i32 @snprintf(i8* %117, i64 %118, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %51)
%120 = call i32 @strcat(i8* %111, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%121 = call i8* @strchr(i8* dereferenceable(1) %94, i32 58)
%122 = icmp eq i8* %121, null
br i1 %122, label %123, label %125
123: ; preds = %100
%124 = call i32 @invalid(i8** %1, i8* %22)
br label %125
125: ; preds = %123, %100
%126 = call i32 @strlen(i8* %94)
%127 = call i32 @strlen(i8* %121)
%128 = add i32 %77, 1
%129 = add i32 %128, %126
%130 = sub i32 %129, %127
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds i8, i8* %22, i64 %131
%133 = call i8* @strchr(i8* dereferenceable(1) %132, i32 58)
%134 = icmp eq i8* %133, null
br i1 %134, label %135, label %137
135: ; preds = %125
%136 = call i32 @invalid(i8** %1, i8* %22)
br label %137
137: ; preds = %135, %125
%138 = call i32 @strlen(i8* %132)
%139 = call i32 @strlen(i8* %133)
%140 = add i32 %130, 1
%141 = add i32 %140, %138
%142 = sub i32 %141, %139
%143 = sext i32 %142 to i64
%144 = getelementptr inbounds i8, i8* %22, i64 %143
%145 = call i8* @strchr(i8* dereferenceable(1) %144, i32 47)
%146 = icmp eq i8* %145, null
br i1 %146, label %147, label %149
147: ; preds = %137
%148 = call i32 @invalid(i8** %1, i8* %22)
br label %149
149: ; preds = %147, %137
%150 = call i32 @strlen(i8* %132)
%151 = call i32 @strlen(i8* %133)
%152 = sub nsw i32 %150, %151
%153 = icmp slt i32 %152, 1
br i1 %153, label %154, label %156
154: ; preds = %149
%155 = call i32 @invalid(i8** %1, i8* %22)
br label %156
156: ; preds = %154, %149
%157 = call i32 @strlen(i8* %144)
%158 = call i32 @strlen(i8* %145)
%159 = sub nsw i32 %157, %158
%160 = icmp slt i32 %159, 1
br i1 %160, label %161, label %163
161: ; preds = %156
%162 = call i32 @invalid(i8** %1, i8* %22)
br label %163
163: ; preds = %161, %156
%164 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%165 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%166 = add i32 %152, 1
%167 = add i32 %166, %159
%168 = add i32 %167, %164
%169 = add i32 %168, %165
%170 = call i8* @malloc(i32 %169)
store i8 0, i8* %170
%171 = call i32 @strncat(i8* %170, i8* %132, i32 %152)
%172 = call i32 @strcat(i8* %170, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%173 = call i32 @strncat(i8* %170, i8* %144, i32 %159)
%174 = call i32 @strcat(i8* %170, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%175 = load i32, i32* @O_WRONLY
%176 = call i32 @open(i8* %111, i32 %175)
%177 = icmp slt i32 %176, 0
br i1 %177, label %178, label %184
178: ; preds = %163
%179 = load i32, i32* @stderr
%180 = load i32, i32* @errno
%181 = call i8* @strerror(i32 %180)
%182 = call i32 @fprintf(i32 %179, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.13, i64 0, i64 0), i8* %111, i8* %181)
%183 = call i32 @usage(i8** %1, i32 1)
br label %184
184: ; preds = %178, %163
%185 = call i32 @strlen(i8* %170)
%186 = call i64 @write(i32 %176, i8* %170, i32 %185)
%187 = icmp slt i64 %186, 0
br i1 %187, label %188, label %194
188: ; preds = %184
%189 = load i32, i32* @stderr
%190 = load i32, i32* @errno
%191 = call i8* @strerror(i32 %190)
%192 = call i32 @fprintf(i32 %189, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i64 0, i64 0), i8* %111, i8* %191)
%193 = call i32 @usage(i8** %1, i32 1)
br label %194
194: ; preds = %188, %184
%195 = call i32 @close(i32 %176)
%196 = call i32 @free(i8* %111)
%197 = call i32 @free(i8* %170)
ret i32 0
}