#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 */
struct muggle_des_subkeys {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/
muggle_openssl_des_set_key_unchecked(unsigned char *,
                                     struct muggle_des_subkeys *);
int /*<<< orphan*/ openssl_des_check_key_parity(unsigned char *);
scalar_t__ openssl_des_is_weak_key(unsigned char *);
int muggle_openssl_des_set_key_checked(unsigned char *key,
                                       struct muggle_des_subkeys *ks) {
  if (!openssl_des_check_key_parity(key)) {
    return -1;
  }
  if (openssl_des_is_weak_key(key)) {
    return -2;
  }
  muggle_openssl_des_set_key_unchecked(key, ks);
  return 0;
}


x86 assembly (clang, -O0):
<muggle_openssl_des_set_key_checked>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <openssl_des_check_key_parity@plt>
cmp    $0x0,%eax
jne    115e <muggle_openssl_des_set_key_checked+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1191 <muggle_openssl_des_set_key_checked+0x61>
mov    -0x10(%rbp),%rdi
call   1050 <openssl_des_is_weak_key@plt>
cmp    $0x0,%rax
je     117d <muggle_openssl_des_set_key_checked+0x4d>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1191 <muggle_openssl_des_set_key_checked+0x61>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <muggle_openssl_des_set_key_unchecked@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<muggle_openssl_des_set_key_checked>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <openssl_des_check_key_parity@plt>
test   %eax,%eax
je     1167 <muggle_openssl_des_set_key_checked+0x37>
mov    %rbx,%rdi
call   1050 <openssl_des_is_weak_key@plt>
mov    %rax,%rcx
mov    $0xfffffffe,%eax
test   %rcx,%rcx
jne    116c <muggle_openssl_des_set_key_checked+0x3c>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <muggle_openssl_des_set_key_unchecked@plt>
xor    %eax,%eax
jmp    116c <muggle_openssl_des_set_key_checked+0x3c>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.muggle_des_subkeys = type { i32 }
define i32 @muggle_openssl_des_set_key_checked(i8* %0, %struct.muggle_des_subkeys* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.muggle_des_subkeys*
store i8* %0, i8** %4
store %struct.muggle_des_subkeys* %1, %struct.muggle_des_subkeys** %5
%6 = load i8*, i8** %4
%7 = call i32 @openssl_des_check_key_parity(i8* %6)
%8 = icmp ne i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %2
store i32 -1, i32* %3
br label %19
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i64 @openssl_des_is_weak_key(i8* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 -2, i32* %3
br label %19
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = load %struct.muggle_des_subkeys*, %struct.muggle_des_subkeys** %5
%18 = call i32 @muggle_openssl_des_set_key_unchecked(i8* %16, %struct.muggle_des_subkeys* %17)
store i32 0, i32* %3
br label %19
19: ; preds = %15, %14, %9
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
%struct.muggle_des_subkeys = type { i32 }
define i32 @muggle_openssl_des_set_key_checked(i8* %0, %struct.muggle_des_subkeys* %1) {
%3 = tail call i32 @openssl_des_check_key_parity(i8* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = tail call i64 @openssl_des_is_weak_key(i8* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @muggle_openssl_des_set_key_unchecked(i8* %0, %struct.muggle_des_subkeys* %1)
br label %10
10: ; preds = %5, %2, %8
%11 = phi i32 [ 0, %8 ], [ -1, %2 ], [ -2, %5 ]
ret i32 %11
}