#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_mpi2bn(unsigned char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, size_t);
scalar_t__ reverse(unsigned char *, size_t);
int make_big_endian_set(BIGNUM *num, unsigned char *buff, size_t buff_len) {
  size_t data_size = buff_len + 4;
  unsigned char *temp = (unsigned char *)malloc(data_size);
  if (temp == NULL)
    return 0;
  temp[0] = (buff_len >> 24) & 0xff;
  temp[1] = (buff_len >> 16) & 0xff;
  temp[2] = (buff_len >> 8) & 0xff;
  temp[3] = (buff_len >> 0) & 0xff;
  memcpy((temp + 4), buff, buff_len);
  if (reverse((temp + 4), buff_len) == 0) {
    free(temp);
    return 0;
  }
  BN_mpi2bn(&temp[0], (int)data_size, num);
  free(temp);
  return 1;
}


x86 assembly (clang, -O0):
<make_big_endian_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1194 <make_big_endian_set+0x44>
movl   $0x0,-0x4(%rbp)
jmp    1257 <make_big_endian_set+0x107>
mov    -0x20(%rbp),%rax
shr    $0x18,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
shr    $0x10,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x20(%rbp),%rax
shr    $0x8,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x20(%rbp),%rax
shr    $0x0,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x30(%rbp),%rdi
add    $0x4,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x30(%rbp),%rdi
add    $0x4,%rdi
mov    -0x20(%rbp),%rsi
call   1030 <reverse@plt>
cmp    $0x0,%rax
jne    1234 <make_big_endian_set+0xe4>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1257 <make_big_endian_set+0x107>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
call   1050 <BN_mpi2bn@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_big_endian_set>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r13
mov    %rdi,%r14
lea    0x4(%rdx),%r15
mov    %r15,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     11ba <make_big_endian_set+0x6a>
mov    %rax,%r12
mov    %ebx,%eax
bswap  %eax
mov    %eax,(%r12)
mov    %r12,%rbp
add    $0x4,%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1060 <memcpy@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <reverse@plt>
test   %rax,%rax
je     11be <make_big_endian_set+0x6e>
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
call   1050 <BN_mpi2bn@plt>
mov    $0x1,%ebx
jmp    11c0 <make_big_endian_set+0x70>
xor    %ebx,%ebx
jmp    11c8 <make_big_endian_set+0x78>
xor    %ebx,%ebx
mov    %r12,%rdi
call   1040 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @make_big_endian_set(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%10 = load i64, i64* %7
%11 = add i64 %10, 4
store i64 %11, i64* %8
%12 = load i64, i64* %8
%13 = call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %9
%15 = load i8*, i8** %9
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %3
store i32 0, i32* %4
br label %65
18: ; preds = %3
%19 = load i64, i64* %7
%20 = lshr i64 %19, 24
%21 = and i64 %20, 255
%22 = trunc i64 %21 to i8
%23 = load i8*, i8** %9
%24 = getelementptr inbounds i8, i8* %23, i64 0
store i8 %22, i8* %24
%25 = load i64, i64* %7
%26 = lshr i64 %25, 16
%27 = and i64 %26, 255
%28 = trunc i64 %27 to i8
%29 = load i8*, i8** %9
%30 = getelementptr inbounds i8, i8* %29, i64 1
store i8 %28, i8* %30
%31 = load i64, i64* %7
%32 = lshr i64 %31, 8
%33 = and i64 %32, 255
%34 = trunc i64 %33 to i8
%35 = load i8*, i8** %9
%36 = getelementptr inbounds i8, i8* %35, i64 2
store i8 %34, i8* %36
%37 = load i64, i64* %7
%38 = lshr i64 %37, 0
%39 = and i64 %38, 255
%40 = trunc i64 %39 to i8
%41 = load i8*, i8** %9
%42 = getelementptr inbounds i8, i8* %41, i64 3
store i8 %40, i8* %42
%43 = load i8*, i8** %9
%44 = getelementptr inbounds i8, i8* %43, i64 4
%45 = load i8*, i8** %6
%46 = load i64, i64* %7
%47 = call i32 @memcpy(i8* %44, i8* %45, i64 %46)
%48 = load i8*, i8** %9
%49 = getelementptr inbounds i8, i8* %48, i64 4
%50 = load i64, i64* %7
%51 = call i64 @reverse(i8* %49, i64 %50)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %18
%54 = load i8*, i8** %9
%55 = call i32 @free(i8* %54)
store i32 0, i32* %4
br label %65
56: ; preds = %18
%57 = load i8*, i8** %9
%58 = getelementptr inbounds i8, i8* %57, i64 0
%59 = load i64, i64* %8
%60 = trunc i64 %59 to i32
%61 = load i32*, i32** %5
%62 = call i32 @BN_mpi2bn(i8* %58, i32 %60, i32* %61)
%63 = load i8*, i8** %9
%64 = call i32 @free(i8* %63)
store i32 1, i32* %4
br label %65
65: ; preds = %56, %53, %17
%66 = load i32, i32* %4
ret i32 %66
}

LLVM IR (-O2):
define i32 @make_big_endian_set(i32* %0, i8* %1, i64 %2) {
%4 = add i64 %2, 4
%5 = tail call i64 @malloc(i64 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %29, label %8
8: ; preds = %3
%9 = lshr i64 %2, 24
%10 = trunc i64 %9 to i8
store i8 %10, i8* %6
%11 = lshr i64 %2, 16
%12 = trunc i64 %11 to i8
%13 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %12, i8* %13
%14 = lshr i64 %2, 8
%15 = trunc i64 %14 to i8
%16 = getelementptr inbounds i8, i8* %6, i64 2
store i8 %15, i8* %16
%17 = trunc i64 %2 to i8
%18 = getelementptr inbounds i8, i8* %6, i64 3
store i8 %17, i8* %18
%19 = getelementptr inbounds i8, i8* %6, i64 4
%20 = tail call i32 @memcpy(i8* %19, i8* %1, i64 %2)
%21 = tail call i64 @reverse(i8* %19, i64 %2)
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %8
%24 = trunc i64 %4 to i32
%25 = tail call i32 @BN_mpi2bn(i8* %6, i32 %24, i32* %0)
br label %26
26: ; preds = %8, %23
%27 = phi i32 [ 1, %23 ], [ 0, %8 ]
%28 = tail call i32 @free(i8* %6)
br label %29
29: ; preds = %26, %3
%30 = phi i32 [ 0, %3 ], [ %27, %26 ]
ret i32 %30
}