#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*/ member_1;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EX_NOPERM;
int EX_OK;
int EX_OSFILE;
int EX_USAGE;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, unsigned int *);
int getopt_long(int, char **, char *, struct option *, int /*<<< orphan*/ *);
scalar_t__ getuid();
int /*<<< orphan*/ show_help();
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int opts = 0, activate = 0, deactivate = 0, toggle = 0, verbose = 0;
  struct stat sb;
  FILE *f;
  if (0 != getuid()) {
    fprintf(stderr, "You have to be root in order to use uksmctl\n");
    exit(EX_NOPERM);
  }
  if (0 != stat("/sys/kernel/mm/uksm", &sb) && S_ISDIR(sb.st_mode)) {
    fprintf(stderr, "Unable to find uksm interface in %s\n",
            "/sys/kernel/mm/uksm");
    exit(EX_OSFILE);
  }
  struct option longopts[] = {
      {"activate", 0, NULL, 'a'}, {"deactivate", 0, NULL, 'd'},
      {"toggle", 0, NULL, 't'},   {"verbose", 0, NULL, 'v'},
      {"help", 0, NULL, 'h'},     {0, 0, 0, 0}};
  while (-1 != (opts = getopt_long(argc, argv, "adtvh", longopts, NULL))) {
    switch (opts) {
    case 'a':
      activate = 1;
      break;
    case 'd':
      deactivate = 1;
      break;
    case 't':
      toggle = 1;
      break;
    case 'v':
      verbose++;
      if (verbose > 2) {
        fprintf(stderr, "Invalid -v switches count\n");
        exit(EX_USAGE);
      }
      break;
    case 'h':
      show_help();
      break;
    default:
      fprintf(stderr, "Unknown option: %c\n", opts);
      exit(EX_USAGE);
      break;
    }
  }
  if (1 == activate) {
    f = fopen("/sys/kernel/mm/uksm"
              "/run",
              "w");
    if (NULL == f) {
      fprintf(stderr, "Unable to open run file\n");
      exit(EX_OSFILE);
    }
    if (fprintf(f, "%d", 1) < 0) {
      fprintf(stderr, "Unable to write to run file\n");
      fclose(f);
      exit(EX_OSFILE);
    }
    if (0 != fclose(f)) {
      fprintf(stderr, "Unable to close run file\n");
      exit(EX_OSFILE);
    }
    switch (verbose) {
    case 1:
      fprintf(stdout, "1\n");
      break;
    case 2:
      fprintf(stdout, "UKSM activated\n");
    }
    exit(EX_OK);
  }
  if (1 == deactivate) {
    f = fopen("/sys/kernel/mm/uksm"
              "/run",
              "w");
    if (NULL == f) {
      fprintf(stderr, "Unable to open run file\n");
      exit(EX_OSFILE);
    }
    if (fprintf(f, "%d", 0) < 0) {
      fprintf(stderr, "Unable to write to run file\n");
      fclose(f);
      exit(EX_OSFILE);
    }
    if (0 != fclose(f)) {
      fprintf(stderr, "Unable to close run file\n");
      exit(EX_OSFILE);
    }
    switch (verbose) {
    case 1:
      fprintf(stdout, "0\n");
    case 2:
      fprintf(stdout, "UKSM deactivated\n");
    }
    exit(EX_OK);
  }
  if (1 == toggle) {
    f = fopen("/sys/kernel/mm/uksm"
              "/run",
              "r");
    if (NULL == f) {
      fprintf(stderr, "Unable to open run file\n");
      exit(EX_OSFILE);
    }
    unsigned int run = 0;
    errno = 0;
    fscanf(f, "%u", &run);
    if (0 != errno) {
      fprintf(stderr, "Unable to read run file\n");
      fclose(f);
      exit(EX_OSFILE);
    }
    if (0 != fclose(f)) {
      fprintf(stderr, "Unable to close run file\n");
      exit(EX_OSFILE);
    }
    switch (run) {
    case 0:
      run = 1;
      switch (verbose) {
      case 2:
        fprintf(stdout, "UKSM was inactive, activating\n");
        break;
      }
      break;
    case 1:
      run = 0;
      switch (verbose) {
      case 2:
        fprintf(stdout, "UKSM was active, deactivating\n");
        break;
      }
      break;
    }
    f = fopen("/sys/kernel/mm/uksm"
              "/run",
              "w");
    if (NULL == f) {
      fprintf(stderr, "Unable to open run file\n");
      exit(EX_OSFILE);
    }
    if (fprintf(f, "%d", run) < 0) {
      fprintf(stderr, "Unable to write to run file\n");
      fclose(f);
      exit(EX_OSFILE);
    }
    if (0 != fclose(f)) {
      fprintf(stderr, "Unable to close run file\n");
      exit(EX_OSFILE);
    }
    switch (run) {
    case 0:
      switch (verbose) {
      case 1:
        fprintf(stdout, "0\n");
        break;
      case 2:
        fprintf(stdout, "UKSM deactivated\n");
        break;
      }
      break;
    case 1:
      switch (verbose) {
      case 1:
        fprintf(stdout, "1\n");
        break;
      case 2:
        fprintf(stdout, "UKSM activated\n");
        break;
      }
      break;
    }
    exit(EX_OK);
  }
  return EX_OK;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1226 <main+0x76>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    0xe58(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1090 <stat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1282 <main+0xd2>
mov    -0x28(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1282 <main+0xd2>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
lea    0xe18(%rip),%rdx
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    -0xf0(%rbp),%rdi
lea    0x2a90(%rip),%rsi
mov    $0xc0,%edx
call   10a0 <memcpy@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0xf0(%rbp),%rcx
lea    0xe2e(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1050 <getopt_long@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     1394 <main+0x1e4>
mov    -0x14(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x100(%rbp)
sub    $0x15,%eax
ja     1367 <main+0x1b7>
mov    -0x100(%rbp),%rax
lea    0xd0f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x18(%rbp)
jmp    138f <main+0x1df>
movl   $0x1,-0x1c(%rbp)
jmp    138f <main+0x1df>
movl   $0x1,-0x20(%rbp)
jmp    138f <main+0x1df>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x2,-0x24(%rbp)
jle    1356 <main+0x1a6>
mov    0x2c90(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2c89(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    138f <main+0x1df>
mov    $0x0,%al
call   10b0 <show_help@plt>
jmp    138f <main+0x1df>
mov    0x2c5a(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xd84(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2c50(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    129a <main+0xea>
mov    $0x1,%eax
cmp    -0x18(%rbp),%eax
jne    14e3 <main+0x333>
lea    0xd69(%rip),%rdi
lea    0xd7a(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    13ea <main+0x23a>
mov    0x2bfc(%rip),%rax
mov    (%rax),%edi
lea    0xd57(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2bdd(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %eax,%edi
lea    0xd4e(%rip),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1080 <fprintf@plt>
cmp    $0x0,%rax
jge    143b <main+0x28b>
mov    0x2bb4(%rip),%rax
mov    (%rax),%edi
lea    0xd2b(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2b8c(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1477 <main+0x2c7>
mov    0x2b6f(%rip),%rax
mov    (%rax),%edi
lea    0xd03(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2b50(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x104(%rbp)
sub    $0x1,%eax
je     14a2 <main+0x2f2>
jmp    148e <main+0x2de>
mov    -0x104(%rbp),%eax
sub    $0x2,%eax
je     14be <main+0x30e>
jmp    14d5 <main+0x325>
mov    0x2b07(%rip),%rax
mov    (%rax),%edi
lea    0xccd(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    14d5 <main+0x325>
mov    0x2aeb(%rip),%rax
mov    (%rax),%edi
lea    0xcb4(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2acc(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    $0x1,%eax
cmp    -0x1c(%rbp),%eax
jne    162a <main+0x47a>
lea    0xc1a(%rip),%rdi
lea    0xc2b(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    1539 <main+0x389>
mov    0x2aad(%rip),%rax
mov    (%rax),%edi
lea    0xc08(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2a8e(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %eax,%edi
lea    0xbff(%rip),%rsi
xor    %edx,%edx
mov    $0x0,%al
call   1080 <fprintf@plt>
cmp    $0x0,%rax
jge    1587 <main+0x3d7>
mov    0x2a68(%rip),%rax
mov    (%rax),%edi
lea    0xbdf(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2a40(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     15c3 <main+0x413>
mov    0x2a23(%rip),%rax
mov    (%rax),%edi
lea    0xbb7(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2a04(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x108(%rbp)
sub    $0x1,%eax
je     15ee <main+0x43e>
jmp    15da <main+0x42a>
mov    -0x108(%rbp),%eax
sub    $0x2,%eax
je     1605 <main+0x455>
jmp    161c <main+0x46c>
mov    0x29bb(%rip),%rax
mov    (%rax),%edi
lea    0xb94(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x29a4(%rip),%rax
mov    (%rax),%edi
lea    0xb80(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2985(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    $0x1,%eax
cmp    -0x20(%rbp),%eax
jne    199d <main+0x7ed>
lea    0xad3(%rip),%rdi
lea    0xb61(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    1680 <main+0x4d0>
mov    0x2966(%rip),%rax
mov    (%rax),%edi
lea    0xac1(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2947(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
movl   $0x0,-0xf4(%rbp)
mov    0x2927(%rip),%rax
movq   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
lea    0xb06(%rip),%rsi
lea    -0xf4(%rbp),%rdx
call   1070 <fscanf@plt>
xor    %eax,%eax
mov    0x2900(%rip),%rcx
cmp    (%rcx),%rax
je     16ef <main+0x53f>
mov    0x2900(%rip),%rax
mov    (%rax),%edi
lea    0xadb(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x28d8(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     172b <main+0x57b>
mov    0x28bb(%rip),%rax
mov    (%rax),%edi
lea    0xa4f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x289c(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0xf4(%rbp),%eax
mov    %eax,-0x10c(%rbp)
test   %eax,%eax
je     1758 <main+0x5a8>
jmp    1744 <main+0x594>
mov    -0x10c(%rbp),%eax
sub    $0x1,%eax
je     178f <main+0x5df>
jmp    17c6 <main+0x616>
movl   $0x1,-0xf4(%rbp)
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
jne    178a <main+0x5da>
jmp    1773 <main+0x5c3>
mov    0x2836(%rip),%rax
mov    (%rax),%edi
lea    0xa42(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    17c6 <main+0x616>
movl   $0x0,-0xf4(%rbp)
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
jne    17c1 <main+0x611>
jmp    17aa <main+0x5fa>
mov    0x27ff(%rip),%rax
mov    (%rax),%edi
lea    0xa2a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    17c6 <main+0x616>
lea    0x945(%rip),%rdi
lea    0x956(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    180e <main+0x65e>
mov    0x27d8(%rip),%rax
mov    (%rax),%edi
lea    0x933(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x27b9(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %eax,%edi
mov    -0xf4(%rbp),%edx
lea    0x924(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
cmp    $0x0,%rax
jge    1860 <main+0x6b0>
mov    0x278f(%rip),%rax
mov    (%rax),%edi
lea    0x906(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2767(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     189c <main+0x6ec>
mov    0x274a(%rip),%rax
mov    (%rax),%edi
lea    0x8de(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x272b(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0xf4(%rbp),%eax
mov    %eax,-0x110(%rbp)
test   %eax,%eax
je     18c9 <main+0x719>
jmp    18b5 <main+0x705>
mov    -0x110(%rbp),%eax
sub    $0x1,%eax
je     192c <main+0x77c>
jmp    198f <main+0x7df>
mov    -0x24(%rbp),%eax
mov    %eax,-0x114(%rbp)
sub    $0x1,%eax
je     18f4 <main+0x744>
jmp    18e0 <main+0x730>
mov    -0x114(%rbp),%eax
sub    $0x2,%eax
je     1910 <main+0x760>
jmp    1927 <main+0x777>
mov    0x26b5(%rip),%rax
mov    (%rax),%edi
lea    0x88e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1927 <main+0x777>
mov    0x2699(%rip),%rax
mov    (%rax),%edi
lea    0x875(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    198f <main+0x7df>
mov    -0x24(%rbp),%eax
mov    %eax,-0x118(%rbp)
sub    $0x1,%eax
je     1957 <main+0x7a7>
jmp    1943 <main+0x793>
mov    -0x118(%rbp),%eax
sub    $0x2,%eax
je     1973 <main+0x7c3>
jmp    198a <main+0x7da>
mov    0x2652(%rip),%rax
mov    (%rax),%edi
lea    0x818(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    198a <main+0x7da>
mov    0x2636(%rip),%rax
mov    (%rax),%edi
lea    0x7ff(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    198f <main+0x7df>
mov    0x2612(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    0x2604(%rip),%rax
mov    (%rax),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <getuid@plt>
test   %rax,%rax
jne    1313 <main+0x163>
lea    0xea8(%rip),%rdi
lea    0x18(%rsp),%rsi
call   1090 <stat@plt>
test   %rax,%rax
je     11fe <main+0x4e>
mov    0x18(%rsp),%edi
call   1060 <S_ISDIR@plt>
test   %rax,%rax
jne    143f <main+0x28f>
lea    0x2b1b(%rip),%rsi
lea    0x20(%rsp),%r14
mov    $0xc0,%edx
mov    %r14,%rdi
call   10a0 <memcpy@plt>
lea    0xebf(%rip),%r15
lea    0xddb(%rip),%r12
movl   $0x0,0x14(%rsp)
xor    %r13d,%r13d
movl   $0x0,0x10(%rsp)
xor    %eax,%eax
mov    %rax,0x8(%rsp)
jmp    1257 <main+0xa7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10b0 <show_help@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %r8d,%r8d
call   1050 <getopt_long@plt>
cmp    $0x68,%eax
je     1250 <main+0xa0>
lea    -0x61(%rax),%ecx
cmp    $0x15,%ecx
ja     12b0 <main+0x100>
movslq (%r12,%rcx,4),%rcx
add    %r12,%rcx
jmp    *%rcx
mov    $0x1,%r13b
jmp    1257 <main+0xa7>
mov    0x8(%rsp),%rcx
lea    0x1(%rcx),%eax
cmp    $0x2,%ecx
mov    %rax,0x8(%rsp)
jl     1257 <main+0xa7>
jmp    1423 <main+0x273>
movl   $0x1,0x14(%rsp)
jmp    1257 <main+0xa7>
movl   $0x1,0x10(%rsp)
jmp    1257 <main+0xa7>
cmp    $0xffffffff,%eax
jne    12ec <main+0x13c>
test   $0x1,%r13b
jne    1338 <main+0x188>
cmpl   $0x1,0x14(%rsp)
je     13a4 <main+0x1f4>
cmpl   $0x1,0x10(%rsp)
je     13ef <main+0x23f>
mov    0x2cd0(%rip),%rax
mov    (%rax),%eax
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cd5(%rip),%rcx
mov    (%rcx),%edi
lea    0xe02(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    0x2cae(%rip),%rax
mov    (%rax),%edi
lea    0xd35(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    0xdd3(%rip),%rdi
lea    0xde4(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1407 <main+0x257>
mov    %rax,%rbx
lea    0xde7(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
test   %rax,%rax
js     13da <main+0x22a>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
jne    161c <main+0x46c>
cmpl   $0x1,0x8(%rsp)
je     1555 <main+0x3a5>
cmpl   $0x2,0x8(%rsp)
jne    156c <main+0x3bc>
lea    0xde3(%rip),%rsi
jmp    155c <main+0x3ac>
lea    0xd67(%rip),%rdi
lea    0xd78(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1407 <main+0x257>
mov    %rax,%rbx
lea    0xd7f(%rip),%rsi
mov    %ebx,%edi
xor    %edx,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
test   %rax,%rax
jns    14e0 <main+0x330>
mov    0x2be7(%rip),%rax
mov    (%rax),%edi
lea    0xd5e(%rip),%rsi
jmp    1538 <main+0x388>
lea    0xd1c(%rip),%rdi
lea    0xdaa(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
jne    1462 <main+0x2b2>
mov    0x2bba(%rip),%rax
mov    (%rax),%edi
lea    0xd15(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1547 <main+0x397>
mov    0x2b9e(%rip),%rax
mov    (%rax),%edi
lea    0xcb0(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1305 <main+0x155>
mov    0x2b82(%rip),%rax
mov    (%rax),%edi
lea    0xc4a(%rip),%rsi
lea    0xc2f(%rip),%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1547 <main+0x397>
mov    %rax,%rbx
movl   $0x0,0x4(%rsp)
mov    0x2b44(%rip),%rbp
movq   $0x0,0x0(%rbp)
lea    0xd26(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1070 <fscanf@plt>
cmpq   $0x0,0x0(%rbp)
jne    1528 <main+0x378>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
jne    161c <main+0x46c>
mov    0x4(%rsp),%eax
cmp    $0x1,%eax
je     157a <main+0x3ca>
test   %eax,%eax
jne    15a0 <main+0x3f0>
movl   $0x1,0x4(%rsp)
cmpl   $0x2,0x8(%rsp)
jne    15a0 <main+0x3f0>
lea    0xcea(%rip),%rsi
jmp    1590 <main+0x3e0>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
jne    161c <main+0x46c>
cmpl   $0x2,0x8(%rsp)
je     1516 <main+0x366>
cmpl   $0x1,0x8(%rsp)
jne    156c <main+0x3bc>
mov    0x2aaa(%rip),%rax
mov    (%rax),%edi
lea    0xc83(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2a93(%rip),%rax
mov    (%rax),%edi
lea    0xc6f(%rip),%rsi
jmp    1565 <main+0x3b5>
mov    0x2a99(%rip),%rax
mov    (%rax),%edi
lea    0xc74(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2a72(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    0xc23(%rip),%rsi
mov    0x2a4d(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2a35(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
movl   $0x0,0x4(%rsp)
cmpl   $0x2,0x8(%rsp)
jne    15a0 <main+0x3f0>
lea    0xc54(%rip),%rsi
mov    0x2a19(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xb6b(%rip),%rdi
lea    0xb7c(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1407 <main+0x257>
mov    %rax,%rbx
mov    0x4(%rsp),%edx
lea    0xb7b(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1080 <fprintf@plt>
test   %rax,%rax
js     13da <main+0x22a>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
jne    161c <main+0x46c>
mov    0x4(%rsp),%eax
cmp    $0x1,%eax
je     1382 <main+0x1d2>
test   %eax,%eax
jne    156c <main+0x3bc>
cmpl   $0x1,0x8(%rsp)
je     1631 <main+0x481>
cmpl   $0x2,0x8(%rsp)
jne    156c <main+0x3bc>
lea    0xb7e(%rip),%rsi
jmp    155c <main+0x3ac>
mov    0x29a5(%rip),%rax
mov    (%rax),%edi
lea    0xb39(%rip),%rsi
jmp    1417 <main+0x267>
lea    0xb5a(%rip),%rsi
jmp    155c <main+0x3ac>

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32*, i32 }
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [45 x i8] c"You have to be root in order to use uksmctl\0A\00"
@EX_NOPERM = global i32 0
@.str.1 = [20 x i8] c"/sys/kernel/mm/uksm\00"
@.str.2 = [37 x i8] c"Unable to find uksm interface in %s\0A\00"
@EX_OSFILE = global i32 0
@.str.3 = [9 x i8] c"activate\00"
@.str.4 = [11 x i8] c"deactivate\00"
@.str.5 = [7 x i8] c"toggle\00"
@.str.6 = [8 x i8] c"verbose\00"
@.str.7 = [5 x i8] c"help\00"
@__const.main.longopts = [6 x %struct.option] [%struct.option { i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i32 0, i32 0), i8 0, i32* null, i32 97 }, %struct.option { i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i32 0, i32 0), i8 0, i32* null, i32 100 }, %struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i32 0, i32 0), i8 0, i32* null, i32 116 }, %struct.option { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i32 0, i32 0), i8 0, i32* null, i32 118 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i32 0, i32 0), i8 0, i32* null, i32 104 }, %struct.option zeroinitializer]
@.str.8 = [6 x i8] c"adtvh\00"
@.str.9 = [27 x i8] c"Invalid -v switches count\0A\00"
@EX_USAGE = global i32 0
@.str.10 = [20 x i8] c"Unknown option: %c\0A\00"
@.str.11 = [24 x i8] c"/sys/kernel/mm/uksm/run\00"
@.str.12 = [2 x i8] c"w\00"
@.str.13 = [25 x i8] c"Unable to open run file\0A\00"
@.str.14 = [3 x i8] c"%d\00"
@.str.15 = [29 x i8] c"Unable to write to run file\0A\00"
@.str.16 = [26 x i8] c"Unable to close run file\0A\00"
@stdout = global i32 0
@.str.17 = [3 x i8] c"1\0A\00"
@.str.18 = [16 x i8] c"UKSM activated\0A\00"
@EX_OK = global i32 0
@.str.19 = [3 x i8] c"0\0A\00"
@.str.20 = [18 x i8] c"UKSM deactivated\0A\00"
@.str.21 = [2 x i8] c"r\00"
@errno = global i64 0
@.str.22 = [3 x i8] c"%u\00"
@.str.23 = [25 x i8] c"Unable to read run file\0A\00"
@.str.24 = [31 x i8] c"UKSM was inactive, activating\0A\00"
@.str.25 = [31 x i8] c"UKSM was active, deactivating\0A\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 i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.stat
%12 = alloca i32*
%13 = alloca [6 x %struct.option]
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%15 = call i64 (...) @getuid()
%16 = icmp ne i64 0, %15
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i64 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EX_NOPERM
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = call i64 @stat(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %11)
%24 = icmp ne i64 0, %23
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i64 @S_ISDIR(i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = call i64 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%33 = load i32, i32* @EX_OSFILE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %25, %22
%36 = bitcast [6 x %struct.option]* %13 to i8*
br label %37
37: ; preds = %67, %35
%38 = load i32, i32* %4
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds [6 x %struct.option], [6 x %struct.option]* %13, i64 0, i64 0
%41 = call i32 @getopt_long(i32 %38, i8** %39, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), %struct.option* %40, i32* null)
store i32 %41, i32* %6
%42 = icmp ne i32 -1, %41
br i1 %42, label %43, label %68
43: ; preds = %37
%44 = load i32, i32* %6
switch i32 %44, label %61 [
i32 97, label %45
i32 100, label %46
i32 116, label %47
i32 118, label %48
i32 104, label %59
]
45: ; preds = %43
store i32 1, i32* %7
br label %67
46: ; preds = %43
store i32 1, i32* %8
br label %67
47: ; preds = %43
store i32 1, i32* %9
br label %67
48: ; preds = %43
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 1
store i32 %50, i32* %10
%51 = load i32, i32* %10
%52 = icmp sgt i32 %51, 2
br i1 %52, label %53, label %58
53: ; preds = %48
%54 = load i32, i32* @stderr
%55 = call i64 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%56 = load i32, i32* @EX_USAGE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %48
br label %67
59: ; preds = %43
%60 = call i32 (...) @show_help()
br label %67
61: ; preds = %43
%62 = load i32, i32* @stderr
%63 = load i32, i32* %6
%64 = call i64 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i32 %63)
%65 = load i32, i32* @EX_USAGE
%66 = call i32 @exit(i32 %65)
unreachable
67: ; preds = %59, %58, %47, %46, %45
br label %37
68: ; preds = %37
%69 = load i32, i32* %7
%70 = icmp eq i32 1, %69
br i1 %70, label %71, label %112
71: ; preds = %68
%72 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
store i32* %72, i32** %12
%73 = load i32*, i32** %12
%74 = icmp eq i32* null, %73
br i1 %74, label %75, label %80
75: ; preds = %71
%76 = load i32, i32* @stderr
%77 = call i64 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0))
%78 = load i32, i32* @EX_OSFILE
%79 = call i32 @exit(i32 %78)
unreachable
80: ; preds = %71
%81 = load i32*, i32** %12
%82 = ptrtoint i32* %81 to i32
%83 = call i64 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0), i32 1)
%84 = icmp slt i64 %83, 0
br i1 %84, label %85, label %92
85: ; preds = %80
%86 = load i32, i32* @stderr
%87 = call i64 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.15, i64 0, i64 0))
%88 = load i32*, i32** %12
%89 = call i64 @fclose(i32* %88)
%90 = load i32, i32* @EX_OSFILE
%91 = call i32 @exit(i32 %90)
unreachable
92: ; preds = %80
%93 = load i32*, i32** %12
%94 = call i64 @fclose(i32* %93)
%95 = icmp ne i64 0, %94
br i1 %95, label %96, label %101
96: ; preds = %92
%97 = load i32, i32* @stderr
%98 = call i64 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.16, i64 0, i64 0))
%99 = load i32, i32* @EX_OSFILE
%100 = call i32 @exit(i32 %99)
unreachable
101: ; preds = %92
%102 = load i32, i32* %10
switch i32 %102, label %109 [
i32 1, label %103
i32 2, label %106
]
103: ; preds = %101
%104 = load i32, i32* @stdout
%105 = call i64 (i32, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.17, i64 0, i64 0))
br label %109
106: ; preds = %101
%107 = load i32, i32* @stdout
%108 = call i64 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.18, i64 0, i64 0))
br label %109
109: ; preds = %106, %101, %103
%110 = load i32, i32* @EX_OK
%111 = call i32 @exit(i32 %110)
unreachable
112: ; preds = %68
%113 = load i32, i32* %8
%114 = icmp eq i32 1, %113
br i1 %114, label %115, label %156
115: ; preds = %112
%116 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
store i32* %116, i32** %12
%117 = load i32*, i32** %12
%118 = icmp eq i32* null, %117
br i1 %118, label %119, label %124
119: ; preds = %115
%120 = load i32, i32* @stderr
%121 = call i64 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0))
%122 = load i32, i32* @EX_OSFILE
%123 = call i32 @exit(i32 %122)
unreachable
124: ; preds = %115
%125 = load i32*, i32** %12
%126 = ptrtoint i32* %125 to i32
%127 = call i64 (i32, i8*, ...) @fprintf(i32 %126, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0), i32 0)
%128 = icmp slt i64 %127, 0
br i1 %128, label %129, label %136
129: ; preds = %124
%130 = load i32, i32* @stderr
%131 = call i64 (i32, i8*, ...) @fprintf(i32 %130, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.15, i64 0, i64 0))
%132 = load i32*, i32** %12
%133 = call i64 @fclose(i32* %132)
%134 = load i32, i32* @EX_OSFILE
%135 = call i32 @exit(i32 %134)
unreachable
136: ; preds = %124
%137 = load i32*, i32** %12
%138 = call i64 @fclose(i32* %137)
%139 = icmp ne i64 0, %138
br i1 %139, label %140, label %145
140: ; preds = %136
%141 = load i32, i32* @stderr
%142 = call i64 (i32, i8*, ...) @fprintf(i32 %141, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.16, i64 0, i64 0))
%143 = load i32, i32* @EX_OSFILE
%144 = call i32 @exit(i32 %143)
unreachable
145: ; preds = %136
%146 = load i32, i32* %10
switch i32 %146, label %153 [
i32 1, label %147
i32 2, label %150
]
147: ; preds = %145
%148 = load i32, i32* @stdout
%149 = call i64 (i32, i8*, ...) @fprintf(i32 %148, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.19, i64 0, i64 0))
br label %150
150: ; preds = %145, %147
%151 = load i32, i32* @stdout
%152 = call i64 (i32, i8*, ...) @fprintf(i32 %151, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.20, i64 0, i64 0))
br label %153
153: ; preds = %150, %145
%154 = load i32, i32* @EX_OK
%155 = call i32 @exit(i32 %154)
unreachable
156: ; preds = %112
%157 = load i32, i32* %9
%158 = icmp eq i32 1, %157
br i1 %158, label %159, label %257
159: ; preds = %156
%160 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.21, i64 0, i64 0))
store i32* %160, i32** %12
%161 = load i32*, i32** %12
%162 = icmp eq i32* null, %161
br i1 %162, label %163, label %168
163: ; preds = %159
%164 = load i32, i32* @stderr
%165 = call i64 (i32, i8*, ...) @fprintf(i32 %164, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0))
%166 = load i32, i32* @EX_OSFILE
%167 = call i32 @exit(i32 %166)
unreachable
168: ; preds = %159
store i32 0, i32* %14
store i64 0, i64* @errno
%169 = load i32*, i32** %12
%170 = call i32 @fscanf(i32* %169, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.22, i64 0, i64 0), i32* %14)
%171 = load i64, i64* @errno
%172 = icmp ne i64 0, %171
br i1 %172, label %173, label %180
173: ; preds = %168
%174 = load i32, i32* @stderr
%175 = call i64 (i32, i8*, ...) @fprintf(i32 %174, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.23, i64 0, i64 0))
%176 = load i32*, i32** %12
%177 = call i64 @fclose(i32* %176)
%178 = load i32, i32* @EX_OSFILE
%179 = call i32 @exit(i32 %178)
unreachable
180: ; preds = %168
%181 = load i32*, i32** %12
%182 = call i64 @fclose(i32* %181)
%183 = icmp ne i64 0, %182
br i1 %183, label %184, label %189
184: ; preds = %180
%185 = load i32, i32* @stderr
%186 = call i64 (i32, i8*, ...) @fprintf(i32 %185, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.16, i64 0, i64 0))
%187 = load i32, i32* @EX_OSFILE
%188 = call i32 @exit(i32 %187)
unreachable
189: ; preds = %180
%190 = load i32, i32* %14
switch i32 %190, label %203 [
i32 0, label %191
i32 1, label %197
]
191: ; preds = %189
store i32 1, i32* %14
%192 = load i32, i32* %10
switch i32 %192, label %196 [
i32 2, label %193
]
193: ; preds = %191
%194 = load i32, i32* @stdout
%195 = call i64 (i32, i8*, ...) @fprintf(i32 %194, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.24, i64 0, i64 0))
br label %196
196: ; preds = %191, %193
br label %203
197: ; preds = %189
store i32 0, i32* %14
%198 = load i32, i32* %10
switch i32 %198, label %202 [
i32 2, label %199
]
199: ; preds = %197
%200 = load i32, i32* @stdout
%201 = call i64 (i32, i8*, ...) @fprintf(i32 %200, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.25, i64 0, i64 0))
br label %202
202: ; preds = %197, %199
br label %203
203: ; preds = %189, %202, %196
%204 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
store i32* %204, i32** %12
%205 = load i32*, i32** %12
%206 = icmp eq i32* null, %205
br i1 %206, label %207, label %212
207: ; preds = %203
%208 = load i32, i32* @stderr
%209 = call i64 (i32, i8*, ...) @fprintf(i32 %208, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0))
%210 = load i32, i32* @EX_OSFILE
%211 = call i32 @exit(i32 %210)
unreachable
212: ; preds = %203
%213 = load i32*, i32** %12
%214 = ptrtoint i32* %213 to i32
%215 = load i32, i32* %14
%216 = call i64 (i32, i8*, ...) @fprintf(i32 %214, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0), i32 %215)
%217 = icmp slt i64 %216, 0
br i1 %217, label %218, label %225
218: ; preds = %212
%219 = load i32, i32* @stderr
%220 = call i64 (i32, i8*, ...) @fprintf(i32 %219, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.15, i64 0, i64 0))
%221 = load i32*, i32** %12
%222 = call i64 @fclose(i32* %221)
%223 = load i32, i32* @EX_OSFILE
%224 = call i32 @exit(i32 %223)
unreachable
225: ; preds = %212
%226 = load i32*, i32** %12
%227 = call i64 @fclose(i32* %226)
%228 = icmp ne i64 0, %227
br i1 %228, label %229, label %234
229: ; preds = %225
%230 = load i32, i32* @stderr
%231 = call i64 (i32, i8*, ...) @fprintf(i32 %230, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.16, i64 0, i64 0))
%232 = load i32, i32* @EX_OSFILE
%233 = call i32 @exit(i32 %232)
unreachable
234: ; preds = %225
%235 = load i32, i32* %14
switch i32 %235, label %254 [
i32 0, label %236
i32 1, label %245
]
236: ; preds = %234
%237 = load i32, i32* %10
switch i32 %237, label %244 [
i32 1, label %238
i32 2, label %241
]
238: ; preds = %236
%239 = load i32, i32* @stdout
%240 = call i64 (i32, i8*, ...) @fprintf(i32 %239, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.19, i64 0, i64 0))
br label %244
241: ; preds = %236
%242 = load i32, i32* @stdout
%243 = call i64 (i32, i8*, ...) @fprintf(i32 %242, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.20, i64 0, i64 0))
br label %244
244: ; preds = %236, %241, %238
br label %254
245: ; preds = %234
%246 = load i32, i32* %10
switch i32 %246, label %253 [
i32 1, label %247
i32 2, label %250
]
247: ; preds = %245
%248 = load i32, i32* @stdout
%249 = call i64 (i32, i8*, ...) @fprintf(i32 %248, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.17, i64 0, i64 0))
br label %253
250: ; preds = %245
%251 = load i32, i32* @stdout
%252 = call i64 (i32, i8*, ...) @fprintf(i32 %251, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.18, i64 0, i64 0))
br label %253
253: ; preds = %245, %250, %247
br label %254
254: ; preds = %234, %253, %244
%255 = load i32, i32* @EX_OK
%256 = call i32 @exit(i32 %255)
unreachable
257: ; preds = %156
%258 = load i32, i32* @EX_OK
ret i32 %258
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32*, i32 }
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [45 x i8] c"You have to be root in order to use uksmctl\0A\00"
@EX_NOPERM = global i32 0
@.str.1 = [20 x i8] c"/sys/kernel/mm/uksm\00"
@.str.2 = [37 x i8] c"Unable to find uksm interface in %s\0A\00"
@EX_OSFILE = global i32 0
@.str.3 = [9 x i8] c"activate\00"
@.str.4 = [11 x i8] c"deactivate\00"
@.str.5 = [7 x i8] c"toggle\00"
@.str.6 = [8 x i8] c"verbose\00"
@.str.7 = [5 x i8] c"help\00"
@__const.main.longopts = [6 x %struct.option] [%struct.option { i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i32 0, i32 0), i8 0, i32* null, i32 97 }, %struct.option { i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i32 0, i32 0), i8 0, i32* null, i32 100 }, %struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i32 0, i32 0), i8 0, i32* null, i32 116 }, %struct.option { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i32 0, i32 0), i8 0, i32* null, i32 118 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i32 0, i32 0), i8 0, i32* null, i32 104 }, %struct.option zeroinitializer]
@.str.8 = [6 x i8] c"adtvh\00"
@.str.9 = [27 x i8] c"Invalid -v switches count\0A\00"
@EX_USAGE = global i32 0
@.str.10 = [20 x i8] c"Unknown option: %c\0A\00"
@.str.11 = [24 x i8] c"/sys/kernel/mm/uksm/run\00"
@.str.12 = [2 x i8] c"w\00"
@.str.13 = [25 x i8] c"Unable to open run file\0A\00"
@.str.14 = [3 x i8] c"%d\00"
@.str.15 = [29 x i8] c"Unable to write to run file\0A\00"
@.str.16 = [26 x i8] c"Unable to close run file\0A\00"
@stdout = global i32 0
@.str.17 = [3 x i8] c"1\0A\00"
@.str.18 = [16 x i8] c"UKSM activated\0A\00"
@EX_OK = global i32 0
@.str.19 = [3 x i8] c"0\0A\00"
@.str.20 = [18 x i8] c"UKSM deactivated\0A\00"
@.str.21 = [2 x i8] c"r\00"
@errno = global i64 0
@.str.22 = [3 x i8] c"%u\00"
@.str.23 = [25 x i8] c"Unable to read run file\0A\00"
@.str.24 = [31 x i8] c"UKSM was inactive, activating\0A\00"
@.str.25 = [31 x i8] c"UKSM was active, deactivating\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.stat
%4 = alloca [6 x %struct.option]
%5 = alloca i32
%6 = bitcast %struct.stat* %3 to i8*
%7 = tail call i64 (...) @getuid()
%8 = icmp eq i64 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i64 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EX_NOPERM
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = call i64 @stat(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %27, label %17
17: ; preds = %14
%18 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%19 = load i32, i32* %18
%20 = call i64 @S_ISDIR(i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = call i64 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @EX_OSFILE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %17, %14
%28 = bitcast [6 x %struct.option]* %4 to i8*
%29 = getelementptr inbounds [6 x %struct.option], [6 x %struct.option]* %4, i64 0, i64 0
br label %30
30: ; preds = %44, %27
%31 = phi i1 [ false, %27 ], [ true, %44 ]
%32 = phi i32 [ 0, %27 ], [ %36, %44 ]
%33 = phi i32 [ 0, %27 ], [ %40, %44 ]
%34 = phi i32 [ 0, %27 ], [ %43, %44 ]
br label %35
35: ; preds = %44, %30
%36 = phi i32 [ %32, %30 ], [ 1, %44 ]
%37 = phi i32 [ %33, %30 ], [ %40, %44 ]
%38 = phi i32 [ %34, %30 ], [ %43, %44 ]
br label %39
39: ; preds = %44, %35
%40 = phi i32 [ %37, %35 ], [ 1, %44 ]
%41 = phi i32 [ %38, %35 ], [ %43, %44 ]
br label %42
42: ; preds = %39, %46
%43 = phi i32 [ %41, %39 ], [ %47, %46 ]
br label %44
44: ; preds = %42, %54
%45 = call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), %struct.option* %29, i32* null)
switch i32 %45, label %56 [
i32 -1, label %61
i32 97, label %30
i32 100, label %35
i32 116, label %39
i32 118, label %46
i32 104, label %54
]
46: ; preds = %44
%47 = add nsw i32 %43, 1
%48 = icmp sgt i32 %43, 1
br i1 %48, label %49, label %42
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = call i64 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%52 = load i32, i32* @EX_USAGE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %44
%55 = call i32 (...) @show_help()
br label %44
56: ; preds = %44
%57 = load i32, i32* @stderr
%58 = call i64 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i32 %45)
%59 = load i32, i32* @EX_USAGE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %44
br i1 %31, label %62, label %98
62: ; preds = %61
%63 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%64 = icmp eq i32* %63, null
br i1 %64, label %65, label %70
65: ; preds = %62
%66 = load i32, i32* @stderr
%67 = call i64 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0))
%68 = load i32, i32* @EX_OSFILE
%69 = call i32 @exit(i32 %68)
unreachable
70: ; preds = %62
%71 = ptrtoint i32* %63 to i64
%72 = trunc i64 %71 to i32
%73 = call i64 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0), i32 1)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %81
75: ; preds = %70
%76 = load i32, i32* @stderr
%77 = call i64 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.15, i64 0, i64 0))
%78 = call i64 @fclose(i32* %63)
%79 = load i32, i32* @EX_OSFILE
%80 = call i32 @exit(i32 %79)
unreachable
81: ; preds = %70
%82 = call i64 @fclose(i32* %63)
%83 = icmp eq i64 %82, 0
br i1 %83, label %89, label %84
84: ; preds = %81
%85 = load i32, i32* @stderr
%86 = call i64 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.16, i64 0, i64 0))
%87 = load i32, i32* @EX_OSFILE
%88 = call i32 @exit(i32 %87)
unreachable
89: ; preds = %81
switch i32 %43, label %95 [
i32 1, label %91
i32 2, label %90
]
90: ; preds = %89
br label %91
91: ; preds = %89, %90
%92 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.18, i64 0, i64 0), %90 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.17, i64 0, i64 0), %89 ]
%93 = load i32, i32* @stdout
%94 = call i64 (i32, i8*, ...) @fprintf(i32 %93, i8* %92)
br label %95
95: ; preds = %91, %89
%96 = load i32, i32* @EX_OK
%97 = call i32 @exit(i32 %96)
unreachable
98: ; preds = %61
%99 = icmp eq i32 %36, 1
br i1 %99, label %100, label %137
100: ; preds = %98
%101 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%102 = icmp eq i32* %101, null
br i1 %102, label %103, label %108
103: ; preds = %100
%104 = load i32, i32* @stderr
%105 = call i64 (i32, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0))
%106 = load i32, i32* @EX_OSFILE
%107 = call i32 @exit(i32 %106)
unreachable
108: ; preds = %100
%109 = ptrtoint i32* %101 to i64
%110 = trunc i64 %109 to i32
%111 = call i64 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0), i32 0)
%112 = icmp slt i64 %111, 0
br i1 %112, label %113, label %119
113: ; preds = %108
%114 = load i32, i32* @stderr
%115 = call i64 (i32, i8*, ...) @fprintf(i32 %114, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.15, i64 0, i64 0))
%116 = call i64 @fclose(i32* %101)
%117 = load i32, i32* @EX_OSFILE
%118 = call i32 @exit(i32 %117)
unreachable
119: ; preds = %108
%120 = call i64 @fclose(i32* %101)
%121 = icmp eq i64 %120, 0
br i1 %121, label %127, label %122
122: ; preds = %119
%123 = load i32, i32* @stderr
%124 = call i64 (i32, i8*, ...) @fprintf(i32 %123, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.16, i64 0, i64 0))
%125 = load i32, i32* @EX_OSFILE
%126 = call i32 @exit(i32 %125)
unreachable
127: ; preds = %119
switch i32 %43, label %134 [
i32 1, label %128
i32 2, label %131
]
128: ; preds = %127
%129 = load i32, i32* @stdout
%130 = call i64 (i32, i8*, ...) @fprintf(i32 %129, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.19, i64 0, i64 0))
br label %131
131: ; preds = %127, %128
%132 = load i32, i32* @stdout
%133 = call i64 (i32, i8*, ...) @fprintf(i32 %132, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.20, i64 0, i64 0))
br label %134
134: ; preds = %131, %127
%135 = load i32, i32* @EX_OK
%136 = call i32 @exit(i32 %135)
unreachable
137: ; preds = %98
%138 = icmp eq i32 %40, 1
br i1 %138, label %139, label %217
139: ; preds = %137
%140 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.21, i64 0, i64 0))
%141 = icmp eq i32* %140, null
br i1 %141, label %142, label %147
142: ; preds = %139
%143 = load i32, i32* @stderr
%144 = call i64 (i32, i8*, ...) @fprintf(i32 %143, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0))
%145 = load i32, i32* @EX_OSFILE
%146 = call i32 @exit(i32 %145)
unreachable
147: ; preds = %139
%148 = bitcast i32* %5 to i8*
store i32 0, i32* %5
store i64 0, i64* @errno
%149 = call i32 @fscanf(i32* %140, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.22, i64 0, i64 0), i32* %5)
%150 = load i64, i64* @errno
%151 = icmp eq i64 %150, 0
br i1 %151, label %158, label %152
152: ; preds = %147
%153 = load i32, i32* @stderr
%154 = call i64 (i32, i8*, ...) @fprintf(i32 %153, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.23, i64 0, i64 0))
%155 = call i64 @fclose(i32* %140)
%156 = load i32, i32* @EX_OSFILE
%157 = call i32 @exit(i32 %156)
unreachable
158: ; preds = %147
%159 = call i64 @fclose(i32* %140)
%160 = icmp eq i64 %159, 0
br i1 %160, label %166, label %161
161: ; preds = %158
%162 = load i32, i32* @stderr
%163 = call i64 (i32, i8*, ...) @fprintf(i32 %162, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.16, i64 0, i64 0))
%164 = load i32, i32* @EX_OSFILE
%165 = call i32 @exit(i32 %164)
unreachable
166: ; preds = %158
%167 = load i32, i32* %5
switch i32 %167, label %176 [
i32 0, label %168
i32 1, label %170
]
168: ; preds = %166
store i32 1, i32* %5
%169 = icmp eq i32 %43, 2
br i1 %169, label %172, label %176
170: ; preds = %166
store i32 0, i32* %5
%171 = icmp eq i32 %43, 2
br i1 %171, label %172, label %176
172: ; preds = %170, %168
%173 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.24, i64 0, i64 0), %168 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.25, i64 0, i64 0), %170 ]
%174 = load i32, i32* @stdout
%175 = call i64 (i32, i8*, ...) @fprintf(i32 %174, i8* %173)
br label %176
176: ; preds = %172, %170, %168, %166
%177 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%178 = icmp eq i32* %177, null
br i1 %178, label %179, label %184
179: ; preds = %176
%180 = load i32, i32* @stderr
%181 = call i64 (i32, i8*, ...) @fprintf(i32 %180, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0))
%182 = load i32, i32* @EX_OSFILE
%183 = call i32 @exit(i32 %182)
unreachable
184: ; preds = %176
%185 = ptrtoint i32* %177 to i64
%186 = trunc i64 %185 to i32
%187 = load i32, i32* %5
%188 = call i64 (i32, i8*, ...) @fprintf(i32 %186, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0), i32 %187)
%189 = icmp slt i64 %188, 0
br i1 %189, label %190, label %196
190: ; preds = %184
%191 = load i32, i32* @stderr
%192 = call i64 (i32, i8*, ...) @fprintf(i32 %191, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.15, i64 0, i64 0))
%193 = call i64 @fclose(i32* %177)
%194 = load i32, i32* @EX_OSFILE
%195 = call i32 @exit(i32 %194)
unreachable
196: ; preds = %184
%197 = call i64 @fclose(i32* %177)
%198 = icmp eq i64 %197, 0
br i1 %198, label %204, label %199
199: ; preds = %196
%200 = load i32, i32* @stderr
%201 = call i64 (i32, i8*, ...) @fprintf(i32 %200, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.16, i64 0, i64 0))
%202 = load i32, i32* @EX_OSFILE
%203 = call i32 @exit(i32 %202)
unreachable
204: ; preds = %196
%205 = load i32, i32* %5
switch i32 %205, label %214 [
i32 0, label %206
i32 1, label %208
]
206: ; preds = %204
switch i32 %43, label %214 [
i32 1, label %210
i32 2, label %207
]
207: ; preds = %206
br label %210
208: ; preds = %204
switch i32 %43, label %214 [
i32 1, label %210
i32 2, label %209
]
209: ; preds = %208
br label %210
210: ; preds = %208, %206, %207, %209
%211 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.18, i64 0, i64 0), %209 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.20, i64 0, i64 0), %207 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.19, i64 0, i64 0), %206 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.17, i64 0, i64 0), %208 ]
%212 = load i32, i32* @stdout
%213 = call i64 (i32, i8*, ...) @fprintf(i32 %212, i8* %211)
br label %214
214: ; preds = %210, %208, %206, %204
%215 = load i32, i32* @EX_OK
%216 = call i32 @exit(i32 %215)
unreachable
217: ; preds = %137
%218 = load i32, i32* @EX_OK
ret i32 %218
}