#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*/ BN_CTX;
typedef int /*<<< orphan*/ BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ BN_CTX_end(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_CTX_get(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_CTX_start(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_copy(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_mod_mul(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
char *ERR_error_string(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ ERR_get_error();
int /*<<< orphan*/ ERR_load_crypto_strings();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int add(BIGNUM *result, const BIGNUM *a, const BIGNUM *b, const BIGNUM *n2,
        BN_CTX *ctx) {
  int ret = 1;
  BN_CTX_start(ctx);
  BIGNUM *tmp1 = BN_CTX_get(ctx);
  if (!BN_mod_mul(tmp1, a, b, n2, ctx))
    goto end;
  BN_copy(result, tmp1);
  ret = 0;
end:
  if (ret) {
    ERR_load_crypto_strings();
    fprintf(stderr, "add: %s", ERR_error_string(ERR_get_error(), NULL));
  }
  BN_CTX_end(ctx);
  return ret;
}


x86 assembly (clang, -O0):
<add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <BN_CTX_start@plt>
mov    -0x28(%rbp),%rdi
call   1030 <BN_CTX_get@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1080 <BN_mod_mul@plt>
cmp    $0x0,%eax
jne    11f0 <add+0x60>
jmp    1204 <add+0x74>
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1060 <BN_copy@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1245 <add+0xb5>
mov    $0x0,%al
call   10b0 <ERR_load_crypto_strings@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    $0x0,%al
call   10a0 <ERR_get_error@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1090 <ERR_error_string@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rdx
lea    0xdc0(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <BN_CTX_end@plt>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%r14
mov    %r8,%rdi
call   1050 <BN_CTX_start@plt>
mov    %r15,%rdi
call   1030 <BN_CTX_get@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %r15,%r8
call   1080 <BN_mod_mul@plt>
test   %eax,%eax
je     11e4 <add+0x54>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <BN_copy@plt>
xor    %ebx,%ebx
jmp    121a <add+0x8a>
xor    %eax,%eax
call   10b0 <ERR_load_crypto_strings@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   10a0 <ERR_get_error@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1090 <ERR_error_string@plt>
lea    0xdf5(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%ebx
mov    %r15,%rdi
call   1040 <BN_CTX_end@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [8 x i8] c"add: %s\00"
define i32 @add(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32*
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
store i32 1, i32* %11
%13 = load i32*, i32** %10
%14 = call i32 @BN_CTX_start(i32* %13)
%15 = load i32*, i32** %10
%16 = call i32* @BN_CTX_get(i32* %15)
store i32* %16, i32** %12
%17 = load i32*, i32** %12
%18 = load i32*, i32** %7
%19 = load i32*, i32** %8
%20 = load i32*, i32** %9
%21 = load i32*, i32** %10
%22 = call i32 @BN_mod_mul(i32* %17, i32* %18, i32* %19, i32* %20, i32* %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %5
br label %29
25: ; preds = %5
%26 = load i32*, i32** %6
%27 = load i32*, i32** %12
%28 = call i32 @BN_copy(i32* %26, i32* %27)
store i32 0, i32* %11
br label %29
29: ; preds = %25, %24
%30 = load i32, i32* %11
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = call i32 (...) @ERR_load_crypto_strings()
%34 = load i32, i32* @stderr
%35 = call i32 (...) @ERR_get_error()
%36 = call i8* @ERR_error_string(i32 %35, i32* null)
%37 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %32, %29
%39 = load i32*, i32** %10
%40 = call i32 @BN_CTX_end(i32* %39)
%41 = load i32, i32* %11
ret i32 %41
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [8 x i8] c"add: %s\00"
define i32 @add(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = tail call i32 @BN_CTX_start(i32* %4)
%7 = tail call i32* @BN_CTX_get(i32* %4)
%8 = tail call i32 @BN_mod_mul(i32* %7, i32* %1, i32* %2, i32* %3, i32* %4)
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %5
%11 = tail call i32 @BN_copy(i32* %0, i32* %7)
br label %18
12: ; preds = %5
%13 = tail call i32 (...) @ERR_load_crypto_strings()
%14 = load i32, i32* @stderr
%15 = tail call i32 (...) @ERR_get_error()
%16 = tail call i8* @ERR_error_string(i32 %15, i32* null)
%17 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %10, %12
%19 = phi i32 [ 1, %12 ], [ 0, %10 ]
%20 = tail call i32 @BN_CTX_end(i32* %4)
ret i32 %19
}