#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 */

/* Variables and functions */
char *crypt_md5(char const *, char const *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ salt_invalid(char *);
int strlen(char *);
int main(int argc, char **argv) {
  char *cryptpw;
  char *passwd;
  char *salt;
  if (argc < 3) {
    printf("\nUsage: md5_pw password salt\n\n");
    return (0);
  }
  passwd = argv[1];
  salt = argv[2];
  if (salt_invalid(salt)) {
    printf("\nsalt [%s] contains characters that are not allowed - only "
           "[A-Za-z0-9./] are allowed\n",
           salt);
    exit(0);
  }
  if (strlen(salt) > 8)
    printf("\nOnly first 8 characters of the salt were used\n");
  cryptpw = crypt_md5((const char *)passwd, (const char *)salt);
  printf("\nmd5 crypt password: %s\n\n", cryptpw);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    118a <main+0x3a>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1218 <main+0xc8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <salt_invalid@plt>
cmp    $0x0,%rax
je     11ce <main+0x7e>
mov    -0x28(%rbp),%rsi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x8,%eax
jle    11ee <main+0x9e>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <crypt_md5@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     1177 <main+0x17>
lea    0xf2f(%rip),%rdi
call   1030 <puts@plt>
jmp    11c1 <main+0x61>
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rbx
mov    %rbx,%rdi
call   1070 <salt_invalid@plt>
test   %rax,%rax
jne    11cb <main+0x6b>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x9,%eax
jl     11a5 <main+0x45>
lea    0xed0(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <crypt_md5@plt>
lea    0xe9f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe2e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"\0AUsage: md5_pw password salt\0A\0A\00"
@.str.1 = [86 x i8] c"\0Asalt [%s] contains characters that are not allowed - only [A-Za-z0-9./] are allowed\0A\00"
@.str.2 = [48 x i8] c"\0AOnly first 8 characters of the salt were used\0A\00"
@.str.3 = [26 x i8] c"\0Amd5 crypt password: %s\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %39
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %7
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
store i8* %19, i8** %8
%20 = load i8*, i8** %8
%21 = call i64 @salt_invalid(i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %13
%24 = load i8*, i8** %8
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %13
%28 = load i8*, i8** %8
%29 = call i32 @strlen(i8* %28)
%30 = icmp sgt i32 %29, 8
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
%34 = load i8*, i8** %7
%35 = load i8*, i8** %8
%36 = call i8* @crypt_md5(i8* %34, i8* %35)
store i8* %36, i8** %6
%37 = load i8*, i8** %6
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %37)
store i32 0, i32* %3
br label %39
39: ; preds = %33, %11
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str.1 = [86 x i8] c"\0Asalt [%s] contains characters that are not allowed - only [A-Za-z0-9./] are allowed\0A\00"
@.str.3 = [26 x i8] c"\0Amd5 crypt password: %s\0A\0A\00"
@str = [47 x i8] c"\0AOnly first 8 characters of the salt were used\00"
@str.4 = [30 x i8] c"\0AUsage: md5_pw password salt\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.4, i64 0, i64 0))
br label %24
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i64 @salt_invalid(i8* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %6
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([86 x i8], [86 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %6
%17 = tail call i32 @strlen(i8* %10)
%18 = icmp sgt i32 %17, 8
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
%22 = tail call i8* @crypt_md5(i8* %8, i8* %10)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %4
ret i32 0
}