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

/* Variables and functions */
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, unsigned int);
int oracle_check_valid(int /*<<< orphan*/ *);
int /*<<< orphan*/ oracle_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *oracle_query(char *, unsigned int, unsigned char *, int,
                                 unsigned char *, unsigned int);
int run_oracle_valid(char *hostport, unsigned int keysize,
                     unsigned char *encrypted_key,
                     unsigned int encrypted_key_length) {
  unsigned char clear_key[keysize];
  memset(clear_key, 0, keysize);
  SSL *ssl = oracle_query(hostport, keysize, clear_key, sizeof(clear_key),
                          encrypted_key, encrypted_key_length);
  if (ssl == NULL)
    return 0;
  int res = oracle_check_valid(ssl);
  oracle_free(ssl);
  return res;
}


x86 assembly (clang, -O0):
<run_oracle_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x14(%rbp),%eax
mov    %rax,-0x50(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x58(%rbp),%rdx
mov    -0x50(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    %eax,%ecx
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
call   1050 <oracle_query@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11ca <run_oracle_valid+0x8a>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    11ec <run_oracle_valid+0xac>
mov    -0x40(%rbp),%rdi
call   1030 <oracle_check_valid@plt>
mov    %eax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
call   1060 <oracle_free@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_oracle_valid>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,-0x2c(%rbp)
mov    %rdx,%r12
mov    %esi,%ebx
mov    %rdi,%r13
mov    %esi,%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
xor    %r15d,%r15d
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1040 <memset@plt>
mov    %r13,%rdi
mov    %ebx,%esi
mov    %r14,%rdx
mov    %ebx,%ecx
mov    %r12,%r8
mov    -0x2c(%rbp),%r9d
call   1050 <oracle_query@plt>
test   %rax,%rax
je     11ac <run_oracle_valid+0x6c>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <oracle_check_valid@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1060 <oracle_free@plt>
mov    %r15d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @run_oracle_valid(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%15 = load i32, i32* %7
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %10
%18 = alloca i8, i64 %16
store i64 %16, i64* %11
%19 = load i32, i32* %7
%20 = call i32 @memset(i8* %18, i32 0, i32 %19)
%21 = load i8*, i8** %6
%22 = load i32, i32* %7
%23 = trunc i64 %16 to i32
%24 = load i8*, i8** %8
%25 = load i32, i32* %9
%26 = call i32* @oracle_query(i8* %21, i32 %22, i8* %18, i32 %23, i8* %24, i32 %25)
store i32* %26, i32** %12
%27 = load i32*, i32** %12
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %30
29: ; preds = %4
store i32 0, i32* %5
store i32 1, i32* %13
br label %36
30: ; preds = %4
%31 = load i32*, i32** %12
%32 = call i32 @oracle_check_valid(i32* %31)
store i32 %32, i32* %14
%33 = load i32*, i32** %12
%34 = call i32 @oracle_free(i32* %33)
%35 = load i32, i32* %14
store i32 %35, i32* %5
store i32 1, i32* %13
br label %36
36: ; preds = %30, %29
%37 = load i8*, i8** %10
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
define i32 @run_oracle_valid(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = zext i32 %1 to i64
%6 = alloca i8, i64 %5
%7 = call i32 @memset(i8* %6, i32 0, i32 %1)
%8 = call i32* @oracle_query(i8* %0, i32 %1, i8* %6, i32 %1, i8* %2, i32 %3)
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %4
%11 = call i32 @oracle_check_valid(i32* %8)
%12 = call i32 @oracle_free(i32* %8)
br label %13
13: ; preds = %4, %10
%14 = phi i32 [ %11, %10 ], [ 0, %4 ]
ret i32 %14
}