#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_div(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ const *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_gcd(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                          int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_mul(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                          int /*<<< orphan*/ *, 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 BN_lcm(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) {
  int ret = 0;
  BN_CTX_start(ctx);
  BIGNUM *tmp = BN_CTX_get(ctx);
  BIGNUM *gcd = BN_CTX_get(ctx);
  if (!BN_gcd(gcd, a, b, ctx))
    goto end;
  if (!BN_div(tmp, NULL, a, gcd, ctx))
    goto end;
  if (!BN_mul(r, b, tmp, ctx))
    goto end;
  ret = 1;
end:
  if (ret != 1) {
    ERR_load_crypto_strings();
    fprintf(stderr, "Error calculating lcm: %s",
            ERR_error_string(ERR_get_error(), NULL));
  }
  BN_CTX_end(ctx);
  return ret;
}


x86 assembly (clang, -O0):
<BN_lcm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <BN_CTX_start@plt>
mov    -0x20(%rbp),%rdi
call   1030 <BN_CTX_get@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%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
call   1040 <BN_gcd@plt>
cmp    $0x0,%eax
jne    1205 <BN_lcm+0x65>
jmp    1256 <BN_lcm+0xb6>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x20(%rbp),%r8
xor    %eax,%eax
mov    %eax,%esi
call   10c0 <BN_div@plt>
cmp    $0x0,%eax
jne    122c <BN_lcm+0x8c>
jmp    1256 <BN_lcm+0xb6>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1050 <BN_mul@plt>
cmp    $0x0,%eax
jne    124f <BN_lcm+0xaf>
jmp    1256 <BN_lcm+0xb6>
movl   $0x1,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
je     1297 <BN_lcm+0xf7>
mov    $0x0,%al
call   10b0 <ERR_load_crypto_strings@plt>
mov    0x2d72(%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    0xd6e(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <BN_CTX_end@plt>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BN_lcm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%r14
mov    %rcx,%rdi
call   1070 <BN_CTX_start@plt>
mov    %rbx,%rdi
call   1030 <BN_CTX_get@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   1030 <BN_CTX_get@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1040 <BN_gcd@plt>
test   %eax,%eax
je     1227 <BN_lcm+0x87>
mov    %r14,(%rsp)
xor    %r14d,%r14d
mov    %r13,%rdi
xor    %esi,%esi
mov    %rbp,%rdx
mov    %r12,%rcx
mov    %rbx,%r8
call   10c0 <BN_div@plt>
test   %eax,%eax
je     122a <BN_lcm+0x8a>
mov    (%rsp),%rdi
mov    %r15,%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1050 <BN_mul@plt>
xor    %r14d,%r14d
test   %eax,%eax
setne  %r14b
jne    125b <BN_lcm+0xbb>
jmp    122a <BN_lcm+0x8a>
xor    %r14d,%r14d
xor    %eax,%eax
call   10b0 <ERR_load_crypto_strings@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
call   10a0 <ERR_get_error@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1090 <ERR_error_string@plt>
lea    0xdaf(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1060 <BN_CTX_end@plt>
mov    %r14d,%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 = [26 x i8] c"Error calculating lcm: %s\00"
define i32 @BN_lcm(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i32 0, i32* %9
%12 = load i32*, i32** %8
%13 = call i32 @BN_CTX_start(i32* %12)
%14 = load i32*, i32** %8
%15 = call i32* @BN_CTX_get(i32* %14)
store i32* %15, i32** %10
%16 = load i32*, i32** %8
%17 = call i32* @BN_CTX_get(i32* %16)
store i32* %17, i32** %11
%18 = load i32*, i32** %11
%19 = load i32*, i32** %6
%20 = load i32*, i32** %7
%21 = load i32*, i32** %8
%22 = call i32 @BN_gcd(i32* %18, i32* %19, i32* %20, i32* %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %4
br label %42
25: ; preds = %4
%26 = load i32*, i32** %10
%27 = load i32*, i32** %6
%28 = load i32*, i32** %11
%29 = load i32*, i32** %8
%30 = call i32 @BN_div(i32* %26, i32* null, i32* %27, i32* %28, i32* %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %25
br label %42
33: ; preds = %25
%34 = load i32*, i32** %5
%35 = load i32*, i32** %7
%36 = load i32*, i32** %10
%37 = load i32*, i32** %8
%38 = call i32 @BN_mul(i32* %34, i32* %35, i32* %36, i32* %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %33
br label %42
41: ; preds = %33
store i32 1, i32* %9
br label %42
42: ; preds = %41, %40, %32, %24
%43 = load i32, i32* %9
%44 = icmp ne i32 %43, 1
br i1 %44, label %45, label %51
45: ; preds = %42
%46 = call i32 (...) @ERR_load_crypto_strings()
%47 = load i32, i32* @stderr
%48 = call i32 (...) @ERR_get_error()
%49 = call i8* @ERR_error_string(i32 %48, i32* null)
%50 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %49)
br label %51
51: ; preds = %45, %42
%52 = load i32*, i32** %8
%53 = call i32 @BN_CTX_end(i32* %52)
%54 = load i32, i32* %9
ret i32 %54
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Error calculating lcm: %s\00"
define i32 @BN_lcm(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = tail call i32 @BN_CTX_start(i32* %3)
%6 = tail call i32* @BN_CTX_get(i32* %3)
%7 = tail call i32* @BN_CTX_get(i32* %3)
%8 = tail call i32 @BN_gcd(i32* %7, i32* %1, i32* %2, i32* %3)
%9 = icmp eq i32 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %4
%11 = tail call i32 @BN_div(i32* %6, i32* null, i32* %1, i32* %7, i32* %3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %10
%14 = tail call i32 @BN_mul(i32* %0, i32* %2, i32* %6, i32* %3)
%15 = icmp eq i32 %14, 0
%16 = xor i1 %15, true
%17 = zext i1 %16 to i32
br i1 %15, label %18, label %25
18: ; preds = %4, %10, %13
%19 = phi i32 [ %17, %13 ], [ 0, %10 ], [ 0, %4 ]
%20 = tail call i32 (...) @ERR_load_crypto_strings()
%21 = load i32, i32* @stderr
%22 = tail call i32 (...) @ERR_get_error()
%23 = tail call i8* @ERR_error_string(i32 %22, i32* null)
%24 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %18, %13
%26 = phi i32 [ %19, %18 ], [ %17, %13 ]
%27 = tail call i32 @BN_CTX_end(i32* %3)
ret i32 %26
}