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

/* Variables and functions */
int /*<<< orphan*/ *get_dh1024();
int /*<<< orphan*/ *get_dh2048();
int /*<<< orphan*/ printf(char *, int);
DH *tmp_dh_callback(SSL *s, int is_export, int keylength) {
  static DH *dh_2048 = NULL;
  static DH *dh_1024 = NULL;
  DH *dh_tmp = NULL;
  switch (keylength) {
  case 2048:
    if (!dh_2048)
      dh_2048 = get_dh2048();
    dh_tmp = dh_2048;
    break;
  case 1024:
    if (!dh_1024)
      dh_1024 = get_dh1024();
    dh_tmp = dh_1024;
    break;
  default:
    printf("Keylength %d \n", keylength);
  }
  return (dh_tmp);
}


x86 assembly (clang, -O0):
<tmp_dh_callback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x400,%eax
je     119f <tmp_dh_callback+0x6f>
jmp    1160 <tmp_dh_callback+0x30>
mov    -0x1c(%rbp),%eax
sub    $0x800,%eax
jne    11cb <tmp_dh_callback+0x9b>
jmp    1173 <tmp_dh_callback+0x43>
cmpq   $0x0,0x2ec5(%rip)
jne    118f <tmp_dh_callback+0x5f>
mov    $0x0,%al
call   1030 <get_dh2048@plt>
mov    %rax,0x2eb1(%rip)
mov    0x2eaa(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11da <tmp_dh_callback+0xaa>
cmpq   $0x0,0x2ea1(%rip)
jne    11bb <tmp_dh_callback+0x8b>
mov    $0x0,%al
call   1050 <get_dh1024@plt>
mov    %rax,0x2e8d(%rip)
mov    0x2e86(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11da <tmp_dh_callback+0xaa>
mov    -0x10(%rbp),%esi
lea    0xe2b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tmp_dh_callback>:
push   %rax
cmp    $0x400,%edx
je     114f <tmp_dh_callback+0x1f>
cmp    $0x800,%edx
jne    116b <tmp_dh_callback+0x3b>
mov    0x2ef8(%rip),%rax
test   %rax,%rax
je     117d <tmp_dh_callback+0x4d>
pop    %rcx
ret
mov    0x2ef2(%rip),%rax
test   %rax,%rax
jne    114d <tmp_dh_callback+0x1d>
xor    %eax,%eax
call   1050 <get_dh1024@plt>
mov    %rax,0x2edf(%rip)
pop    %rcx
ret
lea    0xe8e(%rip),%rdi
mov    %edx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret
xor    %eax,%eax
call   1030 <get_dh2048@plt>
mov    %rax,0x2eb5(%rip)
pop    %rcx
ret

LLVM IR (-O0):
@tmp_dh_callback.dh_2048 = internal global i32* null
@tmp_dh_callback.dh_1024 = internal global i32* null
@.str = [15 x i8] c"Keylength %d \0A\00"
define i32* @tmp_dh_callback(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32* null, i32** %7
%8 = load i32, i32* %6
switch i32 %8, label %23 [
i32 2048, label %9
i32 1024, label %16
]
9: ; preds = %3
%10 = load i32*, i32** @tmp_dh_callback.dh_2048
%11 = icmp ne i32* %10, null
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = call i32* (...) @get_dh2048()
store i32* %13, i32** @tmp_dh_callback.dh_2048
br label %14
14: ; preds = %12, %9
%15 = load i32*, i32** @tmp_dh_callback.dh_2048
store i32* %15, i32** %7
br label %26
16: ; preds = %3
%17 = load i32*, i32** @tmp_dh_callback.dh_1024
%18 = icmp ne i32* %17, null
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = call i32* (...) @get_dh1024()
store i32* %20, i32** @tmp_dh_callback.dh_1024
br label %21
21: ; preds = %19, %16
%22 = load i32*, i32** @tmp_dh_callback.dh_1024
store i32* %22, i32** %7
br label %26
23: ; preds = %3
%24 = load i32, i32* %6
%25 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %23, %21, %14
%27 = load i32*, i32** %7
ret i32* %27
}

LLVM IR (-O2):
@tmp_dh_callback.dh_2048 = internal unnamed_addr global i32* null
@tmp_dh_callback.dh_1024 = internal unnamed_addr global i32* null
@.str = [15 x i8] c"Keylength %d \0A\00"
define i32* @tmp_dh_callback(i32* nocapture readnone %0, i32 %1, i32 %2) {
switch i32 %2, label %14 [
i32 2048, label %4
i32 1024, label %9
]
4: ; preds = %3
%5 = load i32*, i32** @tmp_dh_callback.dh_2048
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %16
7: ; preds = %4
%8 = tail call i32* (...) @get_dh2048()
store i32* %8, i32** @tmp_dh_callback.dh_2048
br label %16
9: ; preds = %3
%10 = load i32*, i32** @tmp_dh_callback.dh_1024
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = tail call i32* (...) @get_dh1024()
store i32* %13, i32** @tmp_dh_callback.dh_1024
br label %16
14: ; preds = %3
%15 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %16
16: ; preds = %9, %12, %4, %7, %14
%17 = phi i32* [ null, %14 ], [ %8, %7 ], [ %5, %4 ], [ %13, %12 ], [ %10, %9 ]
ret i32* %17
}