#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*/ uint8_t;
typedef int /*<<< orphan*/ uint;
typedef int /*<<< orphan*/ RSA;

/* Variables and functions */
int /*<<< orphan*/ RSA_free(int /*<<< orphan*/ *);
int rsa_get_priv_key(char const *, int /*<<< orphan*/ **);
int rsa_init();
int /*<<< orphan*/ rsa_remove();
int rsa_sign_with_key(int /*<<< orphan*/ *, void const *, int const,
                      int /*<<< orphan*/ **, int /*<<< orphan*/ *);
int rsa_sign(const char *private_path, const void *data, const int size,
             uint8_t **sigp, uint *sig_len) {
  RSA *rsa;
  int ret;
  ret = rsa_init();
  if (ret)
    return ret;
  ret = rsa_get_priv_key(private_path, &rsa);
  if (ret)
    goto err_priv;
  ret = rsa_sign_with_key(rsa, data, size, sigp, sig_len);
  if (ret)
    goto err_sign;
  RSA_free(rsa);
  rsa_remove();
  return ret;
err_sign:
  RSA_free(rsa);
err_priv:
  rsa_remove();
  return ret;
}


x86 assembly (clang, -O0):
<rsa_sign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    $0x0,%al
call   1070 <rsa_init@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     118a <rsa_sign+0x3a>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1204 <rsa_sign+0xb4>
mov    -0x10(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1030 <rsa_get_priv_key@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     11a9 <rsa_sign+0x59>
jmp    11f7 <rsa_sign+0xa7>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1060 <rsa_sign_with_key@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     11d3 <rsa_sign+0x83>
jmp    11ee <rsa_sign+0x9e>
mov    -0x38(%rbp),%rdi
call   1050 <RSA_free@plt>
mov    $0x0,%al
call   1040 <rsa_remove@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1204 <rsa_sign+0xb4>
mov    -0x38(%rbp),%rdi
call   1050 <RSA_free@plt>
mov    $0x0,%al
call   1040 <rsa_remove@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rsa_sign>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %edx,%r12d
mov    %rsi,%r13
mov    %rdi,%rbp
xor    %eax,%eax
call   1070 <rsa_init@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    11b5 <rsa_sign+0x65>
mov    %rsp,%rsi
mov    %rbp,%rdi
call   1030 <rsa_get_priv_key@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    11ae <rsa_sign+0x5e>
mov    (%rsp),%rdi
mov    %r13,%rsi
mov    %r12d,%edx
mov    %r15,%rcx
mov    %r14,%r8
call   1060 <rsa_sign_with_key@plt>
mov    %eax,%ebx
mov    (%rsp),%rdi
call   1050 <RSA_free@plt>
test   %ebx,%ebx
jne    11ae <rsa_sign+0x5e>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <rsa_remove@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @rsa_sign(i8* %0, i8* %1, i32 %2, i32** %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32**
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32** %3, i32*** %10
store i32* %4, i32** %11
%14 = call i32 (...) @rsa_init()
store i32 %14, i32* %13
%15 = load i32, i32* %13
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %5
%18 = load i32, i32* %13
store i32 %18, i32* %6
br label %46
19: ; preds = %5
%20 = load i8*, i8** %7
%21 = call i32 @rsa_get_priv_key(i8* %20, i32** %12)
store i32 %21, i32* %13
%22 = load i32, i32* %13
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
br label %43
25: ; preds = %19
%26 = load i32*, i32** %12
%27 = load i8*, i8** %8
%28 = load i32, i32* %9
%29 = load i32**, i32*** %10
%30 = load i32*, i32** %11
%31 = call i32 @rsa_sign_with_key(i32* %26, i8* %27, i32 %28, i32** %29, i32* %30)
store i32 %31, i32* %13
%32 = load i32, i32* %13
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %25
br label %40
35: ; preds = %25
%36 = load i32*, i32** %12
%37 = call i32 @RSA_free(i32* %36)
%38 = call i32 (...) @rsa_remove()
%39 = load i32, i32* %13
store i32 %39, i32* %6
br label %46
40: ; preds = %34
%41 = load i32*, i32** %12
%42 = call i32 @RSA_free(i32* %41)
br label %43
43: ; preds = %40, %24
%44 = call i32 (...) @rsa_remove()
%45 = load i32, i32* %13
store i32 %45, i32* %6
br label %46
46: ; preds = %43, %35, %17
%47 = load i32, i32* %6
ret i32 %47
}

LLVM IR (-O2):
define i32 @rsa_sign(i8* %0, i8* %1, i32 %2, i32** %3, i32* %4) {
%6 = alloca i32*
%7 = bitcast i32** %6 to i8*
%8 = tail call i32 (...) @rsa_init()
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %24
10: ; preds = %5
%11 = call i32 @rsa_get_priv_key(i8* %0, i32** %6)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i32*, i32** %6
%15 = call i32 @rsa_sign_with_key(i32* %14, i8* %1, i32 %2, i32** %3, i32* %4)
%16 = icmp eq i32 %15, 0
%17 = load i32*, i32** %6
%18 = call i32 @RSA_free(i32* %17)
br i1 %16, label %21, label %19
19: ; preds = %13, %10
%20 = phi i32 [ %11, %10 ], [ %15, %13 ]
br label %21
21: ; preds = %13, %19
%22 = phi i32 [ %20, %19 ], [ 0, %13 ]
%23 = call i32 (...) @rsa_remove()
br label %24
24: ; preds = %21, %5
%25 = phi i32 [ %8, %5 ], [ %22, %21 ]
ret i32 %25
}