#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*/ SSL;

/* Variables and functions */
int /*<<< orphan*/ BIO_FLAGS_READ;
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ SSL_get_rbio(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_in_init(int /*<<< orphan*/ *);
int dtls1_handle_timeout(int /*<<< orphan*/ *);
int /*<<< orphan*/ dtls1_is_timer_expired(int /*<<< orphan*/ *);
int dtls1_read_failed(SSL *s, int code) {
  if (code > 0) {
    return 1;
  }
  if (!dtls1_is_timer_expired(s)) {
    return code;
  }
  if (!SSL_in_init(s)) {
    BIO_set_flags(SSL_get_rbio(s), BIO_FLAGS_READ);
    return code;
  }
  return dtls1_handle_timeout(s);
}


x86 assembly (clang, -O0):
<dtls1_read_failed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1175 <dtls1_read_failed+0x25>
movl   $0x1,-0x4(%rbp)
jmp    11d4 <dtls1_read_failed+0x84>
mov    -0x10(%rbp),%rdi
call   1030 <dtls1_is_timer_expired@plt>
cmp    $0x0,%eax
jne    1192 <dtls1_read_failed+0x42>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <dtls1_read_failed+0x84>
mov    -0x10(%rbp),%rdi
call   1070 <SSL_in_init@plt>
cmp    $0x0,%eax
jne    11c8 <dtls1_read_failed+0x78>
mov    -0x10(%rbp),%rdi
call   1060 <SSL_get_rbio@plt>
mov    %eax,%edi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
call   1050 <BIO_set_flags@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <dtls1_read_failed+0x84>
mov    -0x10(%rbp),%rdi
call   1040 <dtls1_handle_timeout@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dtls1_read_failed>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1,%eax
test   %esi,%esi
jg     119b <dtls1_read_failed+0x4b>
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <dtls1_is_timer_expired@plt>
test   %eax,%eax
je     1199 <dtls1_read_failed+0x49>
mov    %rbx,%rdi
call   1070 <SSL_in_init@plt>
mov    %rbx,%rdi
test   %eax,%eax
je     1184 <dtls1_read_failed+0x34>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <dtls1_handle_timeout@plt>
call   1060 <SSL_get_rbio@plt>
mov    0x2e48(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1050 <BIO_set_flags@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@BIO_FLAGS_READ = global i32 0
define i32 @dtls1_read_failed(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %2
store i32 1, i32* %3
br label %28
9: ; preds = %2
%10 = load i32*, i32** %4
%11 = call i32 @dtls1_is_timer_expired(i32* %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = load i32, i32* %5
store i32 %14, i32* %3
br label %28
15: ; preds = %9
%16 = load i32*, i32** %4
%17 = call i32 @SSL_in_init(i32* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %15
%20 = load i32*, i32** %4
%21 = call i32 @SSL_get_rbio(i32* %20)
%22 = load i32, i32* @BIO_FLAGS_READ
%23 = call i32 @BIO_set_flags(i32 %21, i32 %22)
%24 = load i32, i32* %5
store i32 %24, i32* %3
br label %28
25: ; preds = %15
%26 = load i32*, i32** %4
%27 = call i32 @dtls1_handle_timeout(i32* %26)
store i32 %27, i32* %3
br label %28
28: ; preds = %25, %19, %13, %8
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@BIO_FLAGS_READ = global i32 0
define i32 @dtls1_read_failed(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %16, label %4
4: ; preds = %2
%5 = tail call i32 @dtls1_is_timer_expired(i32* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %16, label %7
7: ; preds = %4
%8 = tail call i32 @SSL_in_init(i32* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = tail call i32 @SSL_get_rbio(i32* %0)
%12 = load i32, i32* @BIO_FLAGS_READ
%13 = tail call i32 @BIO_set_flags(i32 %11, i32 %12)
br label %16
14: ; preds = %7
%15 = tail call i32 @dtls1_handle_timeout(i32* %0)
br label %16
16: ; preds = %4, %2, %14, %10
%17 = phi i32 [ %15, %14 ], [ %1, %10 ], [ 1, %2 ], [ %1, %4 ]
ret i32 %17
}