#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 long time_t;
typedef int /*<<< orphan*/ SSL_SESSION;

/* Variables and functions */
long LONG_MAX;
long SSL_SESSION_get_time(int /*<<< orphan*/ *);
long SSL_SESSION_get_timeout(int /*<<< orphan*/ *);
long time(int /*<<< orphan*/ *);
int ssl_session_is_valid(SSL_SESSION *sess) {
  time_t curtimet;
  long curtime, timeout;
  curtimet = time(NULL);
  if (curtimet == (time_t)-1)
    return 0;
  curtime = curtimet;
  if ((curtime < 0) || ((time_t)curtime != curtimet))
    return 0;
  timeout = SSL_SESSION_get_timeout(sess);
  if (curtime > LONG_MAX - timeout)
    return 0;
  return (SSL_SESSION_get_time(sess) < curtime + timeout);
}


x86 assembly (clang, -O0):
<ssl_session_is_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    1160 <ssl_session_is_valid+0x30>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <ssl_session_is_valid+0xb0>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jl     1181 <ssl_session_is_valid+0x51>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     118d <ssl_session_is_valid+0x5d>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <ssl_session_is_valid+0xb0>
mov    -0x10(%rbp),%rdi
call   1030 <SSL_SESSION_get_timeout@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2e3b(%rip),%rcx
mov    (%rcx),%rcx
sub    -0x28(%rbp),%rcx
cmp    %rcx,%rax
jle    11c1 <ssl_session_is_valid+0x91>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <ssl_session_is_valid+0xb0>
mov    -0x10(%rbp),%rdi
call   1050 <SSL_SESSION_get_time@plt>
mov    -0x20(%rbp),%rcx
add    -0x28(%rbp),%rcx
cmp    %rcx,%rax
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_session_is_valid>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %r15d,%r15d
xor    %edi,%edi
call   1040 <time@plt>
test   %rax,%rax
js     117f <ssl_session_is_valid+0x4f>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <SSL_SESSION_get_timeout@plt>
mov    %rax,%r12
mov    0x2e81(%rip),%rax
mov    (%rax),%rax
sub    %r12,%rax
cmp    %rax,%rbx
jg     117f <ssl_session_is_valid+0x4f>
mov    %r14,%rdi
call   1050 <SSL_SESSION_get_time@plt>
add    %rbx,%r12
xor    %r15d,%r15d
cmp    %r12,%rax
setl   %r15b
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@LONG_MAX = global i64 0
define i32 @ssl_session_is_valid(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i32* %0, i32** %3
%7 = call i64 @time(i32* null)
store i64 %7, i64* %4
%8 = load i64, i64* %4
%9 = icmp eq i64 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %37
11: ; preds = %1
%12 = load i64, i64* %4
store i64 %12, i64* %5
%13 = load i64, i64* %5
%14 = icmp slt i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = load i64, i64* %5
%17 = load i64, i64* %4
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %15, %11
store i32 0, i32* %2
br label %37
20: ; preds = %15
%21 = load i32*, i32** %3
%22 = call i64 @SSL_SESSION_get_timeout(i32* %21)
store i64 %22, i64* %6
%23 = load i64, i64* %5
%24 = load i64, i64* @LONG_MAX
%25 = load i64, i64* %6
%26 = sub nsw i64 %24, %25
%27 = icmp sgt i64 %23, %26
br i1 %27, label %28, label %29
28: ; preds = %20
store i32 0, i32* %2
br label %37
29: ; preds = %20
%30 = load i32*, i32** %3
%31 = call i64 @SSL_SESSION_get_time(i32* %30)
%32 = load i64, i64* %5
%33 = load i64, i64* %6
%34 = add nsw i64 %32, %33
%35 = icmp slt i64 %31, %34
%36 = zext i1 %35 to i32
store i32 %36, i32* %2
br label %37
37: ; preds = %29, %28, %19, %10
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
@LONG_MAX = global i64 0
define i32 @ssl_session_is_valid(i32* %0) {
%2 = tail call i64 @time(i32* null)
%3 = icmp slt i64 %2, 0
br i1 %3, label %14, label %4
4: ; preds = %1
%5 = tail call i64 @SSL_SESSION_get_timeout(i32* %0)
%6 = load i64, i64* @LONG_MAX
%7 = sub nsw i64 %6, %5
%8 = icmp sgt i64 %2, %7
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = tail call i64 @SSL_SESSION_get_time(i32* %0)
%11 = add nsw i64 %5, %2
%12 = icmp slt i64 %10, %11
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %4, %1, %9
%15 = phi i32 [ %13, %9 ], [ 0, %1 ], [ 0, %4 ]
ret i32 %15
}