#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 check_blob_sign(void *, int);
int check_rsa_pub_sign(void *, int, int /*<<< orphan*/ *);
int decrypt_key_and_burn_key(void *, int, void *, void *, int);
int /*<<< orphan*/ printf(char *);
int update_key(void *data_buf, int buf_len, RSA *secure_pub_key,
               void *secure_aes_key, void *hmac_msg, int msg_len) {
  int ret = -1;
  if (check_rsa_pub_sign(data_buf, buf_len, secure_pub_key) == -1) {
    printf("check rsa pub sign failed");
    goto exit;
  }
  if (check_blob_sign(data_buf, buf_len) == -1) {
    printf("check blob sign failed");
    goto exit;
  }
  ret = decrypt_key_and_burn_key(data_buf, buf_len, secure_aes_key, hmac_msg,
                                 msg_len);
  if (ret == -1)
    printf("check DEC KEY failed");
exit:
  return ret;
}


x86 assembly (clang, -O0):
<update_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
movl   $0xffffffff,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1060 <check_rsa_pub_sign@plt>
cmp    $0xffffffff,%eax
jne    1190 <update_key+0x50>
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
jmp    11ec <update_key+0xac>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <check_blob_sign@plt>
cmp    $0xffffffff,%eax
jne    11b6 <update_key+0x76>
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
jmp    11ec <update_key+0xac>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
call   1030 <decrypt_key_and_burn_key@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    11e7 <update_key+0xa7>
lea    0xe4f(%rip),%rdi
call   1040 <printf@plt>
jmp    11ec <update_key+0xac>
mov    -0x30(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_key>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r9d,%r14d
mov    %r8,%r15
mov    %rcx,%r12
mov    %esi,%ebx
mov    %rdi,%rbp
call   1060 <check_rsa_pub_sign@plt>
cmp    $0xffffffff,%eax
je     1190 <update_key+0x50>
mov    %rbp,%rdi
mov    %ebx,%esi
call   1050 <check_blob_sign@plt>
cmp    $0xffffffff,%eax
je     1199 <update_key+0x59>
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14d,%r8d
call   1030 <decrypt_key_and_burn_key@plt>
cmp    $0xffffffff,%eax
jne    11aa <update_key+0x6a>
lea    0xea3(%rip),%rdi
jmp    11a0 <update_key+0x60>
lea    0xe69(%rip),%rdi
jmp    11a0 <update_key+0x60>
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"check rsa pub sign failed\00"
@.str.1 = [23 x i8] c"check blob sign failed\00"
@.str.2 = [21 x i8] c"check DEC KEY failed\00"
define i32 @update_key(i8* %0, i32 %1, i32* %2, i8* %3, i8* %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32* %2, i32** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i32 %5, i32* %12
store i32 -1, i32* %13
%14 = load i8*, i8** %7
%15 = load i32, i32* %8
%16 = load i32*, i32** %9
%17 = call i32 @check_rsa_pub_sign(i8* %14, i32 %15, i32* %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %6
%20 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %40
21: ; preds = %6
%22 = load i8*, i8** %7
%23 = load i32, i32* %8
%24 = call i32 @check_blob_sign(i8* %22, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %40
28: ; preds = %21
%29 = load i8*, i8** %7
%30 = load i32, i32* %8
%31 = load i8*, i8** %10
%32 = load i8*, i8** %11
%33 = load i32, i32* %12
%34 = call i32 @decrypt_key_and_burn_key(i8* %29, i32 %30, i8* %31, i8* %32, i32 %33)
store i32 %34, i32* %13
%35 = load i32, i32* %13
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %28
%38 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %28
br label %40
40: ; preds = %39, %26, %19
%41 = load i32, i32* %13
ret i32 %41
}

LLVM IR (-O2):
@.str = [26 x i8] c"check rsa pub sign failed\00"
@.str.1 = [23 x i8] c"check blob sign failed\00"
@.str.2 = [21 x i8] c"check DEC KEY failed\00"
define i32 @update_key(i8* %0, i32 %1, i32* %2, i8* %3, i8* %4, i32 %5) {
%7 = tail call i32 @check_rsa_pub_sign(i8* %0, i32 %1, i32* %2)
%8 = icmp eq i32 %7, -1
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = tail call i32 @check_blob_sign(i8* %0, i32 %1)
%11 = icmp eq i32 %10, -1
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i32 @decrypt_key_and_burn_key(i8* %0, i32 %1, i8* %3, i8* %4, i32 %5)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %12, %9, %6
%16 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), %6 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), %9 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), %12 ]
%17 = tail call i32 @printf(i8* dereferenceable(1) %16)
br label %18
18: ; preds = %15, %12
%19 = phi i32 [ %13, %12 ], [ -1, %15 ]
ret i32 %19
}