#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 ssize_t;
typedef int /*<<< orphan*/ BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ BN_bin2bn(unsigned char *, unsigned char,
                             int /*<<< orphan*/ *);
scalar_t__ alloca(unsigned char);
int /*<<< orphan*/ bzero(unsigned char *, unsigned char);
int recv(int, void *, unsigned char, int /*<<< orphan*/);
int recv_bn(int socket, BIGNUM *y) {
  unsigned char size = 0;
  int ret = 0;
  ssize_t rc = recv(socket, &size, 1, 0);
  if (rc != 1 || size == 0)
    return 0;
  unsigned char *tmp = (unsigned char *)alloca(size);
  ssize_t red = 0;
  do {
    rc = recv(socket, (void *)(tmp + red), size - red, 0);
    if (rc < 0)
      goto err;
    red += rc;
  } while (red < size);
  if (!BN_bin2bn(tmp, size, y))
    goto err;
  ret = 1;
err:
  bzero(tmp, size + 1);
  return ret;
}


x86 assembly (clang, -O0):
<recv_bn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    1187 <recv_bn+0x47>
movzbl -0x11(%rbp),%eax
cmp    $0x0,%eax
jne    1193 <recv_bn+0x53>
movl   $0x0,-0x4(%rbp)
jmp    1231 <recv_bn+0xf1>
movzbl -0x11(%rbp),%edi
call   1050 <alloca@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
movslq -0x2c(%rbp),%rax
add    %rax,%rsi
movzbl -0x11(%rbp),%eax
sub    -0x2c(%rbp),%eax
xor    %ecx,%ecx
movzbl %al,%edx
call   1030 <recv@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11d8 <recv_bn+0x98>
jmp    1218 <recv_bn+0xd8>
mov    -0x1c(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
movzbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jl     11a7 <recv_bn+0x67>
mov    -0x28(%rbp),%rdi
mov    -0x11(%rbp),%al
mov    -0x10(%rbp),%rdx
movzbl %al,%esi
call   1040 <BN_bin2bn@plt>
cmp    $0x0,%eax
jne    1211 <recv_bn+0xd1>
jmp    1218 <recv_bn+0xd8>
movl   $0x1,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
movzbl -0x11(%rbp),%eax
add    $0x1,%eax
movzbl %al,%esi
call   1060 <bzero@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_bn>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
movb   $0x0,0xf(%rsp)
lea    0xf(%rsp),%rsi
xor    %r15d,%r15d
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x1,%eax
jne    11dc <recv_bn+0x9c>
mov    0xf(%rsp),%al
test   %al,%al
je     11dc <recv_bn+0x9c>
movzbl %al,%edi
call   1050 <alloca@plt>
mov    %rax,%r12
xor    %r15d,%r15d
mov    0xf(%rsp),%al
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movslq %ebx,%rcx
lea    (%r12,%rcx,1),%rsi
sub    %cl,%al
movzbl %al,%edx
mov    %ebp,%edi
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     11cb <recv_bn+0x8b>
add    %eax,%ebx
movzbl 0xf(%rsp),%eax
cmp    %eax,%ebx
jl     1190 <recv_bn+0x50>
movzbl %al,%esi
mov    %r12,%rdi
mov    %r14,%rdx
call   1040 <BN_bin2bn@plt>
xor    %r15d,%r15d
test   %eax,%eax
setne  %r15b
mov    0xf(%rsp),%al
add    $0x1,%al
movzbl %al,%esi
mov    %r12,%rdi
call   1060 <bzero@plt>
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @recv_bn(i32 %0, i32* %1) {
%3 = alloca i8
store i8 0, i8* %3
%4 = call i32 @recv(i32 %0, i8* %3, i8 zeroext 1, i32 0)
%5 = icmp ne i32 %4, 1
%6 = load i8, i8* %3
%7 = icmp eq i8 %6, 0
%8 = select i1 %5, i1 true, i1 %7
br i1 %8, label %36, label %9
9: ; preds = %2
%10 = call i64 @alloca(i8 zeroext %6)
%11 = inttoptr i64 %10 to i8*
%12 = load i8, i8* %3
br label %13
13: ; preds = %22, %9
%14 = phi i8 [ %12, %9 ], [ %24, %22 ]
%15 = phi i32 [ 0, %9 ], [ %23, %22 ]
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %11, i64 %16
%18 = trunc i32 %15 to i8
%19 = sub i8 %14, %18
%20 = call i32 @recv(i32 %0, i8* %17, i8 zeroext %19, i32 0)
%21 = icmp slt i32 %20, 0
br i1 %21, label %31, label %22
22: ; preds = %13
%23 = add nsw i32 %20, %15
%24 = load i8, i8* %3
%25 = zext i8 %24 to i32
%26 = icmp slt i32 %23, %25
br i1 %26, label %13, label %27
27: ; preds = %22
%28 = call i32 @BN_bin2bn(i8* %11, i8 zeroext %24, i32* %1)
%29 = icmp ne i32 %28, 0
%30 = zext i1 %29 to i32
br label %31
31: ; preds = %13, %27
%32 = phi i32 [ %30, %27 ], [ 0, %13 ]
%33 = load i8, i8* %3
%34 = add i8 %33, 1
%35 = call i32 @bzero(i8* %11, i8 zeroext %34)
br label %36
36: ; preds = %2, %31
%37 = phi i32 [ %32, %31 ], [ 0, %2 ]
ret i32 %37
}