#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 */
int /*<<< orphan*/ *PBEWithMD5AndDES_encrypt(unsigned char *, size_t,
                                             unsigned char *, size_t, char **);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
size_t strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, size_t);
int usage(char *);
int main(int argc, char *argv[]) {
  char *input = NULL;
  char *password = NULL;
  char *encrypt;
  size_t i;
  if (argc != 3) {
    return usage(argv[0]);
  }
  for (i = 1; i < 3; i++) {
    if (!strncmp(argv[i], "input=", strlen("input="))) {
      input = &(argv[i][strlen("input=")]);
    }
    if (!strncmp(argv[i], "password=", strlen("password="))) {
      password = &(argv[i][strlen("password=")]);
    }
  }
  if ((input == NULL) || (password == NULL)) {
    return usage(argv[0]);
  }
  printf("\n----ARGUMENTS-------------------\n\n");
  printf("input: %s\npassword: %s\n\n\n", input, password);
  if (PBEWithMD5AndDES_encrypt((unsigned char *)input, strlen(input),
                               (unsigned char *)password, strlen(password),
                               &encrypt) != NULL) {
    printf("\n----OUTPUT----------------------\n\n");
    printf("%s\n\n\n", encrypt);
  } else {
    printf("PBEWithMD5AndDES_encrypt() returns error.\n");
    return -1;
  }
  free(encrypt);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a4 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    1376 <main+0x216>
movq   $0x1,-0x30(%rbp)
cmpq   $0x3,-0x30(%rbp)
jae    1291 <main+0x131>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
lea    0xe32(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rdx
lea    0xe1f(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    1219 <main+0xb9>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
lea    0xdfa(%rip),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x48(%rbp)
lea    0xdd7(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rdx
lea    0xdc4(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    127b <main+0x11b>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x50(%rbp)
lea    0xd9f(%rip),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    1280 <main+0x120>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11ac <main+0x4c>
cmpq   $0x0,-0x18(%rbp)
je     12a7 <main+0x147>
cmpq   $0x0,-0x20(%rbp)
jne    12bb <main+0x15b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    1376 <main+0x216>
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    -0x28(%rbp),%r8
call   1080 <PBEWithMD5AndDES_encrypt@plt>
cmp    $0x0,%rax
je     134c <main+0x1ec>
lea    0xd21(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xd09(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1366 <main+0x206>
lea    0xd20(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1376 <main+0x216>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x3,%edi
jne    1289 <main+0x119>
mov    0x8(%r14),%rbp
lea    0xe6e(%rip),%r15
mov    $0x6,%edx
mov    %rbp,%rdi
mov    %r15,%rsi
call   1040 <strncmp@plt>
lea    0x6(%rbp),%r13
xor    %ebx,%ebx
test   %eax,%eax
cmovne %rbx,%r13
lea    0xe52(%rip),%r12
mov    $0x9,%edx
mov    %rbp,%rdi
mov    %r12,%rsi
call   1040 <strncmp@plt>
add    $0x9,%rbp
test   %eax,%eax
cmovne %rbx,%rbp
mov    0x10(%r14),%rbx
mov    $0x6,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strncmp@plt>
lea    0x6(%rbx),%r15
test   %eax,%eax
cmovne %r13,%r15
mov    $0x9,%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strncmp@plt>
add    $0x9,%rbx
test   %eax,%eax
cmovne %rbp,%rbx
test   %r15,%r15
je     1289 <main+0x119>
test   %rbx,%rbx
je     1289 <main+0x119>
lea    0xe13(%rip),%rdi
call   1050 <puts@plt>
lea    0xded(%rip),%rdi
xor    %r14d,%r14d
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %rsp,%r8
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1090 <PBEWithMD5AndDES_encrypt@plt>
test   %rax,%rax
je     129f <main+0x12f>
lea    0xe11(%rip),%rdi
call   1050 <puts@plt>
mov    (%rsp),%rsi
lea    0xdae(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
jmp    12b1 <main+0x141>
mov    (%r14),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <usage@plt>
lea    0xda8(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"input=\00"
@.str.1 = [10 x i8] c"password=\00"
@.str.2 = [36 x i8] c"\0A----ARGUMENTS-------------------\0A\0A\00"
@.str.3 = [26 x i8] c"input: %s\0Apassword: %s\0A\0A\0A\00"
@.str.4 = [36 x i8] c"\0A----OUTPUT----------------------\0A\0A\00"
@.str.5 = [6 x i8] c"%s\0A\0A\0A\00"
@.str.6 = [43 x i8] c"PBEWithMD5AndDES_encrypt() returns error.\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*
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i8* null, i8** %7
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @usage(i8* %15)
store i32 %16, i32* %3
br label %88
17: ; preds = %2
store i64 1, i64* %9
br label %18
18: ; preds = %52, %17
%19 = load i64, i64* %9
%20 = icmp ult i64 %19, 3
br i1 %20, label %21, label %55
21: ; preds = %18
%22 = load i8**, i8*** %5
%23 = load i64, i64* %9
%24 = getelementptr inbounds i8*, i8** %22, i64 %23
%25 = load i8*, i8** %24
%26 = call i64 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @strncmp(i8* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %36, label %29
29: ; preds = %21
%30 = load i8**, i8*** %5
%31 = load i64, i64* %9
%32 = getelementptr inbounds i8*, i8** %30, i64 %31
%33 = load i8*, i8** %32
%34 = call i64 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8* %35, i8** %6
br label %36
36: ; preds = %29, %21
%37 = load i8**, i8*** %5
%38 = load i64, i64* %9
%39 = getelementptr inbounds i8*, i8** %37, i64 %38
%40 = load i8*, i8** %39
%41 = call i64 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%42 = call i32 @strncmp(i8* %40, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %51, label %44
44: ; preds = %36
%45 = load i8**, i8*** %5
%46 = load i64, i64* %9
%47 = getelementptr inbounds i8*, i8** %45, i64 %46
%48 = load i8*, i8** %47
%49 = call i64 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%50 = getelementptr inbounds i8, i8* %48, i64 %49
store i8* %50, i8** %7
br label %51
51: ; preds = %44, %36
br label %52
52: ; preds = %51
%53 = load i64, i64* %9
%54 = add i64 %53, 1
store i64 %54, i64* %9
br label %18
55: ; preds = %18
%56 = load i8*, i8** %6
%57 = icmp eq i8* %56, null
br i1 %57, label %61, label %58
58: ; preds = %55
%59 = load i8*, i8** %7
%60 = icmp eq i8* %59, null
br i1 %60, label %61, label %66
61: ; preds = %58, %55
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 0
%64 = load i8*, i8** %63
%65 = call i32 @usage(i8* %64)
store i32 %65, i32* %3
br label %88
66: ; preds = %58
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%68 = load i8*, i8** %6
%69 = load i8*, i8** %7
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %68, i8* %69)
%71 = load i8*, i8** %6
%72 = load i8*, i8** %6
%73 = call i64 @strlen(i8* %72)
%74 = load i8*, i8** %7
%75 = load i8*, i8** %7
%76 = call i64 @strlen(i8* %75)
%77 = call i32* @PBEWithMD5AndDES_encrypt(i8* %71, i64 %73, i8* %74, i64 %76, i8** %8)
%78 = icmp ne i32* %77, null
br i1 %78, label %79, label %83
79: ; preds = %66
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%81 = load i8*, i8** %8
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %81)
br label %85
83: ; preds = %66
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %3
br label %88
85: ; preds = %79
%86 = load i8*, i8** %8
%87 = call i32 @free(i8* %86)
store i32 0, i32* %3
br label %88
88: ; preds = %85, %83, %61, %12
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
@.str = [7 x i8] c"input=\00"
@.str.1 = [10 x i8] c"password=\00"
@.str.3 = [26 x i8] c"input: %s\0Apassword: %s\0A\0A\0A\00"
@.str.5 = [6 x i8] c"%s\0A\0A\0A\00"
@str = [35 x i8] c"\0A----ARGUMENTS-------------------\0A\00"
@str.7 = [42 x i8] c"PBEWithMD5AndDES_encrypt() returns error.\00"
@str.8 = [35 x i8] c"\0A----OUTPUT----------------------\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %6, label %30
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strncmp(i8* dereferenceable(1) %8, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 6)
%10 = icmp eq i32 %9, 0
%11 = getelementptr inbounds i8, i8* %8, i64 6
%12 = select i1 %10, i8* %11, i8* null
%13 = tail call i32 @strncmp(i8* dereferenceable(1) %8, i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 9)
%14 = icmp eq i32 %13, 0
%15 = getelementptr inbounds i8, i8* %8, i64 9
%16 = select i1 %14, i8* %15, i8* null
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @strncmp(i8* dereferenceable(1) %18, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 6)
%20 = icmp eq i32 %19, 0
%21 = getelementptr inbounds i8, i8* %18, i64 6
%22 = select i1 %20, i8* %21, i8* %12
%23 = tail call i32 @strncmp(i8* dereferenceable(1) %18, i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 9)
%24 = icmp eq i32 %23, 0
%25 = getelementptr inbounds i8, i8* %18, i64 9
%26 = select i1 %24, i8* %25, i8* %16
%27 = icmp eq i8* %22, null
%28 = icmp eq i8* %26, null
%29 = select i1 %27, i1 true, i1 %28
br i1 %29, label %33, label %36
30: ; preds = %2
%31 = load i8*, i8** %1
%32 = tail call i32 @usage(i8* %31)
br label %51
33: ; preds = %6
%34 = load i8*, i8** %1
%35 = tail call i32 @usage(i8* %34)
br label %51
36: ; preds = %6
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %22, i8* %26)
%39 = tail call i64 @strlen(i8* dereferenceable(1) %22)
%40 = tail call i64 @strlen(i8* dereferenceable(1) %26)
%41 = call i32* @PBEWithMD5AndDES_encrypt(i8* %22, i64 %39, i8* %26, i64 %40, i8** %3)
%42 = icmp eq i32* %41, null
br i1 %42, label %49, label %43
43: ; preds = %36
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.8, i64 0, i64 0))
%45 = load i8*, i8** %3
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %45)
%47 = load i8*, i8** %3
%48 = call i32 @free(i8* %47)
br label %51
49: ; preds = %36
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.7, i64 0, i64 0))
br label %51
51: ; preds = %43, %49, %33, %30
%52 = phi i32 [ %32, %30 ], [ %35, %33 ], [ 0, %43 ], [ -1, %49 ]
ret i32 %52
}