#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_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_CTX_new();
int BN_mod_sub(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
               int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_new();
int /*<<< orphan*/ printf(char *, int);
BIGNUM *subm(BIGNUM *a, BIGNUM *b, BIGNUM *m) {
  BN_CTX *ctx = BN_CTX_new();
  BIGNUM *result = BN_new();
  int ret = BN_mod_sub(result, a, b, m, ctx);
  if (ret != 1) {
    printf("subm: BN_sub failed: %d", ret);
    result = NULL;
  }
  BN_CTX_free(ctx);
  return result;
}


x86 assembly (clang, -O0):
<subm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1070 <BN_CTX_new@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <BN_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1040 <BN_mod_sub@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
je     11b7 <subm+0x67>
mov    -0x2c(%rbp),%esi
lea    0xe56(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <BN_CTX_free@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<subm>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
xor    %eax,%eax
call   1070 <BN_CTX_new@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <BN_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <BN_mod_sub@plt>
cmp    $0x1,%eax
je     119f <subm+0x4f>
lea    0xe6a(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1060 <BN_CTX_free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [24 x i8] c"subm: BN_sub failed: %d\00"
define i32* @subm(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%10 = call i32* (...) @BN_CTX_new()
store i32* %10, i32** %7
%11 = call i32* (...) @BN_new()
store i32* %11, i32** %8
%12 = load i32*, i32** %8
%13 = load i32*, i32** %4
%14 = load i32*, i32** %5
%15 = load i32*, i32** %6
%16 = load i32*, i32** %7
%17 = call i32 @BN_mod_sub(i32* %12, i32* %13, i32* %14, i32* %15, i32* %16)
store i32 %17, i32* %9
%18 = load i32, i32* %9
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %23
20: ; preds = %3
%21 = load i32, i32* %9
%22 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32* null, i32** %8
br label %23
23: ; preds = %20, %3
%24 = load i32*, i32** %7
%25 = call i32 @BN_CTX_free(i32* %24)
%26 = load i32*, i32** %8
ret i32* %26
}

LLVM IR (-O2):
@.str = [24 x i8] c"subm: BN_sub failed: %d\00"
define i32* @subm(i32* %0, i32* %1, i32* %2) {
%4 = tail call i32* (...) @BN_CTX_new()
%5 = tail call i32* (...) @BN_new()
%6 = tail call i32 @BN_mod_sub(i32* %5, i32* %0, i32* %1, i32* %2, i32* %4)
%7 = icmp eq i32 %6, 1
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %10
10: ; preds = %8, %3
%11 = phi i32* [ null, %8 ], [ %5, %3 ]
%12 = tail call i32 @BN_CTX_free(i32* %4)
ret i32* %11
}