#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 */
typedef int /*<<< orphan*/ SSL;
typedef int /*<<< orphan*/ RSA;

/* Variables and functions */
int /*<<< orphan*/ RSA_F4;
int /*<<< orphan*/ *RSA_generate_key(int, int /*<<< orphan*/,
                                     int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
RSA *tmp_rsa_callback(SSL *ssl, int is_export, int keylen) {
  static RSA *rsa512 = NULL;
  static RSA *rsa1024 = NULL;
  switch (keylen) {
  case 512:
    if (!rsa512)
      rsa512 = RSA_generate_key(keylen, RSA_F4, NULL, NULL);
    return rsa512;
    break;
  case 1024:
    if (!rsa1024)
      rsa1024 = RSA_generate_key(keylen, RSA_F4, NULL, NULL);
    return rsa1024;
    break;
  default:
    if (rsa1024)
      return rsa1024;
    if (rsa512)
      return rsa512;
    rsa512 = RSA_generate_key(keylen, RSA_F4, NULL, NULL);
    return rsa512;
  }
}


x86 assembly (clang, -O0):
<tmp_rsa_callback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x200,%eax
je     114b <tmp_rsa_callback+0x3b>
jmp    1138 <tmp_rsa_callback+0x28>
mov    -0x1c(%rbp),%eax
sub    $0x400,%eax
je     1188 <tmp_rsa_callback+0x78>
jmp    11c5 <tmp_rsa_callback+0xb5>
cmpq   $0x0,0x2edd(%rip)
jne    1178 <tmp_rsa_callback+0x68>
mov    -0x18(%rbp),%edi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1030 <RSA_generate_key@plt>
mov    %rax,0x2eb8(%rip)
mov    0x2eb1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    122b <tmp_rsa_callback+0x11b>
cmpq   $0x0,0x2ea8(%rip)
jne    11b5 <tmp_rsa_callback+0xa5>
mov    -0x18(%rbp),%edi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1030 <RSA_generate_key@plt>
mov    %rax,0x2e83(%rip)
mov    0x2e7c(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    122b <tmp_rsa_callback+0x11b>
cmpq   $0x0,0x2e6b(%rip)
je     11e3 <tmp_rsa_callback+0xd3>
mov    0x2e5e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    122b <tmp_rsa_callback+0x11b>
cmpq   $0x0,0x2e45(%rip)
je     1201 <tmp_rsa_callback+0xf1>
mov    0x2e38(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    122b <tmp_rsa_callback+0x11b>
mov    -0x18(%rbp),%edi
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1030 <RSA_generate_key@plt>
mov    %rax,0x2e10(%rip)
mov    0x2e09(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tmp_rsa_callback>:
push   %rax
cmp    $0x400,%edx
je     112f <tmp_rsa_callback+0x1f>
cmp    $0x200,%edx
jne    115b <tmp_rsa_callback+0x4b>
mov    0x2f08(%rip),%rax
test   %rax,%rax
je     1180 <tmp_rsa_callback+0x70>
pop    %rcx
ret
mov    0x2f02(%rip),%rax
test   %rax,%rax
jne    112d <tmp_rsa_callback+0x1d>
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
mov    $0x400,%edi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <RSA_generate_key@plt>
mov    %rax,0x2edf(%rip)
pop    %rcx
ret
mov    0x2ed6(%rip),%rax
test   %rax,%rax
jne    112d <tmp_rsa_callback+0x1d>
mov    0x2ec2(%rip),%rax
test   %rax,%rax
jne    112d <tmp_rsa_callback+0x1d>
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
mov    %edx,%edi
jmp    118e <tmp_rsa_callback+0x7e>
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    $0x200,%edi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <RSA_generate_key@plt>
mov    %rax,0x2e92(%rip)
pop    %rcx
ret

LLVM IR (-O0):
@tmp_rsa_callback.rsa512 = internal global i32* null
@tmp_rsa_callback.rsa1024 = internal global i32* null
@RSA_F4 = global i32 0
define i32* @tmp_rsa_callback(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
switch i32 %8, label %27 [
i32 512, label %9
i32 1024, label %18
]
9: ; preds = %3
%10 = load i32*, i32** @tmp_rsa_callback.rsa512
%11 = icmp ne i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = load i32, i32* %7
%14 = load i32, i32* @RSA_F4
%15 = call i32* @RSA_generate_key(i32 %13, i32 %14, i32* null, i32* null)
store i32* %15, i32** @tmp_rsa_callback.rsa512
br label %16
16: ; preds = %12, %9
%17 = load i32*, i32** @tmp_rsa_callback.rsa512
store i32* %17, i32** %4
br label %42
18: ; preds = %3
%19 = load i32*, i32** @tmp_rsa_callback.rsa1024
%20 = icmp ne i32* %19, null
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = load i32, i32* %7
%23 = load i32, i32* @RSA_F4
%24 = call i32* @RSA_generate_key(i32 %22, i32 %23, i32* null, i32* null)
store i32* %24, i32** @tmp_rsa_callback.rsa1024
br label %25
25: ; preds = %21, %18
%26 = load i32*, i32** @tmp_rsa_callback.rsa1024
store i32* %26, i32** %4
br label %42
27: ; preds = %3
%28 = load i32*, i32** @tmp_rsa_callback.rsa1024
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = load i32*, i32** @tmp_rsa_callback.rsa1024
store i32* %31, i32** %4
br label %42
32: ; preds = %27
%33 = load i32*, i32** @tmp_rsa_callback.rsa512
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = load i32*, i32** @tmp_rsa_callback.rsa512
store i32* %36, i32** %4
br label %42
37: ; preds = %32
%38 = load i32, i32* %7
%39 = load i32, i32* @RSA_F4
%40 = call i32* @RSA_generate_key(i32 %38, i32 %39, i32* null, i32* null)
store i32* %40, i32** @tmp_rsa_callback.rsa512
%41 = load i32*, i32** @tmp_rsa_callback.rsa512
store i32* %41, i32** %4
br label %42
42: ; preds = %37, %35, %30, %25, %16
%43 = load i32*, i32** %4
ret i32* %43
}

LLVM IR (-O2):
@tmp_rsa_callback.rsa512 = internal unnamed_addr global i32* null
@tmp_rsa_callback.rsa1024 = internal unnamed_addr global i32* null
@RSA_F4 = global i32 0
define i32* @tmp_rsa_callback(i32* nocapture readnone %0, i32 %1, i32 %2) {
switch i32 %2, label %16 [
i32 512, label %4
i32 1024, label %10
]
4: ; preds = %3
%5 = load i32*, i32** @tmp_rsa_callback.rsa512
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %25
7: ; preds = %4
%8 = load i32, i32* @RSA_F4
%9 = tail call i32* @RSA_generate_key(i32 512, i32 %8, i32* null, i32* null)
store i32* %9, i32** @tmp_rsa_callback.rsa512
br label %25
10: ; preds = %3
%11 = load i32*, i32** @tmp_rsa_callback.rsa1024
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %25
13: ; preds = %10
%14 = load i32, i32* @RSA_F4
%15 = tail call i32* @RSA_generate_key(i32 1024, i32 %14, i32* null, i32* null)
store i32* %15, i32** @tmp_rsa_callback.rsa1024
br label %25
16: ; preds = %3
%17 = load i32*, i32** @tmp_rsa_callback.rsa1024
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i32*, i32** @tmp_rsa_callback.rsa512
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* @RSA_F4
%24 = tail call i32* @RSA_generate_key(i32 %2, i32 %23, i32* null, i32* null)
store i32* %24, i32** @tmp_rsa_callback.rsa512
br label %25
25: ; preds = %10, %13, %4, %7, %19, %16, %22
%26 = phi i32* [ %24, %22 ], [ %17, %16 ], [ %20, %19 ], [ %9, %7 ], [ %5, %4 ], [ %15, %13 ], [ %11, %10 ]
ret i32* %26
}