#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*/ EC_POINT;
typedef int /*<<< orphan*/ EC_GROUP;
typedef int /*<<< orphan*/ BN_CTX;

/* Variables and functions */
int /*<<< orphan*/ BN_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_CTX_new();
int EC_POINT_oct2point(int /*<<< orphan*/ const *, int /*<<< orphan*/ *,
                       unsigned char *, size_t, int /*<<< orphan*/ *);
char POINT_CONVERSION_UNCOMPRESSED;
int /*<<< orphan*/ _explicit_bzero(char *, size_t);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ read_str(char **, size_t *, char **, size_t *);
int read_point(char **str, size_t *str_len, const EC_GROUP *curve,
               EC_POINT *point) {
  BN_CTX *bnctx = NULL;
  int res = 0;
  char *buf;
  size_t buf_len;
  if (!read_str(str, str_len, &buf, &buf_len))
    goto rp_cleanup;
  if (!buf_len)
    goto rp_cleanup;
  if (buf[0] != POINT_CONVERSION_UNCOMPRESSED)
    goto rp_cleanup;
  if ((bnctx = BN_CTX_new()) == NULL)
    goto rp_cleanup;
  if (EC_POINT_oct2point(curve, point, (unsigned char *)buf, buf_len, bnctx) !=
      1)
    goto rp_cleanup;
  res = 1;
rp_cleanup:
  if (buf) {
    _explicit_bzero(buf, buf_len);
    free(buf);
  }
  if (bnctx)
    BN_CTX_free(bnctx);
  return res;
}


