#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 */
typedef int /*<<< orphan*/ command;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int const atoi(char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
char *getenv(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ setenv(char *, char *, int);
int setgid(int /*<<< orphan*/);
int setuid(int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char const *, char *);
int system(char *);
scalar_t__ tty_ready(int const);
int tty_wait(int const);
int main(int argc, char *argv[]) {
  int to_tty = 0;
  if (argc != 2 ||
      (strcmp(argv[1], "active") != 0 && strcmp(argv[1], "graphic") != 0 &&
       strcmp(argv[1], "other") != 0 && strcmp(argv[1], "activate") != 0 &&
       strcmp(argv[1], "lock") != 0)) {
    to_tty = atoi(argc == 2 ? argv[1] : "0");
    if (to_tty == 0) {
      fprintf(stderr,
              "Usage: %s "
              "<active|graphic|other|activate|lock|"
              "N>\n"
              "\tactive   Print active tty.\n"
              "\tgraphic  Print graphic tty.\n"
              "\tother    Swith to other tty.\n"
              "\t         Create tty if $TTY_CTL_OTHER_CREATE set.\n"
              "\tactivate Active caller's tty.\n"
              "\tlock     Lock all tty.\n"
              "\tN        Switch to tty N.\n",
              argv[0]);
      return EXIT_FAILURE;
    }
  }
  if (setuid(0) == -1) {
    perror("setuid");
    return EXIT_FAILURE;
  }
  if (setgid(0) == -1) {
    perror("setgid");
    return EXIT_FAILURE;
  }
  if (strcmp(argv[1], "lock") == 0) {
    setenv("TERM", "linux", 1);
    system("openvt -s -w -- bash -c 'if ! pidof vlock >/dev/null 2>&1; then "
           "setterm --blank 1; vlock -a; setterm --blank 15; fi'");
    return EXIT_SUCCESS;
  }
  int status = EXIT_FAILURE;
  char command[255] = {'\0'};
  if (to_tty != 0) {
    snprintf(command, sizeof(command), "chvt %d", to_tty);
    status = system(command);
    status = ((status == -1 || !WIFEXITED(status)) ? EXIT_FAILURE
                                                   : WEXITSTATUS(status));
    if (0 == status) {
      tty_wait(to_tty);
    }
    return status;
  }
  if (strcmp(argv[1], "active") == 0) {
    system("cat /sys/class/tty/tty0/active | awk -Ftty '{print $2}'");
    return EXIT_SUCCESS;
  }
  if (strcmp(argv[1], "graphic") == 0) {
    status = system(
        "(cat /proc/`pgrep -x 'Xorg|Xwayland' | head -1`/environ | strings | "
        "grep XDG_VTNR | head -1 | awk -F= '{print $2}') 2>/dev/null");
    status = ((status == -1 || !WIFEXITED(status)) ? EXIT_FAILURE
                                                   : WEXITSTATUS(status));
    return status;
  }
  const char *my_tty = getenv("XDG_VTNR");
  if (my_tty == NULL) {
    fputs("Warning: $XDG_VTNR not exists, default is \"1\"\n", stderr);
    my_tty = "1";
  }
  if (strcmp(argv[1], "activate") == 0) {
    snprintf(command, sizeof(command), "chvt %s", my_tty);
    status = system(command);
    status = ((status == -1 || !WIFEXITED(status)) ? EXIT_FAILURE
                                                   : WEXITSTATUS(status));
    return 0 == status ? tty_wait(atoi(my_tty)) : status;
  }
  const int other_tty = (strcmp(my_tty, "1") == 0 ? 2 : 1);
  if (getenv("TTY_CTL_OTHER_CREATE") || tty_ready(other_tty) == 0) {
    snprintf(command, sizeof(command), "chvt %d", other_tty);
    status = system(command);
    status = ((status == -1 || !WIFEXITED(status)) ? EXIT_FAILURE
                                                   : WEXITSTATUS(status));
    return 0 == status ? tty_wait(other_tty) : status;
  }
  return EXIT_FAILURE;
}


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)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    12c0 <main+0xc0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdc7(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     133c <main+0x13c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdb0(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     133c <main+0x13c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd9a(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     133c <main+0x13c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd82(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     133c <main+0x13c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd6d(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     133c <main+0x13c>
cmpl   $0x2,-0x8(%rbp)
jne    12de <main+0xde>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x138(%rbp)
jmp    12f1 <main+0xf1>
lea    0xd3e(%rip),%rax
mov    %rax,-0x138(%rbp)
jmp    12f1 <main+0xf1>
mov    -0x138(%rbp),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1337 <main+0x137>
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd04(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2cab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1784 <main+0x584>
jmp    133c <main+0x13c>
xor    %edi,%edi
call   1120 <setuid@plt>
cmp    $0xffffffff,%eax
jne    1369 <main+0x169>
lea    0xde0(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2c79(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1784 <main+0x584>
xor    %edi,%edi
call   10e0 <setgid@plt>
cmp    $0xffffffff,%eax
jne    1396 <main+0x196>
lea    0xdba(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2c4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1784 <main+0x584>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xc79(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    13e9 <main+0x1e9>
lea    0xd86(%rip),%rdi
lea    0xd84(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
lea    0xd79(%rip),%rdi
call   1060 <system@plt>
mov    0x2bf1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1784 <main+0x584>
mov    0x2be8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1090 <memset@plt>
cmpl   $0x0,-0x14(%rbp)
je     14a2 <main+0x2a2>
lea    -0x120(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0xff,%esi
lea    0xd99(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
lea    -0x120(%rbp),%rdi
call   1060 <system@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
je     1459 <main+0x259>
mov    -0x18(%rbp),%edi
call   1110 <WIFEXITED@plt>
cmp    $0x0,%eax
jne    146d <main+0x26d>
mov    0x2b78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x13c(%rbp)
jmp    147b <main+0x27b>
mov    -0x18(%rbp),%edi
call   10d0 <WEXITSTATUS@plt>
mov    %eax,-0x13c(%rbp)
mov    -0x13c(%rbp),%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
jne    1497 <main+0x297>
mov    -0x14(%rbp),%edi
call   1050 <tty_wait@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1784 <main+0x584>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xb4f(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    14dd <main+0x2dd>
lea    0xd02(%rip),%rdi
call   1060 <system@plt>
mov    0x2afd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1784 <main+0x584>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xb1b(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    155b <main+0x35b>
lea    0xcff(%rip),%rdi
call   1060 <system@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
je     1525 <main+0x325>
mov    -0x18(%rbp),%edi
call   1110 <WIFEXITED@plt>
cmp    $0x0,%eax
jne    1539 <main+0x339>
mov    0x2aac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x140(%rbp)
jmp    1547 <main+0x347>
mov    -0x18(%rbp),%edi
call   10d0 <WEXITSTATUS@plt>
mov    %eax,-0x140(%rbp)
mov    -0x140(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1784 <main+0x584>
lea    0xd1f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    159f <main+0x39f>
mov    0x2a5d(%rip),%rax
mov    (%rax),%esi
lea    0xcfe(%rip),%rdi
call   1080 <fputs@plt>
lea    0xd21(%rip),%rax
mov    %rax,-0x128(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xa67(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1673 <main+0x473>
lea    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rcx
mov    $0xff,%esi
lea    0xce4(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
lea    -0x120(%rbp),%rdi
call   1060 <system@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
je     1608 <main+0x408>
mov    -0x18(%rbp),%edi
call   1110 <WIFEXITED@plt>
cmp    $0x0,%eax
jne    161c <main+0x41c>
mov    0x29c9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x144(%rbp)
jmp    162a <main+0x42a>
mov    -0x18(%rbp),%edi
call   10d0 <WEXITSTATUS@plt>
mov    %eax,-0x144(%rbp)
mov    -0x144(%rbp),%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
jne    165c <main+0x45c>
mov    -0x128(%rbp),%rdi
call   1100 <atoi@plt>
mov    %eax,%edi
call   1050 <tty_wait@plt>
mov    %eax,-0x148(%rbp)
jmp    1665 <main+0x465>
mov    -0x18(%rbp),%eax
mov    %eax,-0x148(%rbp)
mov    -0x148(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1784 <main+0x584>
mov    -0x128(%rbp),%rdi
lea    0xc38(%rip),%rsi
call   10a0 <strcmp@plt>
mov    %rax,%rdx
mov    $0x1,%eax
mov    $0x2,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x12c(%rbp)
lea    0xc1c(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
jne    16cb <main+0x4cb>
mov    -0x12c(%rbp),%edi
call   10c0 <tty_ready@plt>
cmp    $0x0,%rax
jne    1778 <main+0x578>
lea    -0x120(%rbp),%rdi
mov    -0x12c(%rbp),%ecx
mov    $0xff,%esi
lea    0xadd(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
lea    -0x120(%rbp),%rdi
call   1060 <system@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
je     1715 <main+0x515>
mov    -0x18(%rbp),%edi
call   1110 <WIFEXITED@plt>
cmp    $0x0,%eax
jne    1729 <main+0x529>
mov    0x28bc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14c(%rbp)
jmp    1737 <main+0x537>
mov    -0x18(%rbp),%edi
call   10d0 <WEXITSTATUS@plt>
mov    %eax,-0x14c(%rbp)
mov    -0x14c(%rbp),%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
jne    1761 <main+0x561>
mov    -0x12c(%rbp),%edi
call   1050 <tty_wait@plt>
mov    %eax,-0x150(%rbp)
jmp    176a <main+0x56a>
mov    -0x18(%rbp),%eax
mov    %eax,-0x150(%rbp)
mov    -0x150(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1784 <main+0x584>
mov    0x2859(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1272 <main+0x82>
mov    0x8(%rbx),%rdi
lea    0xdf4(%rip),%rsi
call   1090 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1288 <main+0x98>
mov    0x8(%rbx),%rdi
lea    0xde4(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1288 <main+0x98>
mov    0x8(%rbx),%rdi
lea    0xdd7(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1288 <main+0x98>
mov    0x8(%rbx),%rdi
lea    0xdc8(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1288 <main+0x98>
mov    0x8(%rbx),%rdi
lea    0xdbc(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1288 <main+0x98>
mov    0x8(%rbx),%rdi
jmp    1279 <main+0x89>
lea    0xdaa(%rip),%rdi
call   10f0 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
je     13a9 <main+0x1b9>
xor    %edi,%edi
call   1110 <setuid@plt>
cmp    $0xffffffff,%eax
je     14e5 <main+0x2f5>
xor    %edi,%edi
call   10d0 <setgid@plt>
cmp    $0xffffffff,%eax
je     14ee <main+0x2fe>
mov    0x8(%rbx),%rdi
lea    0xd6b(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1379 <main+0x189>
xorps  %xmm0,%xmm0
movups %xmm0,0xef(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
test   %ebp,%ebp
je     13e5 <main+0x1f5>
lea    0xe87(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %ebp,%ecx
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
cmp    $0xffffffff,%eax
je     13c6 <main+0x1d6>
mov    %eax,%ebx
mov    %eax,%edi
call   1100 <WIFEXITED@plt>
test   %eax,%eax
je     13c6 <main+0x1d6>
mov    %ebx,%edi
call   10c0 <WEXITSTATUS@plt>
test   %eax,%eax
jne    1503 <main+0x313>
jmp    13d7 <main+0x1e7>
lea    0xdc1(%rip),%rdi
lea    0xdbf(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
lea    0xdb4(%rip),%rdi
call   1060 <system@plt>
mov    0x2c2c(%rip),%rax
jmp    1501 <main+0x311>
mov    0x2c30(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xc69(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    14fa <main+0x30a>
mov    0x2c0b(%rip),%rax
mov    (%rax),%eax
test   %eax,%eax
jne    1503 <main+0x313>
mov    %ebp,%edi
call   1050 <tty_wait@plt>
xor    %eax,%eax
jmp    1503 <main+0x313>
mov    0x8(%rbx),%rdi
lea    0xc10(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     14d9 <main+0x2e9>
mov    0x8(%rbx),%rdi
lea    0xbfe(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     150d <main+0x31d>
lea    0xe63(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1447 <main+0x257>
mov    0x2bae(%rip),%rax
mov    (%rax),%esi
lea    0xe4f(%rip),%rdi
call   1080 <fputs@plt>
lea    0xe72(%rip),%rbp
mov    0x8(%rbx),%rdi
lea    0xbc3(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1534 <main+0x344>
lea    0xe52(%rip),%rsi
mov    %rbp,%rdi
call   1090 <strcmp@plt>
cmp    $0x1,%rax
mov    $0x1,%ebx
adc    $0x0,%ebx
lea    0xe41(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1584 <main+0x394>
lea    0xd2a(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0xff,%esi
mov    %ebx,%ecx
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %rbp,%rdi
call   1060 <system@plt>
cmp    $0xffffffff,%eax
je     1573 <main+0x383>
mov    %eax,%ebp
mov    %eax,%edi
call   1100 <WIFEXITED@plt>
test   %eax,%eax
je     1573 <main+0x383>
mov    %ebp,%edi
call   10c0 <WEXITSTATUS@plt>
jmp    157c <main+0x38c>
lea    0xce9(%rip),%rdi
jmp    1398 <main+0x1a8>
lea    0xc47(%rip),%rdi
jmp    14f5 <main+0x305>
lea    0xc45(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2ad7(%rip),%rax
mov    (%rax),%eax
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xced(%rip),%rdi
call   1060 <system@plt>
cmp    $0xffffffff,%eax
je     14fa <main+0x30a>
mov    %eax,%ebx
mov    %eax,%edi
call   1100 <WIFEXITED@plt>
test   %eax,%eax
je     14fa <main+0x30a>
mov    %ebx,%edi
call   10c0 <WEXITSTATUS@plt>
jmp    1503 <main+0x313>
lea    0xd80(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %rbp,%rcx
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
cmp    $0xffffffff,%eax
je     1599 <main+0x3a9>
mov    %eax,%ebx
mov    %eax,%edi
call   1100 <WIFEXITED@plt>
test   %eax,%eax
je     1599 <main+0x3a9>
mov    %ebx,%edi
call   10c0 <WEXITSTATUS@plt>
jmp    15a2 <main+0x3b2>
mov    0x2a5e(%rip),%rax
mov    (%rax),%eax
test   %eax,%eax
jne    1503 <main+0x313>
mov    %ebx,%edi
jmp    15b4 <main+0x3c4>
mov    %ebx,%edi
call   10b0 <tty_ready@plt>
test   %rax,%rax
jne    14fa <main+0x30a>
jmp    1490 <main+0x2a0>
mov    0x2a38(%rip),%rax
mov    (%rax),%eax
test   %eax,%eax
jne    1503 <main+0x313>
mov    %rbp,%rdi
call   10f0 <atoi@plt>
mov    %eax,%edi
call   1050 <tty_wait@plt>
jmp    1503 <main+0x313>

LLVM IR (-O0):
@.str = [7 x i8] c"active\00"
@.str.1 = [8 x i8] c"graphic\00"
@.str.2 = [6 x i8] c"other\00"
@.str.3 = [9 x i8] c"activate\00"
@.str.4 = [5 x i8] c"lock\00"
@.str.5 = [2 x i8] c"0\00"
@stderr = global i32 0
@.str.6 = [270 x i8] c"Usage: %s <active|graphic|other|activate|lock|N>\0A\09active Print active tty.\0A\09graphic Print graphic tty.\0A\09other Swith to other tty.\0A\09 Create tty if $TTY_CTL_OTHER_CREATE set.\0A\09activate Active caller's tty.\0A\09lock Lock all tty.\0A\09N Switch to tty N.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.7 = [7 x i8] c"setuid\00"
@.str.8 = [7 x i8] c"setgid\00"
@.str.9 = [5 x i8] c"TERM\00"
@.str.10 = [6 x i8] c"linux\00"
@.str.11 = [117 x i8] c"openvt -s -w -- bash -c 'if ! pidof vlock >/dev/null 2>&1; then setterm --blank 1; vlock -a; setterm --blank 15; fi'\00"
@EXIT_SUCCESS = global i32 0
@.str.12 = [8 x i8] c"chvt %d\00"
@.str.13 = [56 x i8] c"cat /sys/class/tty/tty0/active | awk -Ftty '{print $2}'\00"
@.str.14 = [128 x i8] c"(cat /proc/`pgrep -x 'Xorg|Xwayland' | head -1`/environ | strings | grep XDG_VTNR | head -1 | awk -F= '{print $2}') 2>/dev/null\00"
@.str.15 = [9 x i8] c"XDG_VTNR\00"
@.str.16 = [47 x i8] c"Warning: $XDG_VTNR not exists, default is \221\22\0A\00"
@.str.17 = [2 x i8] c"1\00"
@.str.18 = [8 x i8] c"chvt %s\00"
@.str.19 = [21 x i8] c"TTY_CTL_OTHER_CREATE\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [255 x i8]
%9 = alloca i8*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %43, label %13
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %64
19: ; preds = %13
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %64
25: ; preds = %19
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %64
31: ; preds = %25
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %64
37: ; preds = %31
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %64
43: ; preds = %37, %2
%44 = load i32, i32* %4
%45 = icmp eq i32 %44, 2
br i1 %45, label %46, label %50
46: ; preds = %43
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
br label %51
50: ; preds = %43
br label %51
51: ; preds = %50, %46
%52 = phi i8* [ %49, %46 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), %50 ]
%53 = call i32 @atoi(i8* %52)
store i32 %53, i32* %6
%54 = load i32, i32* %6
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %63
56: ; preds = %51
%57 = load i32, i32* @stderr
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 0
%60 = load i8*, i8** %59
%61 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([270 x i8], [270 x i8]* @.str.6, i64 0, i64 0), i8* %60)
%62 = load i32, i32* @EXIT_FAILURE
store i32 %62, i32* %3
br label %232
63: ; preds = %51
br label %64
64: ; preds = %63, %37, %31, %25, %19, %13
%65 = call i32 @setuid(i32 0)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %70
67: ; preds = %64
%68 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%69 = load i32, i32* @EXIT_FAILURE
store i32 %69, i32* %3
br label %232
70: ; preds = %64
%71 = call i32 @setgid(i32 0)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %76
73: ; preds = %70
%74 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%75 = load i32, i32* @EXIT_FAILURE
store i32 %75, i32* %3
br label %232
76: ; preds = %70
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 1
%79 = load i8*, i8** %78
%80 = call i64 @strcmp(i8* %79, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%81 = icmp eq i64 %80, 0
br i1 %81, label %82, label %86
82: ; preds = %76
%83 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i32 1)
%84 = call i32 @system(i8* getelementptr inbounds ([117 x i8], [117 x i8]* @.str.11, i64 0, i64 0))
%85 = load i32, i32* @EXIT_SUCCESS
store i32 %85, i32* %3
br label %232
86: ; preds = %76
%87 = load i32, i32* @EXIT_FAILURE
store i32 %87, i32* %7
%88 = bitcast [255 x i8]* %8 to i8*
%89 = load i32, i32* %6
%90 = icmp ne i32 %89, 0
br i1 %90, label %91, label %117
91: ; preds = %86
%92 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%93 = load i32, i32* %6
%94 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %92, i32 255, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0), i32 %93)
%95 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%96 = call i32 @system(i8* %95)
store i32 %96, i32* %7
%97 = load i32, i32* %7
%98 = icmp eq i32 %97, -1
br i1 %98, label %103, label %99
99: ; preds = %91
%100 = load i32, i32* %7
%101 = call i32 @WIFEXITED(i32 %100)
%102 = icmp ne i32 %101, 0
br i1 %102, label %105, label %103
103: ; preds = %99, %91
%104 = load i32, i32* @EXIT_FAILURE
br label %108
105: ; preds = %99
%106 = load i32, i32* %7
%107 = call i32 @WEXITSTATUS(i32 %106)
br label %108
108: ; preds = %105, %103
%109 = phi i32 [ %104, %103 ], [ %107, %105 ]
store i32 %109, i32* %7
%110 = load i32, i32* %7
%111 = icmp eq i32 0, %110
br i1 %111, label %112, label %115
112: ; preds = %108
%113 = load i32, i32* %6
%114 = call i32 @tty_wait(i32 %113)
br label %115
115: ; preds = %112, %108
%116 = load i32, i32* %7
store i32 %116, i32* %3
br label %232
117: ; preds = %86
%118 = load i8**, i8*** %5
%119 = getelementptr inbounds i8*, i8** %118, i64 1
%120 = load i8*, i8** %119
%121 = call i64 @strcmp(i8* %120, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%122 = icmp eq i64 %121, 0
br i1 %122, label %123, label %126
123: ; preds = %117
%124 = call i32 @system(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.13, i64 0, i64 0))
%125 = load i32, i32* @EXIT_SUCCESS
store i32 %125, i32* %3
br label %232
126: ; preds = %117
%127 = load i8**, i8*** %5
%128 = getelementptr inbounds i8*, i8** %127, i64 1
%129 = load i8*, i8** %128
%130 = call i64 @strcmp(i8* %129, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%131 = icmp eq i64 %130, 0
br i1 %131, label %132, label %148
132: ; preds = %126
%133 = call i32 @system(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @.str.14, i64 0, i64 0))
store i32 %133, i32* %7
%134 = load i32, i32* %7
%135 = icmp eq i32 %134, -1
br i1 %135, label %140, label %136
136: ; preds = %132
%137 = load i32, i32* %7
%138 = call i32 @WIFEXITED(i32 %137)
%139 = icmp ne i32 %138, 0
br i1 %139, label %142, label %140
140: ; preds = %136, %132
%141 = load i32, i32* @EXIT_FAILURE
br label %145
142: ; preds = %136
%143 = load i32, i32* %7
%144 = call i32 @WEXITSTATUS(i32 %143)
br label %145
145: ; preds = %142, %140
%146 = phi i32 [ %141, %140 ], [ %144, %142 ]
store i32 %146, i32* %7
%147 = load i32, i32* %7
store i32 %147, i32* %3
br label %232
148: ; preds = %126
%149 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.15, i64 0, i64 0))
store i8* %149, i8** %9
%150 = load i8*, i8** %9
%151 = icmp eq i8* %150, null
br i1 %151, label %152, label %155
152: ; preds = %148
%153 = load i32, i32* @stderr
%154 = call i32 @fputs(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.16, i64 0, i64 0), i32 %153)
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0), i8** %9
br label %155
155: ; preds = %152, %148
%156 = load i8**, i8*** %5
%157 = getelementptr inbounds i8*, i8** %156, i64 1
%158 = load i8*, i8** %157
%159 = call i64 @strcmp(i8* %158, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%160 = icmp eq i64 %159, 0
br i1 %160, label %161, label %190
161: ; preds = %155
%162 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%163 = load i8*, i8** %9
%164 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %162, i32 255, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.18, i64 0, i64 0), i8* %163)
%165 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%166 = call i32 @system(i8* %165)
store i32 %166, i32* %7
%167 = load i32, i32* %7
%168 = icmp eq i32 %167, -1
br i1 %168, label %173, label %169
169: ; preds = %161
%170 = load i32, i32* %7
%171 = call i32 @WIFEXITED(i32 %170)
%172 = icmp ne i32 %171, 0
br i1 %172, label %175, label %173
173: ; preds = %169, %161
%174 = load i32, i32* @EXIT_FAILURE
br label %178
175: ; preds = %169
%176 = load i32, i32* %7
%177 = call i32 @WEXITSTATUS(i32 %176)
br label %178
178: ; preds = %175, %173
%179 = phi i32 [ %174, %173 ], [ %177, %175 ]
store i32 %179, i32* %7
%180 = load i32, i32* %7
%181 = icmp eq i32 0, %180
br i1 %181, label %182, label %186
182: ; preds = %178
%183 = load i8*, i8** %9
%184 = call i32 @atoi(i8* %183)
%185 = call i32 @tty_wait(i32 %184)
br label %188
186: ; preds = %178
%187 = load i32, i32* %7
br label %188
188: ; preds = %186, %182
%189 = phi i32 [ %185, %182 ], [ %187, %186 ]
store i32 %189, i32* %3
br label %232
190: ; preds = %155
%191 = load i8*, i8** %9
%192 = call i64 @strcmp(i8* %191, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
%193 = icmp eq i64 %192, 0
%194 = zext i1 %193 to i64
%195 = select i1 %193, i32 2, i32 1
store i32 %195, i32* %10
%196 = call i8* @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.19, i64 0, i64 0))
%197 = icmp ne i8* %196, null
br i1 %197, label %202, label %198
198: ; preds = %190
%199 = load i32, i32* %10
%200 = call i64 @tty_ready(i32 %199)
%201 = icmp eq i64 %200, 0
br i1 %201, label %202, label %230
202: ; preds = %198, %190
%203 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%204 = load i32, i32* %10
%205 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %203, i32 255, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0), i32 %204)
%206 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%207 = call i32 @system(i8* %206)
store i32 %207, i32* %7
%208 = load i32, i32* %7
%209 = icmp eq i32 %208, -1
br i1 %209, label %214, label %210
210: ; preds = %202
%211 = load i32, i32* %7
%212 = call i32 @WIFEXITED(i32 %211)
%213 = icmp ne i32 %212, 0
br i1 %213, label %216, label %214
214: ; preds = %210, %202
%215 = load i32, i32* @EXIT_FAILURE
br label %219
216: ; preds = %210
%217 = load i32, i32* %7
%218 = call i32 @WEXITSTATUS(i32 %217)
br label %219
219: ; preds = %216, %214
%220 = phi i32 [ %215, %214 ], [ %218, %216 ]
store i32 %220, i32* %7
%221 = load i32, i32* %7
%222 = icmp eq i32 0, %221
br i1 %222, label %223, label %226
223: ; preds = %219
%224 = load i32, i32* %10
%225 = call i32 @tty_wait(i32 %224)
br label %228
226: ; preds = %219
%227 = load i32, i32* %7
br label %228
228: ; preds = %226, %223
%229 = phi i32 [ %225, %223 ], [ %227, %226 ]
store i32 %229, i32* %3
br label %232
230: ; preds = %198
%231 = load i32, i32* @EXIT_FAILURE
store i32 %231, i32* %3
br label %232
232: ; preds = %230, %228, %188, %145, %123, %115, %82, %73, %67, %56
%233 = load i32, i32* %3
ret i32 %233
}

LLVM IR (-O2):
@.str = [7 x i8] c"active\00"
@.str.1 = [8 x i8] c"graphic\00"
@.str.2 = [6 x i8] c"other\00"
@.str.3 = [9 x i8] c"activate\00"
@.str.4 = [5 x i8] c"lock\00"
@.str.5 = [2 x i8] c"0\00"
@stderr = global i32 0
@.str.6 = [270 x i8] c"Usage: %s <active|graphic|other|activate|lock|N>\0A\09active Print active tty.\0A\09graphic Print graphic tty.\0A\09other Swith to other tty.\0A\09 Create tty if $TTY_CTL_OTHER_CREATE set.\0A\09activate Active caller's tty.\0A\09lock Lock all tty.\0A\09N Switch to tty N.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.7 = [7 x i8] c"setuid\00"
@.str.8 = [7 x i8] c"setgid\00"
@.str.9 = [5 x i8] c"TERM\00"
@.str.10 = [6 x i8] c"linux\00"
@.str.11 = [117 x i8] c"openvt -s -w -- bash -c 'if ! pidof vlock >/dev/null 2>&1; then setterm --blank 1; vlock -a; setterm --blank 15; fi'\00"
@EXIT_SUCCESS = global i32 0
@.str.12 = [8 x i8] c"chvt %d\00"
@.str.13 = [56 x i8] c"cat /sys/class/tty/tty0/active | awk -Ftty '{print $2}'\00"
@.str.14 = [128 x i8] c"(cat /proc/`pgrep -x 'Xorg|Xwayland' | head -1`/environ | strings | grep XDG_VTNR | head -1 | awk -F= '{print $2}') 2>/dev/null\00"
@.str.15 = [9 x i8] c"XDG_VTNR\00"
@.str.16 = [47 x i8] c"Warning: $XDG_VTNR not exists, default is \221\22\0A\00"
@.str.17 = [2 x i8] c"1\00"
@.str.18 = [8 x i8] c"chvt %s\00"
@.str.19 = [21 x i8] c"TTY_CTL_OTHER_CREATE\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [255 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %5, label %28
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %37, label %10
10: ; preds = %5
%11 = load i8*, i8** %6
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %37, label %14
14: ; preds = %10
%15 = load i8*, i8** %6
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %37, label %18
18: ; preds = %14
%19 = load i8*, i8** %6
%20 = tail call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %37, label %22
22: ; preds = %18
%23 = load i8*, i8** %6
%24 = tail call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %37, label %26
26: ; preds = %22
%27 = load i8*, i8** %6
br label %28
28: ; preds = %2, %26
%29 = phi i8* [ %27, %26 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), %2 ]
%30 = tail call i32 @atoi(i8* %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %1
%35 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([270 x i8], [270 x i8]* @.str.6, i64 0, i64 0), i8* %34)
%36 = load i32, i32* @EXIT_FAILURE
br label %156
37: ; preds = %28, %22, %18, %14, %10, %5
%38 = phi i32 [ %30, %28 ], [ 0, %22 ], [ 0, %18 ], [ 0, %14 ], [ 0, %10 ], [ 0, %5 ]
%39 = tail call i32 @setuid(i32 0)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
br label %156
44: ; preds = %37
%45 = tail call i32 @setgid(i32 0)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
br label %156
50: ; preds = %44
%51 = getelementptr inbounds i8*, i8** %1, i64 1
%52 = load i8*, i8** %51
%53 = tail call i64 @strcmp(i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %50
%56 = tail call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i32 1)
%57 = tail call i32 @system(i8* getelementptr inbounds ([117 x i8], [117 x i8]* @.str.11, i64 0, i64 0))
%58 = load i32, i32* @EXIT_SUCCESS
br label %156
59: ; preds = %50
%60 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%61 = icmp eq i32 %38, 0
br i1 %61, label %78, label %62
62: ; preds = %59
%63 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %60, i32 255, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0), i32 %38)
%64 = call i32 @system(i8* %60)
%65 = icmp eq i32 %64, -1
br i1 %65, label %69, label %66
66: ; preds = %62
%67 = call i32 @WIFEXITED(i32 %64)
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %66, %62
%70 = load i32, i32* @EXIT_FAILURE
br label %73
71: ; preds = %66
%72 = call i32 @WEXITSTATUS(i32 %64)
br label %73
73: ; preds = %71, %69
%74 = phi i32 [ %70, %69 ], [ %72, %71 ]
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %154
76: ; preds = %73
%77 = call i32 @tty_wait(i32 %38)
br label %154
78: ; preds = %59
%79 = load i8*, i8** %51
%80 = tail call i64 @strcmp(i8* %79, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%81 = icmp eq i64 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %78
%83 = tail call i32 @system(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.13, i64 0, i64 0))
%84 = load i32, i32* @EXIT_SUCCESS
br label %154
85: ; preds = %78
%86 = load i8*, i8** %51
%87 = tail call i64 @strcmp(i8* %86, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%88 = icmp eq i64 %87, 0
br i1 %88, label %89, label %99
89: ; preds = %85
%90 = tail call i32 @system(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @.str.14, i64 0, i64 0))
%91 = icmp eq i32 %90, -1
br i1 %91, label %95, label %92
92: ; preds = %89
%93 = tail call i32 @WIFEXITED(i32 %90)
%94 = icmp eq i32 %93, 0
br i1 %94, label %95, label %97
95: ; preds = %92, %89
%96 = load i32, i32* @EXIT_FAILURE
br label %154
97: ; preds = %92
%98 = tail call i32 @WEXITSTATUS(i32 %90)
br label %154
99: ; preds = %85
%100 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.15, i64 0, i64 0))
%101 = icmp eq i8* %100, null
br i1 %101, label %102, label %105
102: ; preds = %99
%103 = load i32, i32* @stderr
%104 = tail call i32 @fputs(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.16, i64 0, i64 0), i32 %103)
br label %105
105: ; preds = %102, %99
%106 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0), %102 ], [ %100, %99 ]
%107 = load i8*, i8** %51
%108 = tail call i64 @strcmp(i8* %107, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%109 = icmp eq i64 %108, 0
br i1 %109, label %110, label %127
110: ; preds = %105
%111 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %60, i32 255, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.18, i64 0, i64 0), i8* %106)
%112 = call i32 @system(i8* %60)
%113 = icmp eq i32 %112, -1
br i1 %113, label %117, label %114
114: ; preds = %110
%115 = call i32 @WIFEXITED(i32 %112)
%116 = icmp eq i32 %115, 0
br i1 %116, label %117, label %119
117: ; preds = %114, %110
%118 = load i32, i32* @EXIT_FAILURE
br label %121
119: ; preds = %114
%120 = call i32 @WEXITSTATUS(i32 %112)
br label %121
121: ; preds = %119, %117
%122 = phi i32 [ %118, %117 ], [ %120, %119 ]
%123 = icmp eq i32 %122, 0
br i1 %123, label %124, label %154
124: ; preds = %121
%125 = call i32 @atoi(i8* %106)
%126 = call i32 @tty_wait(i32 %125)
br label %154
127: ; preds = %105
%128 = tail call i64 @strcmp(i8* %106, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
%129 = icmp eq i64 %128, 0
%130 = select i1 %129, i32 2, i32 1
%131 = tail call i8* @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.19, i64 0, i64 0))
%132 = icmp eq i8* %131, null
br i1 %132, label %133, label %136
133: ; preds = %127
%134 = tail call i64 @tty_ready(i32 %130)
%135 = icmp eq i64 %134, 0
br i1 %135, label %136, label %152
136: ; preds = %133, %127
%137 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %60, i32 255, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0), i32 %130)
%138 = call i32 @system(i8* %60)
%139 = icmp eq i32 %138, -1
br i1 %139, label %143, label %140
140: ; preds = %136
%141 = call i32 @WIFEXITED(i32 %138)
%142 = icmp eq i32 %141, 0
br i1 %142, label %143, label %145
143: ; preds = %140, %136
%144 = load i32, i32* @EXIT_FAILURE
br label %147
145: ; preds = %140
%146 = call i32 @WEXITSTATUS(i32 %138)
br label %147
147: ; preds = %145, %143
%148 = phi i32 [ %144, %143 ], [ %146, %145 ]
%149 = icmp eq i32 %148, 0
br i1 %149, label %150, label %154
150: ; preds = %147
%151 = call i32 @tty_wait(i32 %130)
br label %154
152: ; preds = %133
%153 = load i32, i32* @EXIT_FAILURE
br label %154
154: ; preds = %121, %124, %150, %147, %152, %95, %97, %73, %76, %82
%155 = phi i32 [ %84, %82 ], [ 0, %76 ], [ %74, %73 ], [ %96, %95 ], [ %98, %97 ], [ %126, %124 ], [ %122, %121 ], [ %153, %152 ], [ %151, %150 ], [ %148, %147 ]
br label %156
156: ; preds = %154, %55, %47, %41, %32
%157 = phi i32 [ %36, %32 ], [ %43, %41 ], [ %49, %47 ], [ %58, %55 ], [ %155, %154 ]
ret i32 %157
}