#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_div(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_dup(int /*<<< orphan*/ const *);
int /*<<< orphan*/ BN_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_sub_word(int /*<<< orphan*/ *, int);
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 L(BIGNUM *res, const BIGNUM *u, const BIGNUM *n, BN_CTX *ctx) {
  int ret = 1;
  BIGNUM *u_cp = BN_dup(u);
  if (!BN_sub_word(u_cp, 1))
    goto end;
  if (!BN_div(res, NULL, u_cp, n, ctx))
    goto end;
  ret = 0;
end:
  if (ret) {
    ERR_load_crypto_strings();
    fprintf(stderr, "Error calculating L: %s",
            ERR_error_string(ERR_get_error(), NULL));
  }
  BN_free(u_cp);
  return ret;
}


x86 assembly (clang, -O0):
<L>:
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   $0x1,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <BN_dup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x1,%esi
call   1030 <BN_sub_word@plt>
cmp    $0x0,%eax
jne    11c8 <L+0x48>
jmp    11f6 <L+0x76>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <BN_div@plt>
cmp    $0x0,%eax
jne    11ef <L+0x6f>
jmp    11f6 <L+0x76>
movl   $0x0,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1237 <L+0xb7>
mov    $0x0,%al
call   1090 <ERR_load_crypto_strings@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1080 <ERR_get_error@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <ERR_error_string@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xdce(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <BN_free@plt>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<L>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rdi,%r12
mov    %rsi,%rdi
call   1040 <BN_dup@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    $0x1,%esi
call   1030 <BN_sub_word@plt>
test   %eax,%eax
je     11c7 <L+0x47>
xor    %ebx,%ebx
mov    %r12,%rdi
xor    %esi,%esi
mov    %r13,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   10a0 <BN_div@plt>
test   %eax,%eax
jne    11fd <L+0x7d>
xor    %eax,%eax
call   1090 <ERR_load_crypto_strings@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1080 <ERR_get_error@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1070 <ERR_error_string@plt>
lea    0xe12(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%ebx
mov    %r13,%rdi
call   1050 <BN_free@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"Error calculating L: %s\00"
define i32 @L(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*
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i32 1, i32* %9
%11 = load i32*, i32** %6
%12 = call i32* @BN_dup(i32* %11)
store i32* %12, i32** %10
%13 = load i32*, i32** %10
%14 = call i32 @BN_sub_word(i32* %13, i32 1)
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %4
br label %26
17: ; preds = %4
%18 = load i32*, i32** %5
%19 = load i32*, i32** %10
%20 = load i32*, i32** %7
%21 = load i32*, i32** %8
%22 = call i32 @BN_div(i32* %18, i32* null, i32* %19, i32* %20, i32* %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %17
br label %26
25: ; preds = %17
store i32 0, i32* %9
br label %26
26: ; preds = %25, %24, %16
%27 = load i32, i32* %9
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = call i32 (...) @ERR_load_crypto_strings()
%31 = load i32, i32* @stderr
%32 = call i32 (...) @ERR_get_error()
%33 = call i8* @ERR_error_string(i32 %32, i32* null)
%34 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %29, %26
%36 = load i32*, i32** %10
%37 = call i32 @BN_free(i32* %36)
%38 = load i32, i32* %9
ret i32 %38
}

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