#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_bin2bn(unsigned char const *, size_t,
                              int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_new();
int /*<<< orphan*/ BN_zero(int /*<<< orphan*/ *);
BIGNUM *getbnfrombuf(const unsigned char *buf, size_t len) {
  while (*buf == 0 && len > 0) {
    buf++;
    len--;
  }
  if (len) {
    return BN_bin2bn(buf, len, NULL);
  } else {
    BIGNUM *b = BN_new();
    BN_zero(b);
    return b;
  }
}


x86 assembly (clang, -O0):
<getbnfrombuf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
jne    1160 <getbnfrombuf+0x30>
cmpq   $0x0,-0x18(%rbp)
seta   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1170 <getbnfrombuf+0x40>
jmp    118d <getbnfrombuf+0x5d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1140 <getbnfrombuf+0x10>
cmpq   $0x0,-0x18(%rbp)
je     11b2 <getbnfrombuf+0x82>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <BN_bin2bn@plt>
mov    %rax,-0x8(%rbp)
jmp    11ce <getbnfrombuf+0x9e>
mov    $0x0,%al
call   1030 <BN_new@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <BN_zero@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getbnfrombuf>:
push   %rbx
cmpb   $0x0,(%rdi)
jne    1159 <getbnfrombuf+0x29>
test   %rsi,%rsi
je     116c <getbnfrombuf+0x3c>
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,0x1(%rdi)
lea    0x1(%rdi),%rdi
lea    -0x1(%rsi),%rax
jne    115c <getbnfrombuf+0x2c>
cmp    $0x1,%rsi
mov    %rax,%rsi
jne    1140 <getbnfrombuf+0x10>
jmp    115c <getbnfrombuf+0x2c>
mov    %rsi,%rax
test   %rax,%rax
je     1174 <getbnfrombuf+0x44>
mov    %rax,%rsi
xor    %edx,%edx
pop    %rbx
jmp    1040 <BN_bin2bn@plt>
mov    %rsi,%rax
test   %rax,%rax
jne    1161 <getbnfrombuf+0x31>
xor    %eax,%eax
call   1030 <BN_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <BN_zero@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i32* @getbnfrombuf(i8* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32*
store i8* %0, i8** %4
store i64 %1, i64* %5
br label %7
7: ; preds = %17, %2
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i64, i64* %5
%14 = icmp ugt i64 %13, 0
br label %15
15: ; preds = %12, %7
%16 = phi i1 [ false, %7 ], [ %14, %12 ]
br i1 %16, label %17, label %22
17: ; preds = %15
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %4
%20 = load i64, i64* %5
%21 = add i64 %20, -1
store i64 %21, i64* %5
br label %7
22: ; preds = %15
%23 = load i64, i64* %5
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i8*, i8** %4
%27 = load i64, i64* %5
%28 = call i32* @BN_bin2bn(i8* %26, i64 %27, i32* null)
store i32* %28, i32** %3
br label %34
29: ; preds = %22
%30 = call i32* (...) @BN_new()
store i32* %30, i32** %6
%31 = load i32*, i32** %6
%32 = call i32 @BN_zero(i32* %31)
%33 = load i32*, i32** %6
store i32* %33, i32** %3
br label %34
34: ; preds = %29, %25
%35 = load i32*, i32** %3
ret i32* %35
}

LLVM IR (-O2):
define i32* @getbnfrombuf(i8* %0, i64 %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
%5 = icmp ne i64 %1, 0
%6 = and i1 %4, %5
br i1 %6, label %7, label %16
7: ; preds = %2, %7
%8 = phi i64 [ %11, %7 ], [ %1, %2 ]
%9 = phi i8* [ %10, %7 ], [ %0, %2 ]
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = add i64 %8, -1
%12 = load i8, i8* %10
%13 = icmp eq i8 %12, 0
%14 = icmp ne i64 %11, 0
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %7, label %16
16: ; preds = %7, %2
%17 = phi i8* [ %0, %2 ], [ %10, %7 ]
%18 = phi i64 [ %1, %2 ], [ %11, %7 ]
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = tail call i32* @BN_bin2bn(i8* %17, i64 %18, i32* null)
br label %25
22: ; preds = %16
%23 = tail call i32* (...) @BN_new()
%24 = tail call i32 @BN_zero(i32* %23)
br label %25
25: ; preds = %22, %20
%26 = phi i32* [ %21, %20 ], [ %23, %22 ]
ret i32* %26
}