#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*/ OpenSSL_add_all_algorithms();
int /*<<< orphan*/ decrypt(char *, char *, char *);
int /*<<< orphan*/ encrypt(char *, char *, char *);
int /*<<< orphan*/ genkey(int, char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  if (argv[1] == NULL || argv[2] == NULL || argv[3] == NULL ||
      argv[4] == NULL) {
    printf("Upss, something is wrong, check your parameters!\n");
    printf("Correct format for key generation: genkey 2048 private.pem "
           "public.pem\n");
    printf(
        "Correct format for encryption: encrypt public.pem input encrypted\n");
    printf("Correct format for decryption: decrypt private.pem encrypted "
           "decrypted\n");
    return 1;
  }
  OpenSSL_add_all_algorithms();
  int mode;
  if (strcmp(argv[1], "genkey") == 0) {
    mode = 1;
  } else if (strcmp(argv[1], "encrypt") == 0) {
    mode = 2;
  } else if (strcmp(argv[1], "decrypt") == 0) {
    mode = 3;
  }
  char *inFile = argv[3];
  char *outFile = argv[4];
  if (mode == 1) {
    printf("Start generating private and public key pair ...\n");
    int keyLength = 0;
    sscanf(argv[2], "%d", &keyLength);
    genkey(keyLength, inFile, outFile);
    return 0;
  }
  char *keyFile = argv[2];
  if (mode == 2) {
    printf("Start encrypting ...\n");
    encrypt(keyFile, inFile, outFile);
    return 0;
  }
  if (mode == 3) {
    printf("Start decrypting ...\n");
    decrypt(keyFile, inFile, outFile);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     11c2 <main+0x52>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     11c2 <main+0x52>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x18(%rax)
je     11c2 <main+0x52>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x20(%rax)
jne    11fe <main+0x8e>
lea    0xe37(%rip),%rdi
call   1040 <printf@plt>
lea    0xe5d(%rip),%rdi
call   1040 <printf@plt>
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
lea    0xecf(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    136a <main+0x1fa>
mov    $0x0,%al
call   1070 <OpenSSL_add_all_algorithms@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xef0(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    122f <main+0xbf>
movl   $0x1,-0x14(%rbp)
jmp    1288 <main+0x118>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xecd(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1259 <main+0xe9>
movl   $0x2,-0x14(%rbp)
jmp    1283 <main+0x113>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xeab(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    127e <main+0x10e>
movl   $0x3,-0x14(%rbp)
jmp    1283 <main+0x113>
jmp    1288 <main+0x118>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    12f1 <main+0x181>
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe81(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1080 <sscanf@plt>
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1090 <genkey@plt>
movl   $0x0,-0x4(%rbp)
jmp    136a <main+0x1fa>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x2,-0x14(%rbp)
jne    1330 <main+0x1c0>
lea    0xe42(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <encrypt@plt>
movl   $0x0,-0x4(%rbp)
jmp    136a <main+0x1fa>
cmpl   $0x3,-0x14(%rbp)
jne    1363 <main+0x1f3>
lea    0xe25(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <decrypt@plt>
movl   $0x0,-0x4(%rbp)
jmp    136a <main+0x1fa>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmpq   $0x0,0x8(%rsi)
je     1214 <main+0xa4>
mov    %rsi,%rbx
cmpq   $0x0,0x10(%rsi)
je     1214 <main+0xa4>
cmpq   $0x0,0x18(%rbx)
je     1214 <main+0xa4>
cmpq   $0x0,0x20(%rbx)
je     1214 <main+0xa4>
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <OpenSSL_add_all_algorithms@plt>
mov    0x8(%rbx),%rdi
lea    0xe4e(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1256 <main+0xe6>
mov    0x8(%rbx),%rdi
lea    0xe3c(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1298 <main+0x128>
mov    0x8(%rbx),%rdi
lea    0xe2b(%rip),%rsi
call   1060 <strcmp@plt>
mov    0x10(%rbx),%rbp
mov    0x18(%rbx),%r14
mov    0x20(%rbx),%rbx
lea    0xe1e(%rip),%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <decrypt@plt>
jmp    12be <main+0x14e>
lea    0xe5a(%rip),%rdi
call   1040 <puts@plt>
lea    0xe7f(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb9(%rip),%rdi
call   1040 <puts@plt>
lea    0xeef(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x18(%rbx),%r14
mov    0x20(%rbx),%r15
lea    0xddf(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,0x4(%rsp)
mov    0x10(%rbx),%rdi
lea    0xd9a(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1080 <sscanf@plt>
mov    0x4(%rsp),%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1090 <genkey@plt>
jmp    1249 <main+0xd9>
mov    0x10(%rbx),%rbp
mov    0x18(%rbx),%r14
mov    0x20(%rbx),%rbx
lea    0xd84(%rip),%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <encrypt@plt>
xor    %ebp,%ebp
jmp    1249 <main+0xd9>

LLVM IR (-O0):
@.str = [50 x i8] c"Upss, something is wrong, check your parameters!\0A\00"
@.str.1 = [71 x i8] c"Correct format for key generation: genkey 2048 private.pem public.pem\0A\00"
@.str.2 = [67 x i8] c"Correct format for encryption: encrypt public.pem input encrypted\0A\00"
@.str.3 = [72 x i8] c"Correct format for decryption: decrypt private.pem encrypted decrypted\0A\00"
@.str.4 = [7 x i8] c"genkey\00"
@.str.5 = [8 x i8] c"encrypt\00"
@.str.6 = [8 x i8] c"decrypt\00"
@.str.7 = [50 x i8] c"Start generating private and public key pair ...\0A\00"
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [22 x i8] c"Start encrypting ...\0A\00"
@.str.10 = [22 x i8] c"Start decrypting ...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = icmp eq i8* %13, null
br i1 %14, label %30, label %15
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = icmp eq i8* %18, null
br i1 %19, label %30, label %20
20: ; preds = %15
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 3
%23 = load i8*, i8** %22
%24 = icmp eq i8* %23, null
br i1 %24, label %30, label %25
25: ; preds = %20
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 4
%28 = load i8*, i8** %27
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %35
30: ; preds = %25, %20, %15, %2
%31 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %100
35: ; preds = %25
%36 = call i32 (...) @OpenSSL_add_all_algorithms()
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %35
store i32 1, i32* %6
br label %59
43: ; preds = %35
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %43
store i32 2, i32* %6
br label %58
50: ; preds = %43
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = call i64 @strcmp(i8* %53, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %50
store i32 3, i32* %6
br label %57
57: ; preds = %56, %50
br label %58
58: ; preds = %57, %49
br label %59
59: ; preds = %58, %42
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 3
%62 = load i8*, i8** %61
store i8* %62, i8** %7
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 4
%65 = load i8*, i8** %64
store i8* %65, i8** %8
%66 = load i32, i32* %6
%67 = icmp eq i32 %66, 1
br i1 %67, label %68, label %78
68: ; preds = %59
%69 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %9
%70 = load i8**, i8*** %5
%71 = getelementptr inbounds i8*, i8** %70, i64 2
%72 = load i8*, i8** %71
%73 = call i32 @sscanf(i8* %72, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %9)
%74 = load i32, i32* %9
%75 = load i8*, i8** %7
%76 = load i8*, i8** %8
%77 = call i32 @genkey(i32 %74, i8* %75, i8* %76)
store i32 0, i32* %3
br label %100
78: ; preds = %59
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 2
%81 = load i8*, i8** %80
store i8* %81, i8** %10
%82 = load i32, i32* %6
%83 = icmp eq i32 %82, 2
br i1 %83, label %84, label %90
84: ; preds = %78
%85 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%86 = load i8*, i8** %10
%87 = load i8*, i8** %7
%88 = load i8*, i8** %8
%89 = call i32 @encrypt(i8* %86, i8* %87, i8* %88)
store i32 0, i32* %3
br label %100
90: ; preds = %78
%91 = load i32, i32* %6
%92 = icmp eq i32 %91, 3
br i1 %92, label %93, label %99
93: ; preds = %90
%94 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0))
%95 = load i8*, i8** %10
%96 = load i8*, i8** %7
%97 = load i8*, i8** %8
%98 = call i32 @decrypt(i8* %95, i8* %96, i8* %97)
store i32 0, i32* %3
br label %100
99: ; preds = %90
store i32 1, i32* %3
br label %100
100: ; preds = %99, %93, %84, %68, %30
%101 = load i32, i32* %3
ret i32 %101
}

LLVM IR (-O2):
@.str.4 = [7 x i8] c"genkey\00"
@.str.5 = [8 x i8] c"encrypt\00"
@.str.6 = [8 x i8] c"decrypt\00"
@.str.8 = [3 x i8] c"%d\00"
@str = [21 x i8] c"Start decrypting ...\00"
@str.11 = [21 x i8] c"Start encrypting ...\00"
@str.12 = [49 x i8] c"Start generating private and public key pair ...\00"
@str.13 = [49 x i8] c"Upss, something is wrong, check your parameters!\00"
@str.14 = [70 x i8] c"Correct format for key generation: genkey 2048 private.pem public.pem\00"
@str.15 = [66 x i8] c"Correct format for encryption: encrypt public.pem input encrypted\00"
@str.16 = [71 x i8] c"Correct format for decryption: decrypt private.pem encrypted decrypted\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = icmp eq i8* %5, null
br i1 %6, label %19, label %7
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = icmp eq i8* %9, null
br i1 %10, label %19, label %11
11: ; preds = %7
%12 = getelementptr inbounds i8*, i8** %1, i64 3
%13 = load i8*, i8** %12
%14 = icmp eq i8* %13, null
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = getelementptr inbounds i8*, i8** %1, i64 4
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %24
19: ; preds = %15, %11, %7, %2
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.13, i64 0, i64 0))
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str.14, i64 0, i64 0))
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @str.15, i64 0, i64 0))
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str.16, i64 0, i64 0))
br label %56
24: ; preds = %15
%25 = tail call i32 (...) @OpenSSL_add_all_algorithms()
%26 = load i8*, i8** %4
%27 = tail call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %24
%30 = load i8*, i8** %4
%31 = tail call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %42, label %48
33: ; preds = %24
%34 = load i8*, i8** %12
%35 = load i8*, i8** %16
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.12, i64 0, i64 0))
%37 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%38 = load i8*, i8** %8
%39 = call i32 @sscanf(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %3)
%40 = load i32, i32* %3
%41 = call i32 @genkey(i32 %40, i8* %34, i8* %35)
br label %56
42: ; preds = %29
%43 = load i8*, i8** %12
%44 = load i8*, i8** %16
%45 = load i8*, i8** %8
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.11, i64 0, i64 0))
%47 = tail call i32 @encrypt(i8* %45, i8* %43, i8* %44)
br label %56
48: ; preds = %29
%49 = load i8*, i8** %4
%50 = tail call i64 @strcmp(i8* %49, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%51 = load i8*, i8** %12
%52 = load i8*, i8** %16
%53 = load i8*, i8** %8
%54 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%55 = tail call i32 @decrypt(i8* %53, i8* %51, i8* %52)
br label %56
56: ; preds = %33, %48, %42, %19
%57 = phi i32 [ 1, %19 ], [ 0, %33 ], [ 0, %42 ], [ 0, %48 ]
ret i32 %57
}