x86 assembly (clang, -O0):
<read_point>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1080 <read_str@plt>
cmp    $0x0,%eax
jne    11aa <read_point+0x4a>
jmp    1220 <read_point+0xc0>
cmpq   $0x0,-0x40(%rbp)
jne    11ba <read_point+0x5a>
jmp    1220 <read_point+0xc0>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
mov    0x2e18(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11d8 <read_point+0x78>
jmp    1220 <read_point+0xc0>
mov    $0x0,%al
call   1070 <BN_CTX_new@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11f2 <read_point+0x92>
jmp    1220 <read_point+0xc0>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1050 <EC_POINT_oct2point@plt>
cmp    $0x1,%eax
je     1219 <read_point+0xb9>
jmp    1220 <read_point+0xc0>
movl   $0x1,-0x2c(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1241 <read_point+0xe1>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1040 <_explicit_bzero@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x28(%rbp)
je     1255 <read_point+0xf5>
mov    -0x28(%rbp),%rdi
call   1060 <BN_CTX_free@plt>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_point>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r15
mov    %rdx,%r12
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1080 <read_str@plt>
xor    %r14d,%r14d
mov    $0x0,%ebx
test   %eax,%eax
je     11e7 <read_point+0x87>
mov    0x10(%rsp),%rsi
test   %rsi,%rsi
je     11e7 <read_point+0x87>
mov    0x8(%rsp),%rdi
mov    (%rdi),%al
mov    0x2e3c(%rip),%rcx
cmp    (%rcx),%al
jne    11de <read_point+0x7e>
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <BN_CTX_new@plt>
test   %rax,%rax
je     11e5 <read_point+0x85>
mov    %rax,%rbx
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rcx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rax,%r8
call   1050 <EC_POINT_oct2point@plt>
xor    %r14d,%r14d
cmp    $0x1,%eax
sete   %r14b
jmp    11e7 <read_point+0x87>
xor    %r14d,%r14d
xor    %ebx,%ebx
jmp    11f6 <read_point+0x96>
xor    %ebx,%ebx
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1205 <read_point+0xa5>
mov    0x10(%rsp),%rsi
call   1040 <_explicit_bzero@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
test   %rbx,%rbx
je     1212 <read_point+0xb2>
mov    %rbx,%rdi
call   1060 <BN_CTX_free@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@POINT_CONVERSION_UNCOMPRESSED = global i8 0
define i32 @read_point(i8** %0, i64* %1, i32* %2, i32* %3) {
%5 = alloca i8**
%6 = alloca i64*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
store i8** %0, i8*** %5
store i64* %1, i64** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i32* null, i32** %9
store i32 0, i32* %10
%13 = load i8**, i8*** %5
%14 = load i64*, i64** %6
%15 = call i32 @read_str(i8** %13, i64* %14, i8** %11, i64* %12)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %4
br label %45
18: ; preds = %4
%19 = load i64, i64* %12
%20 = icmp ne i64 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %18
br label %45
22: ; preds = %18
%23 = load i8*, i8** %11
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = load i8, i8* @POINT_CONVERSION_UNCOMPRESSED
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %26, %28
br i1 %29, label %30, label %31
30: ; preds = %22
br label %45
31: ; preds = %22
%32 = call i32* (...) @BN_CTX_new()
store i32* %32, i32** %9
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %35
34: ; preds = %31
br label %45
35: ; preds = %31
%36 = load i32*, i32** %7
%37 = load i32*, i32** %8
%38 = load i8*, i8** %11
%39 = load i64, i64* %12
%40 = load i32*, i32** %9
%41 = call i32 @EC_POINT_oct2point(i32* %36, i32* %37, i8* %38, i64 %39, i32* %40)
%42 = icmp ne i32 %41, 1
br i1 %42, label %43, label %44
43: ; preds = %35
br label %45
44: ; preds = %35
store i32 1, i32* %10
br label %45
45: ; preds = %44, %43, %34, %30, %21, %17
%46 = load i8*, i8** %11
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %54
48: ; preds = %45
%49 = load i8*, i8** %11
%50 = load i64, i64* %12
%51 = call i32 @_explicit_bzero(i8* %49, i64 %50)
%52 = load i8*, i8** %11
%53 = call i32 @free(i8* %52)
br label %54
54: ; preds = %48, %45
%55 = load i32*, i32** %9
%56 = icmp ne i32* %55, null
br i1 %56, label %57, label %60
57: ; preds = %54
%58 = load i32*, i32** %9
%59 = call i32 @BN_CTX_free(i32* %58)
br label %60
60: ; preds = %57, %54
%61 = load i32, i32* %10
ret i32 %61
}

LLVM IR (-O2):
@POINT_CONVERSION_UNCOMPRESSED = global i8 0
define i32 @read_point(i8** %0, i64* %1, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = bitcast i8** %5 to i8*
%8 = bitcast i64* %6 to i8*
%9 = call i32 @read_str(i8** %0, i64* %1, i8** %5, i64* %6)
%10 = icmp ne i32 %9, 0
%11 = load i64, i64* %6
%12 = icmp ne i64 %11, 0
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %14, label %28
14: ; preds = %4
%15 = load i8*, i8** %5
%16 = load i8, i8* %15
%17 = load i8, i8* @POINT_CONVERSION_UNCOMPRESSED
%18 = icmp eq i8 %16, %17
br i1 %18, label %19, label %35
19: ; preds = %14
%20 = call i32* (...) @BN_CTX_new()
%21 = icmp eq i32* %20, null
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = load i8*, i8** %5
%24 = load i64, i64* %6
%25 = call i32 @EC_POINT_oct2point(i32* %2, i32* %3, i8* %23, i64 %24, i32* %20)
%26 = icmp eq i32 %25, 1
%27 = zext i1 %26 to i32
br label %28
28: ; preds = %22, %19, %4
%29 = phi i32* [ %20, %22 ], [ null, %4 ], [ null, %19 ]
%30 = phi i32 [ %27, %22 ], [ 0, %4 ], [ 0, %19 ]
%31 = load i8*, i8** %5
%32 = icmp eq i8* %31, null
br i1 %32, label %43, label %33
33: ; preds = %28
%34 = load i64, i64* %6
br label %35
35: ; preds = %33, %14
%36 = phi i64 [ %34, %33 ], [ %11, %14 ]
%37 = phi i32 [ %30, %33 ], [ 0, %14 ]
%38 = phi i32* [ %29, %33 ], [ null, %14 ]
%39 = phi i8* [ %31, %33 ], [ %15, %14 ]
%40 = call i32 @_explicit_bzero(i8* %39, i64 %36)
%41 = load i8*, i8** %5
%42 = call i32 @free(i8* %41)
br label %43
43: ; preds = %35, %28
%44 = phi i32 [ %37, %35 ], [ %30, %28 ]
%45 = phi i32* [ %38, %35 ], [ %29, %28 ]
%46 = icmp eq i32* %45, null
br i1 %46, label %49, label %47
47: ; preds = %43
%48 = call i32 @BN_CTX_free(i32* %45)
br label %49
49: ; preds = %47, %43
ret i32 %44
}