#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_size;
};
typedef int /*<<< orphan*/ salt;
typedef int /*<<< orphan*/ cmd;

/* Variables and functions */
char *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
char *askpass(char *);
int /*<<< orphan*/ crypt_make_salt();
int /*<<< orphan*/ exit(int);
char *findstr(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char getopt(int, char **, char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, char, int);
char *mmap(int /*<<< orphan*/ *, int /*<<< orphan*/, int, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
char *optarg;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_help(char *);
int /*<<< orphan*/ printf(char *);
char *pw_encrypt(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char *);
int strlen(char *);
scalar_t__ system(char *);
int main(int argc, char **argv) {
  char salt[12];
  char *pass1, *pass2;
  char *cp;
  char c;
  char *input = NULL, *output = NULL;
  char *map;
  char *pw;
  int fd, n;
  struct stat sb;
  while ((c = getopt(argc, argv, "hi:o:")) != -1) {
    switch (c) {
    case 'h':
      print_help(argv[0]);
      exit(0);
      break;
    case 'i':
      input = strdup(optarg);
      break;
    case 'o':
      output = strdup(optarg);
      break;
    default:
      print_help(argv[0]);
      exit(1);
      break;
    }
  }
  if ((output == NULL) && (input == NULL)) {
    fprintf(stderr, "No files specified!\n");
    exit(1);
  }
  if (input == NULL) {
    fprintf(stderr, "No input file specified!\n");
    exit(1);
  }
  if (output && (output != input)) {
    char cmd[1024];
    snprintf(cmd, sizeof(cmd), "cp %s %s", input, output);
    if (system(cmd) != 0) {
      fprintf(stderr, "Copy failed!\n");
      exit(1);
    }
    input = output;
  }
  stat(input, &sb);
  if ((fd = open(input, O_RDWR)) < 0) {
    perror(input);
  }
  if ((map = mmap(NULL, sb.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
                  0)) == MAP_FAILED) {
    perror("mmap()");
    exit(1);
  }
  if ((pw = findstr(map, "mvpmc_root=", sb.st_size)) == NULL) {
    printf("Password not found in input file!\n");
    exit(1);
  }
  pw += 11;
  n = 0;
  while (pw[n] == 'X') {
    n++;
  }
  memset(salt, 0, sizeof(salt));
  strcpy(salt, "$1$");
  strcat(salt, crypt_make_salt());
  strcat(salt, crypt_make_salt());
  strcat(salt, crypt_make_salt());
  strcat(salt, crypt_make_salt());
  if ((pass1 = askpass("Type root password: ")) == NULL) {
    fprintf(stderr, "Invalid password!\n");
    exit(1);
  }
  pass1 = strdup(pass1);
  if ((pass2 = askpass("Type root password again: ")) == NULL) {
    fprintf(stderr, "Invalid password!\n");
    exit(1);
  }
  pass2 = strdup(pass2);
  if (strcmp(pass1, pass2) != 0) {
    fprintf(stderr, "Passwords do not match!\n");
    exit(1);
  }
  cp = pw_encrypt(pass1, salt);
  if (strlen(cp) > n) {
    printf("Not enough space to store password!\n");
    exit(1);
  }
  memset(pw, ' ', n);
  memcpy(pw, cp, strlen(cp));
  printf("Done\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd69(%rip),%rdx
call   1140 <getopt@plt>
mov    %al,-0x39(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     1349 <main+0xe9>
movsbl -0x39(%rbp),%eax
mov    %eax,-0x474(%rbp)
sub    $0x68,%eax
je     12eb <main+0x8b>
jmp    12c3 <main+0x63>
mov    -0x474(%rbp),%eax
sub    $0x69,%eax
je     12fe <main+0x9e>
jmp    12d7 <main+0x77>
mov    -0x474(%rbp),%eax
sub    $0x6f,%eax
je     1316 <main+0xb6>
jmp    132e <main+0xce>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1150 <print_help@plt>
xor    %edi,%edi
call   1170 <exit@plt>
mov    0x2cf3(%rip),%rax
mov    (%rax),%rdi
call   1180 <strdup@plt>
mov    %rax,-0x48(%rbp)
jmp    1344 <main+0xe4>
mov    0x2cdb(%rip),%rax
mov    (%rax),%rdi
call   1180 <strdup@plt>
mov    %rax,-0x50(%rbp)
jmp    1344 <main+0xe4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1150 <print_help@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
jmp    1289 <main+0x29>
cmpq   $0x0,-0x50(%rbp)
jne    137e <main+0x11e>
cmpq   $0x0,-0x48(%rbp)
jne    137e <main+0x11e>
mov    0x2c5a(%rip),%rax
mov    (%rax),%edi
lea    0xc97(%rip),%rsi
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
cmpq   $0x0,-0x48(%rbp)
jne    13a8 <main+0x148>
mov    0x2c30(%rip),%rax
mov    (%rax),%edi
lea    0xc82(%rip),%rsi
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
cmpq   $0x0,-0x50(%rbp)
je     141e <main+0x1be>
mov    -0x50(%rbp),%rax
cmp    -0x48(%rbp),%rax
je     141e <main+0x1be>
lea    -0x470(%rbp),%rdi
mov    -0x48(%rbp),%rcx
mov    -0x50(%rbp),%r8
mov    $0x400,%esi
lea    0xc59(%rip),%rdx
call   1090 <snprintf@plt>
lea    -0x470(%rbp),%rdi
call   1070 <system@plt>
cmp    $0x0,%rax
je     1416 <main+0x1b6>
mov    0x2bc2(%rip),%rax
mov    (%rax),%edi
lea    0xc37(%rip),%rsi
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   10f0 <stat@plt>
mov    -0x48(%rbp),%rdi
mov    0x2b9a(%rip),%rax
mov    (%rax),%esi
call   1120 <open@plt>
mov    %eax,-0x64(%rbp)
cmp    $0x0,%eax
jge    1452 <main+0x1f2>
mov    -0x48(%rbp),%rdi
call   1130 <perror@plt>
mov    -0x70(%rbp),%esi
mov    0x2b94(%rip),%rax
mov    (%rax),%edx
mov    0x2b53(%rip),%rax
or     (%rax),%edx
mov    0x2b72(%rip),%rax
mov    (%rax),%ecx
mov    -0x64(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,-0x58(%rbp)
mov    0x2b25(%rip),%rcx
cmp    (%rcx),%rax
jne    14aa <main+0x24a>
lea    0xbb1(%rip),%rdi
call   1130 <perror@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    -0x58(%rbp),%rdi
mov    -0x70(%rbp),%edx
lea    0xb9b(%rip),%rsi
call   10c0 <findstr@plt>
mov    %rax,-0x60(%rbp)
cmp    $0x0,%rax
jne    14e1 <main+0x281>
lea    0xb8d(%rip),%rdi
call   1080 <printf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    -0x60(%rbp),%rax
add    $0xb,%rax
mov    %rax,-0x60(%rbp)
movl   $0x0,-0x68(%rbp)
mov    -0x60(%rbp),%rax
movslq -0x68(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x58,%eax
jne    1517 <main+0x2b7>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    14f4 <main+0x294>
lea    -0x1c(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
lea    -0x1c(%rbp),%rdi
lea    0xb50(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x1c(%rbp),%rax
mov    %rax,-0x498(%rbp)
mov    $0x0,%al
call   10b0 <crypt_make_salt@plt>
mov    -0x498(%rbp),%rdi
mov    %eax,%esi
call   1160 <strcat@plt>
lea    -0x1c(%rbp),%rax
mov    %rax,-0x490(%rbp)
mov    $0x0,%al
call   10b0 <crypt_make_salt@plt>
mov    -0x490(%rbp),%rdi
mov    %eax,%esi
call   1160 <strcat@plt>
lea    -0x1c(%rbp),%rax
mov    %rax,-0x488(%rbp)
mov    $0x0,%al
call   10b0 <crypt_make_salt@plt>
mov    -0x488(%rbp),%rdi
mov    %eax,%esi
call   1160 <strcat@plt>
lea    -0x1c(%rbp),%rax
mov    %rax,-0x480(%rbp)
mov    $0x0,%al
call   10b0 <crypt_make_salt@plt>
mov    -0x480(%rbp),%rdi
mov    %eax,%esi
call   1160 <strcat@plt>
lea    0xac8(%rip),%rdi
call   1110 <askpass@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    15f0 <main+0x390>
mov    0x29e8(%rip),%rax
mov    (%rax),%edi
lea    0xaba(%rip),%rsi
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1180 <strdup@plt>
mov    %rax,-0x28(%rbp)
lea    0xaaa(%rip),%rdi
call   1110 <askpass@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1636 <main+0x3d6>
mov    0x29a2(%rip),%rax
mov    (%rax),%edi
lea    0xa74(%rip),%rsi
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    -0x30(%rbp),%rdi
call   1180 <strdup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
je     1679 <main+0x419>
mov    0x295f(%rip),%rax
mov    (%rax),%edi
lea    0xa5f(%rip),%rsi
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    -0x28(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1030 <pw_encrypt@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
cmp    -0x68(%rbp),%eax
jle    16b2 <main+0x452>
lea    0xa3f(%rip),%rdi
call   1080 <printf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%edx
mov    $0x20,%esi
call   10a0 <memset@plt>
mov    -0x60(%rbp),%rax
mov    %rax,-0x4a8(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x4a0(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x4a8(%rbp),%rdi
mov    -0x4a0(%rbp),%rsi
mov    %eax,%edx
call   1100 <memcpy@plt>
lea    0xa09(%rip),%rdi
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x4b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0xd83(%rip),%rdx
call   1140 <getopt@plt>
cmp    $0xff,%al
je     12dc <main+0x7c>
xor    %r14d,%r14d
mov    0x2d68(%rip),%r13
lea    0xd69(%rip),%r12
xor    %r15d,%r15d
jmp    12bd <main+0x5d>
nopl   0x0(%rax)
mov    0x0(%r13),%rdi
call   1180 <strdup@plt>
mov    %rax,%r15
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1140 <getopt@plt>
cmp    $0xff,%al
je     12e2 <main+0x82>
movsbl %al,%eax
cmp    $0x69,%eax
je     12a0 <main+0x40>
cmp    $0x6f,%eax
jne    1515 <main+0x2b5>
mov    0x0(%r13),%rdi
call   1180 <strdup@plt>
mov    %rax,%r14
jmp    12ac <main+0x4c>
xor    %r15d,%r15d
xor    %r14d,%r14d
mov    %r14,%rax
or     %r15,%rax
je     154f <main+0x2ef>
test   %r15,%r15
je     1561 <main+0x301>
test   %r14,%r14
je     1342 <main+0xe2>
cmp    %r15,%r14
je     1342 <main+0xe2>
lea    0xd2d(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1090 <snprintf@plt>
mov    %rbx,%rdi
call   1080 <system@plt>
test   %rax,%rax
je     1345 <main+0xe5>
mov    0x2c8c(%rip),%rax
mov    (%rax),%edi
lea    0xd01(%rip),%rsi
jmp    15a2 <main+0x342>
mov    %r15,%r14
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   10f0 <stat@plt>
mov    0x2c77(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1120 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1508 <main+0x2a8>
mov    0x8(%rsp),%ebx
mov    0x2c78(%rip),%rax
mov    0x2c39(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2c56(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebx,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    0x2c0e(%rip),%rcx
cmp    (%rcx),%rax
je     1573 <main+0x313>
lea    0xca1(%rip),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   10c0 <findstr@plt>
test   %rax,%rax
je     1589 <main+0x329>
mov    %rax,%r14
add    $0xb,%r14
mov    $0xffffffff,%ebp
mov    %r14,%rax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebp
cmpb   $0x58,(%rax)
lea    0x1(%rax),%rax
je     13e0 <main+0x180>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
lea    0xc58(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
xor    %eax,%eax
call   10b0 <crypt_make_salt@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1160 <strcat@plt>
xor    %eax,%eax
call   10b0 <crypt_make_salt@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1160 <strcat@plt>
xor    %eax,%eax
call   10b0 <crypt_make_salt@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1160 <strcat@plt>
xor    %eax,%eax
call   10b0 <crypt_make_salt@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1160 <strcat@plt>
lea    0xc09(%rip),%rdi
call   1110 <askpass@plt>
test   %rax,%rax
je     153d <main+0x2dd>
mov    %rax,%rdi
call   1180 <strdup@plt>
mov    %rax,%rbx
lea    0xc11(%rip),%rdi
call   1110 <askpass@plt>
test   %rax,%rax
je     153d <main+0x2dd>
mov    %rax,%rdi
call   1180 <strdup@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
jne    1592 <main+0x332>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <pw_encrypt@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <strlen@plt>
cmp    %ebp,%eax
jg     15b1 <main+0x351>
mov    %r14,%rdi
mov    $0x20,%esi
mov    %ebp,%edx
call   10a0 <memset@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1100 <memcpy@plt>
lea    0xbd0(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1130 <perror@plt>
jmp    136d <main+0x10d>
cmp    $0x68,%eax
jne    152a <main+0x2ca>
mov    0x0(%rbp),%rdi
call   1150 <print_help@plt>
xor    %edi,%edi
call   1170 <exit@plt>
mov    0x0(%rbp),%rdi
call   1150 <print_help@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    0x2a7c(%rip),%rax
mov    (%rax),%edi
lea    0xb2b(%rip),%rsi
jmp    15a2 <main+0x342>
mov    0x2a6a(%rip),%rax
mov    (%rax),%edi
lea    0xaa7(%rip),%rsi
jmp    15a2 <main+0x342>
mov    0x2a58(%rip),%rax
mov    (%rax),%edi
lea    0xaaa(%rip),%rsi
jmp    15a2 <main+0x342>
lea    0xad2(%rip),%rdi
call   1130 <perror@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
lea    0xb58(%rip),%rdi
jmp    15b8 <main+0x358>
mov    0x2a27(%rip),%rax
mov    (%rax),%edi
lea    0xb04(%rip),%rsi
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
lea    0xb0c(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   1170 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [6 x i8] c"hi:o:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.1 = [21 x i8] c"No files specified!\0A\00"
@.str.2 = [26 x i8] c"No input file specified!\0A\00"
@.str.3 = [9 x i8] c"cp %s %s\00"
@.str.4 = [14 x i8] c"Copy failed!\0A\00"
@O_RDWR = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.5 = [7 x i8] c"mmap()\00"
@.str.6 = [12 x i8] c"mvpmc_root=\00"
@.str.7 = [35 x i8] c"Password not found in input file!\0A\00"
@.str.8 = [4 x i8] c"$1$\00"
@.str.9 = [21 x i8] c"Type root password: \00"
@.str.10 = [19 x i8] c"Invalid password!\0A\00"
@.str.11 = [27 x i8] c"Type root password again: \00"
@.str.12 = [25 x i8] c"Passwords do not match!\0A\00"
@.str.13 = [37 x i8] c"Not enough space to store password!\0A\00"
@.str.14 = [6 x i8] c"Done\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [12 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca %struct.stat
%18 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %11
store i8* null, i8** %12
br label %19
19: ; preds = %46, %2
%20 = load i32, i32* %4
%21 = load i8**, i8*** %5
%22 = call signext i8 @getopt(i32 %20, i8** %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8 %22, i8* %10
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, -1
br i1 %24, label %25, label %47
25: ; preds = %19
%26 = load i8, i8* %10
%27 = sext i8 %26 to i32
switch i32 %27, label %40 [
i32 104, label %28
i32 105, label %34
i32 111, label %37
]
28: ; preds = %25
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 @print_help(i8* %31)
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %25
%35 = load i8*, i8** @optarg
%36 = call i8* @strdup(i8* %35)
store i8* %36, i8** %11
br label %46
37: ; preds = %25
%38 = load i8*, i8** @optarg
%39 = call i8* @strdup(i8* %38)
store i8* %39, i8** %12
br label %46
40: ; preds = %25
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 0
%43 = load i8*, i8** %42
%44 = call i32 @print_help(i8* %43)
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %37, %34
br label %19
47: ; preds = %19
%48 = load i8*, i8** %12
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %57
50: ; preds = %47
%51 = load i8*, i8** %11
%52 = icmp eq i8* %51, null
br i1 %52, label %53, label %57
53: ; preds = %50
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %50, %47
%58 = load i8*, i8** %11
%59 = icmp eq i8* %58, null
br i1 %59, label %60, label %64
60: ; preds = %57
%61 = load i32, i32* @stderr
%62 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %57
%65 = load i8*, i8** %12
%66 = icmp ne i8* %65, null
br i1 %66, label %67, label %85
67: ; preds = %64
%68 = load i8*, i8** %12
%69 = load i8*, i8** %11
%70 = icmp ne i8* %68, %69
br i1 %70, label %71, label %85
71: ; preds = %67
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%73 = load i8*, i8** %11
%74 = load i8*, i8** %12
%75 = call i32 @snprintf(i8* %72, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %73, i8* %74)
%76 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%77 = call i64 @system(i8* %76)
%78 = icmp ne i64 %77, 0
br i1 %78, label %79, label %83
79: ; preds = %71
%80 = load i32, i32* @stderr
%81 = call i32 @fprintf(i32 %80, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %71
%84 = load i8*, i8** %12
store i8* %84, i8** %11
br label %85
85: ; preds = %83, %67, %64
%86 = load i8*, i8** %11
%87 = call i32 @stat(i8* %86, %struct.stat* %17)
%88 = load i8*, i8** %11
%89 = load i32, i32* @O_RDWR
%90 = call i32 @open(i8* %88, i32 %89)
store i32 %90, i32* %15
%91 = icmp slt i32 %90, 0
br i1 %91, label %92, label %95
92: ; preds = %85
%93 = load i8*, i8** %11
%94 = call i32 @perror(i8* %93)
br label %95
95: ; preds = %92, %85
%96 = getelementptr inbounds %struct.stat, %struct.stat* %17, i32 0, i32 0
%97 = load i32, i32* %96
%98 = load i32, i32* @PROT_READ
%99 = load i32, i32* @PROT_WRITE
%100 = or i32 %98, %99
%101 = load i32, i32* @MAP_SHARED
%102 = load i32, i32* %15
%103 = call i8* @mmap(i32* null, i32 %97, i32 %100, i32 %101, i32 %102, i32 0)
store i8* %103, i8** %13
%104 = load i8*, i8** @MAP_FAILED
%105 = icmp eq i8* %103, %104
br i1 %105, label %106, label %109
106: ; preds = %95
%107 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%108 = call i32 @exit(i32 1)
unreachable
109: ; preds = %95
%110 = load i8*, i8** %13
%111 = getelementptr inbounds %struct.stat, %struct.stat* %17, i32 0, i32 0
%112 = load i32, i32* %111
%113 = call i8* @findstr(i8* %110, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %112)
store i8* %113, i8** %14
%114 = icmp eq i8* %113, null
br i1 %114, label %115, label %118
115: ; preds = %109
%116 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0))
%117 = call i32 @exit(i32 1)
unreachable
118: ; preds = %109
%119 = load i8*, i8** %14
%120 = getelementptr inbounds i8, i8* %119, i64 11
store i8* %120, i8** %14
store i32 0, i32* %16
br label %121
121: ; preds = %129, %118
%122 = load i8*, i8** %14
%123 = load i32, i32* %16
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds i8, i8* %122, i64 %124
%126 = load i8, i8* %125
%127 = sext i8 %126 to i32
%128 = icmp eq i32 %127, 88
br i1 %128, label %129, label %132
129: ; preds = %121
%130 = load i32, i32* %16
%131 = add nsw i32 %130, 1
store i32 %131, i32* %16
br label %121
132: ; preds = %121
%133 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%134 = call i32 @memset(i8* %133, i8 signext 0, i32 12)
%135 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%136 = call i32 @strcpy(i8* %135, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%137 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%138 = call i32 (...) @crypt_make_salt()
%139 = call i32 @strcat(i8* %137, i32 %138)
%140 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%141 = call i32 (...) @crypt_make_salt()
%142 = call i32 @strcat(i8* %140, i32 %141)
%143 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%144 = call i32 (...) @crypt_make_salt()
%145 = call i32 @strcat(i8* %143, i32 %144)
%146 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%147 = call i32 (...) @crypt_make_salt()
%148 = call i32 @strcat(i8* %146, i32 %147)
%149 = call i8* @askpass(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
store i8* %149, i8** %7
%150 = icmp eq i8* %149, null
br i1 %150, label %151, label %155
151: ; preds = %132
%152 = load i32, i32* @stderr
%153 = call i32 @fprintf(i32 %152, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
%154 = call i32 @exit(i32 1)
unreachable
155: ; preds = %132
%156 = load i8*, i8** %7
%157 = call i8* @strdup(i8* %156)
store i8* %157, i8** %7
%158 = call i8* @askpass(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
store i8* %158, i8** %8
%159 = icmp eq i8* %158, null
br i1 %159, label %160, label %164
160: ; preds = %155
%161 = load i32, i32* @stderr
%162 = call i32 @fprintf(i32 %161, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
%163 = call i32 @exit(i32 1)
unreachable
164: ; preds = %155
%165 = load i8*, i8** %8
%166 = call i8* @strdup(i8* %165)
store i8* %166, i8** %8
%167 = load i8*, i8** %7
%168 = load i8*, i8** %8
%169 = call i64 @strcmp(i8* %167, i8* %168)
%170 = icmp ne i64 %169, 0
br i1 %170, label %171, label %175
171: ; preds = %164
%172 = load i32, i32* @stderr
%173 = call i32 @fprintf(i32 %172, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0))
%174 = call i32 @exit(i32 1)
unreachable
175: ; preds = %164
%176 = load i8*, i8** %7
%177 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%178 = call i8* @pw_encrypt(i8* %176, i8* %177)
store i8* %178, i8** %9
%179 = load i8*, i8** %9
%180 = call i32 @strlen(i8* %179)
%181 = load i32, i32* %16
%182 = icmp sgt i32 %180, %181
br i1 %182, label %183, label %186
183: ; preds = %175
%184 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.13, i64 0, i64 0))
%185 = call i32 @exit(i32 1)
unreachable
186: ; preds = %175
%187 = load i8*, i8** %14
%188 = load i32, i32* %16
%189 = call i32 @memset(i8* %187, i8 signext 32, i32 %188)
%190 = load i8*, i8** %14
%191 = load i8*, i8** %9
%192 = load i8*, i8** %9
%193 = call i32 @strlen(i8* %192)
%194 = call i32 @memcpy(i8* %190, i8* %191, i32 %193)
%195 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.14, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [6 x i8] c"hi:o:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.1 = [21 x i8] c"No files specified!\0A\00"
@.str.2 = [26 x i8] c"No input file specified!\0A\00"
@.str.3 = [9 x i8] c"cp %s %s\00"
@.str.4 = [14 x i8] c"Copy failed!\0A\00"
@O_RDWR = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.5 = [7 x i8] c"mmap()\00"
@.str.6 = [12 x i8] c"mvpmc_root=\00"
@.str.8 = [4 x i8] c"$1$\00"
@.str.9 = [21 x i8] c"Type root password: \00"
@.str.10 = [19 x i8] c"Invalid password!\0A\00"
@.str.11 = [27 x i8] c"Type root password again: \00"
@.str.12 = [25 x i8] c"Passwords do not match!\0A\00"
@str = [5 x i8] c"Done\00"
@str.15 = [36 x i8] c"Not enough space to store password!\00"
@str.16 = [34 x i8] c"Password not found in input file!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [12 x i8]
%4 = alloca %struct.stat
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%7 = bitcast %struct.stat* %4 to i8*
%8 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8 %8, -1
br i1 %9, label %34, label %10
10: ; preds = %2, %29
%11 = phi i8 [ %32, %29 ], [ %8, %2 ]
%12 = phi i8* [ %31, %29 ], [ null, %2 ]
%13 = phi i8* [ %30, %29 ], [ null, %2 ]
%14 = sext i8 %11 to i32
switch i32 %14, label %25 [
i32 104, label %15
i32 105, label %19
i32 111, label %22
]
15: ; preds = %10
%16 = load i8*, i8** %1
%17 = tail call i32 @print_help(i8* %16)
%18 = tail call i32 @exit(i32 0)
unreachable
19: ; preds = %10
%20 = load i8*, i8** @optarg
%21 = tail call i8* @strdup(i8* %20)
br label %29
22: ; preds = %10
%23 = load i8*, i8** @optarg
%24 = tail call i8* @strdup(i8* %23)
br label %29
25: ; preds = %10
%26 = load i8*, i8** %1
%27 = tail call i32 @print_help(i8* %26)
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %22, %19
%30 = phi i8* [ %13, %22 ], [ %21, %19 ]
%31 = phi i8* [ %24, %22 ], [ %12, %19 ]
%32 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%33 = icmp eq i8 %32, -1
br i1 %33, label %34, label %10
34: ; preds = %29, %2
%35 = phi i8* [ null, %2 ], [ %30, %29 ]
%36 = phi i8* [ null, %2 ], [ %31, %29 ]
%37 = icmp eq i8* %36, null
%38 = icmp eq i8* %35, null
%39 = select i1 %37, i1 %38, i1 false
br i1 %39, label %40, label %44
40: ; preds = %34
%41 = load i32, i32* @stderr
%42 = tail call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%43 = tail call i32 @exit(i32 1)
unreachable
44: ; preds = %34
br i1 %38, label %45, label %49
45: ; preds = %44
%46 = load i32, i32* @stderr
%47 = tail call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%48 = tail call i32 @exit(i32 1)
unreachable
49: ; preds = %44
%50 = icmp eq i8* %36, %35
%51 = select i1 %37, i1 true, i1 %50
br i1 %51, label %62, label %52
52: ; preds = %49
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%54 = call i32 @snprintf(i8* %53, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %35, i8* %36)
%55 = call i64 @system(i8* %53)
%56 = icmp eq i64 %55, 0
br i1 %56, label %61, label %57
57: ; preds = %52
%58 = load i32, i32* @stderr
%59 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %52
br label %62
62: ; preds = %61, %49
%63 = phi i8* [ %36, %61 ], [ %35, %49 ]
%64 = call i32 @stat(i8* %63, %struct.stat* %4)
%65 = load i32, i32* @O_RDWR
%66 = call i32 @open(i8* %63, i32 %65)
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %62
%69 = call i32 @perror(i8* %63)
br label %70
70: ; preds = %68, %62
%71 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%72 = load i32, i32* %71
%73 = load i32, i32* @PROT_READ
%74 = load i32, i32* @PROT_WRITE
%75 = or i32 %74, %73
%76 = load i32, i32* @MAP_SHARED
%77 = call i8* @mmap(i32* null, i32 %72, i32 %75, i32 %76, i32 %66, i32 0)
%78 = load i8*, i8** @MAP_FAILED
%79 = icmp eq i8* %77, %78
br i1 %79, label %80, label %83
80: ; preds = %70
%81 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %70
%84 = call i8* @findstr(i8* %77, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %72)
%85 = icmp eq i8* %84, null
br i1 %85, label %86, label %89
86: ; preds = %83
%87 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.16, i64 0, i64 0))
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %83
%90 = getelementptr inbounds i8, i8* %84, i64 11
br label %91
91: ; preds = %91, %89
%92 = phi i64 [ %96, %91 ], [ 0, %89 ]
%93 = getelementptr inbounds i8, i8* %90, i64 %92
%94 = load i8, i8* %93
%95 = icmp eq i8 %94, 88
%96 = add nuw i64 %92, 1
br i1 %95, label %91, label %97
97: ; preds = %91
%98 = trunc i64 %92 to i32
%99 = call i32 @memset(i8* %6, i8 signext 0, i32 12)
%100 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%101 = call i32 (...) @crypt_make_salt()
%102 = call i32 @strcat(i8* %6, i32 %101)
%103 = call i32 (...) @crypt_make_salt()
%104 = call i32 @strcat(i8* %6, i32 %103)
%105 = call i32 (...) @crypt_make_salt()
%106 = call i32 @strcat(i8* %6, i32 %105)
%107 = call i32 (...) @crypt_make_salt()
%108 = call i32 @strcat(i8* %6, i32 %107)
%109 = call i8* @askpass(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%110 = icmp eq i8* %109, null
br i1 %110, label %111, label %115
111: ; preds = %97
%112 = load i32, i32* @stderr
%113 = call i32 @fprintf(i32 %112, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
%114 = call i32 @exit(i32 1)
unreachable
115: ; preds = %97
%116 = call i8* @strdup(i8* %109)
%117 = call i8* @askpass(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
%118 = icmp eq i8* %117, null
br i1 %118, label %119, label %123
119: ; preds = %115
%120 = load i32, i32* @stderr
%121 = call i32 @fprintf(i32 %120, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
%122 = call i32 @exit(i32 1)
unreachable
123: ; preds = %115
%124 = call i8* @strdup(i8* %117)
%125 = call i64 @strcmp(i8* %116, i8* %124)
%126 = icmp eq i64 %125, 0
br i1 %126, label %131, label %127
127: ; preds = %123
%128 = load i32, i32* @stderr
%129 = call i32 @fprintf(i32 %128, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0))
%130 = call i32 @exit(i32 1)
unreachable
131: ; preds = %123
%132 = call i8* @pw_encrypt(i8* %116, i8* %6)
%133 = call i32 @strlen(i8* %132)
%134 = icmp sgt i32 %133, %98
br i1 %134, label %135, label %138
135: ; preds = %131
%136 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.15, i64 0, i64 0))
%137 = call i32 @exit(i32 1)
unreachable
138: ; preds = %131
%139 = call i32 @memset(i8* %90, i8 signext 32, i32 %98)
%140 = call i32 @strlen(i8* %132)
%141 = call i32 @memcpy(i8* %90, i8* %132, i32 %140)
%142 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
ret i32 0
}