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

/* Variables and functions */
int /*<<< orphan*/ *RSA_new();
int key1(int /*<<< orphan*/ *, unsigned char *);
int key2(int /*<<< orphan*/ *, unsigned char *);
int key3(int /*<<< orphan*/ *, unsigned char *);
int rsa_setkey(RSA **key, unsigned char *ctext, int idx) {
  int clen = 0;
  *key = RSA_new();
  switch (idx) {
  case 0:
    clen = key1(*key, ctext);
    break;
  case 1:
    clen = key2(*key, ctext);
    break;
  case 2:
    clen = key3(*key, ctext);
    break;
  }
  return clen;
}


x86 assembly (clang, -O0):
<rsa_setkey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
xor    %eax,%eax
call   1040 <RSA_new@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     11a0 <rsa_setkey+0x60>
jmp    117e <rsa_setkey+0x3e>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
je     11b8 <rsa_setkey+0x78>
jmp    118f <rsa_setkey+0x4f>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     11d0 <rsa_setkey+0x90>
jmp    11e3 <rsa_setkey+0xa3>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <key1@plt>
mov    %eax,-0x18(%rbp)
jmp    11e3 <rsa_setkey+0xa3>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <key2@plt>
mov    %eax,-0x18(%rbp)
jmp    11e3 <rsa_setkey+0xa3>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <key3@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rsa_setkey>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <RSA_new@plt>
mov    %rax,(%rbx)
cmp    $0x2,%ebp
je     1173 <rsa_setkey+0x33>
cmp    $0x1,%ebp
je     1182 <rsa_setkey+0x42>
test   %ebp,%ebp
jne    1191 <rsa_setkey+0x51>
mov    %rax,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <key1@plt>
mov    %rax,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <key3@plt>
mov    %rax,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <key2@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @rsa_setkey(i32** %0, i8* %1, i32 %2) {
%4 = alloca i32**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32** %0, i32*** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
%8 = call i32* (...) @RSA_new()
%9 = load i32**, i32*** %4
store i32* %8, i32** %9
%10 = load i32, i32* %6
switch i32 %10, label %26 [
i32 0, label %11
i32 1, label %16
i32 2, label %21
]
11: ; preds = %3
%12 = load i32**, i32*** %4
%13 = load i32*, i32** %12
%14 = load i8*, i8** %5
%15 = call i32 @key1(i32* %13, i8* %14)
store i32 %15, i32* %7
br label %26
16: ; preds = %3
%17 = load i32**, i32*** %4
%18 = load i32*, i32** %17
%19 = load i8*, i8** %5
%20 = call i32 @key2(i32* %18, i8* %19)
store i32 %20, i32* %7
br label %26
21: ; preds = %3
%22 = load i32**, i32*** %4
%23 = load i32*, i32** %22
%24 = load i8*, i8** %5
%25 = call i32 @key3(i32* %23, i8* %24)
store i32 %25, i32* %7
br label %26
26: ; preds = %3, %21, %16, %11
%27 = load i32, i32* %7
ret i32 %27
}

LLVM IR (-O2):
define i32 @rsa_setkey(i32** nocapture writeonly %0, i8* %1, i32 %2) {
%4 = tail call i32* (...) @RSA_new()
store i32* %4, i32** %0
switch i32 %2, label %11 [
i32 0, label %5
i32 1, label %7
i32 2, label %9
]
5: ; preds = %3
%6 = tail call i32 @key1(i32* %4, i8* %1)
br label %11
7: ; preds = %3
%8 = tail call i32 @key2(i32* %4, i8* %1)
br label %11
9: ; preds = %3
%10 = tail call i32 @key3(i32* %4, i8* %1)
br label %11
11: ; preds = %3, %9, %7, %5
%12 = phi i32 [ 0, %3 ], [ %10, %9 ], [ %8, %7 ], [ %6, %5 ]
ret i32 %12
}