#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*/ BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ BN_uadd(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                           int /*<<< orphan*/ const *);
scalar_t__ BN_ucmp(int /*<<< orphan*/ *, int /*<<< orphan*/ const *);
int BN_usub(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
            int /*<<< orphan*/ const *);
int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
                     const BIGNUM *m) {
  if (!BN_uadd(r, a, b))
    return 0;
  if (BN_ucmp(r, m) >= 0)
    return BN_usub(r, r, m);
  return 1;
}


x86 assembly (clang, -O0):
<BN_mod_add_quick>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <BN_uadd@plt>
cmp    $0x0,%eax
jne    116e <BN_mod_add_quick+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    11a5 <BN_mod_add_quick+0x75>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <BN_ucmp@plt>
cmp    $0x0,%rax
jl     119e <BN_mod_add_quick+0x6e>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <BN_usub@plt>
mov    %eax,-0x4(%rbp)
jmp    11a5 <BN_mod_add_quick+0x75>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BN_mod_add_quick>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdi,%rbx
call   1030 <BN_uadd@plt>
test   %eax,%eax
je     1168 <BN_mod_add_quick+0x38>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <BN_ucmp@plt>
test   %rax,%rax
js     116c <BN_mod_add_quick+0x3c>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <BN_usub@plt>
xor    %eax,%eax
jmp    1171 <BN_mod_add_quick+0x41>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @BN_mod_add_quick(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%10 = load i32*, i32** %6
%11 = load i32*, i32** %7
%12 = load i32*, i32** %8
%13 = call i32 @BN_uadd(i32* %10, i32* %11, i32* %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %4
store i32 0, i32* %5
br label %27
16: ; preds = %4
%17 = load i32*, i32** %6
%18 = load i32*, i32** %9
%19 = call i64 @BN_ucmp(i32* %17, i32* %18)
%20 = icmp sge i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i32*, i32** %6
%23 = load i32*, i32** %6
%24 = load i32*, i32** %9
%25 = call i32 @BN_usub(i32* %22, i32* %23, i32* %24)
store i32 %25, i32* %5
br label %27
26: ; preds = %16
store i32 1, i32* %5
br label %27
27: ; preds = %26, %21, %15
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
define i32 @BN_mod_add_quick(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = tail call i32 @BN_uadd(i32* %0, i32* %1, i32* %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = tail call i64 @BN_ucmp(i32* %0, i32* %3)
%9 = icmp sgt i64 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @BN_usub(i32* %0, i32* %0, i32* %3)
br label %12
12: ; preds = %7, %4, %10
%13 = phi i32 [ %11, %10 ], [ 0, %4 ], [ 1, %7 ]
ret i32 %13
}