#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 scalar_t__ uint16_t;
typedef int /*<<< orphan*/ SSL;

/* Variables and functions */
int /*<<< orphan*/ tls1_get_group_list(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                       scalar_t__ const **, size_t *);
int tls1_check_curve(SSL *s, const uint16_t curve_id) {
  const uint16_t *groups;
  size_t groupslen, i;
  tls1_get_group_list(s, 0, &groups, &groupslen);
  for (i = 0; i < groupslen; i++) {
    if (groups[i] == curve_id)
      return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<tls1_check_curve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1030 <tls1_get_group_list@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1181 <tls1_check_curve+0x71>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
cmp    -0x18(%rbp),%rax
jne    116b <tls1_check_curve+0x5b>
movl   $0x1,-0x4(%rbp)
jmp    1188 <tls1_check_curve+0x78>
jmp    1170 <tls1_check_curve+0x60>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    113b <tls1_check_curve+0x2b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tls1_check_curve>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
xor    %ebp,%ebp
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
xor    %esi,%esi
call   1030 <tls1_get_group_list@plt>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     1158 <tls1_check_curve+0x48>
mov    0x10(%rsp),%rcx
xor    %edx,%edx
nopl   (%rax)
cmp    %rbx,(%rcx,%rdx,8)
je     1153 <tls1_check_curve+0x43>
add    $0x1,%rdx
cmp    %rdx,%rax
jne    1140 <tls1_check_curve+0x30>
xor    %ebp,%ebp
jmp    1158 <tls1_check_curve+0x48>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @tls1_check_curve(i32* %0, i64 %1) {
%3 = alloca i64*
%4 = alloca i64
%5 = bitcast i64** %3 to i8*
%6 = bitcast i64* %4 to i8*
%7 = call i32 @tls1_get_group_list(i32* %0, i32 0, i64** %3, i64* %4)
%8 = load i64, i64* %4
%9 = icmp eq i64 %8, 0
br i1 %9, label %20, label %10
10: ; preds = %2
%11 = load i64*, i64** %3
br label %14
12: ; preds = %14
%13 = icmp eq i64 %19, %8
br i1 %13, label %20, label %14
14: ; preds = %10, %12
%15 = phi i64 [ 0, %10 ], [ %19, %12 ]
%16 = getelementptr inbounds i64, i64* %11, i64 %15
%17 = load i64, i64* %16
%18 = icmp eq i64 %17, %1
%19 = add nuw i64 %15, 1
br i1 %18, label %20, label %12
20: ; preds = %14, %12, %2
%21 = phi i32 [ 0, %2 ], [ 0, %12 ], [ 1, %14 ]
ret i32 %21
}