#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__ time_t;

/* Variables and functions */
int /*<<< orphan*/ assert(scalar_t__ *);
double const difftime(scalar_t__, scalar_t__);
scalar_t__ time(int /*<<< orphan*/ *);
int pause_detect(int ntrans, time_t *p_pause) {
  time_t now = 0;
  const double MAX_PAUSE_SEC = 5.0;
  assert(p_pause);
  if (-2 == ntrans) {
    now = time(NULL);
    if (*p_pause) {
      if (difftime(now, *p_pause) > MAX_PAUSE_SEC) {
        ((void)0);
        return -1;
      }
    } else {
      *p_pause = now;
      ((void)0);
    }
  } else {
    if (*p_pause) {
      *p_pause = 0;
      ((void)0);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<pause_detect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movsd  0xeb1(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
mov    $0xfffffffe,%eax
cmp    -0x8(%rbp),%eax
jne    11c9 <pause_detect+0x99>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     11b9 <pause_detect+0x89>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1030 <difftime@plt>
movsd  0xe62(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11b4 <pause_detect+0x84>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <pause_detect+0xbe>
jmp    11c4 <pause_detect+0x94>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    11e7 <pause_detect+0xb7>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     11e2 <pause_detect+0xb2>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
jmp    11e7 <pause_detect+0xb7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pause_detect>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1040 <assert@plt>
cmp    $0xfffffffe,%ebp
jne    116d <pause_detect+0x3d>
xor    %edi,%edi
call   1050 <time@plt>
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1175 <pause_detect+0x45>
mov    %rax,%rdi
call   1030 <difftime@plt>
mov    $0xffffffff,%eax
ucomisd 0xe97(%rip),%xmm0
jbe    1178 <pause_detect+0x48>
jmp    117a <pause_detect+0x4a>
cmpq   $0x0,(%rbx)
je     1178 <pause_detect+0x48>
xor    %eax,%eax
mov    %rax,(%rbx)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pause_detect(i32 %0, i64* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64*
%6 = alloca i64
%7 = alloca double
store i32 %0, i32* %4
store i64* %1, i64** %5
store i64 0, i64* %6
store double 5.000000e+00, double* %7
%8 = load i64*, i64** %5
%9 = call i32 @assert(i64* %8)
%10 = load i32, i32* %4
%11 = icmp eq i32 -2, %10
br i1 %11, label %12, label %29
12: ; preds = %2
%13 = call i64 @time(i32* null)
store i64 %13, i64* %6
%14 = load i64*, i64** %5
%15 = load i64, i64* %14
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %12
%18 = load i64, i64* %6
%19 = load i64*, i64** %5
%20 = load i64, i64* %19
%21 = call double @difftime(i64 %18, i64 %20)
%22 = fcmp ogt double %21, 5.000000e+00
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 -1, i32* %3
br label %37
24: ; preds = %17
br label %28
25: ; preds = %12
%26 = load i64, i64* %6
%27 = load i64*, i64** %5
store i64 %26, i64* %27
br label %28
28: ; preds = %25, %24
br label %36
29: ; preds = %2
%30 = load i64*, i64** %5
%31 = load i64, i64* %30
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = load i64*, i64** %5
store i64 0, i64* %34
br label %35
35: ; preds = %33, %29
br label %36
36: ; preds = %35, %28
store i32 0, i32* %3
br label %37
37: ; preds = %36, %23
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
define i32 @pause_detect(i32 %0, i64* %1) {
%3 = tail call i32 @assert(i64* %1)
%4 = icmp eq i32 %0, -2
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = tail call i64 @time(i32* null)
%7 = load i64, i64* %1
%8 = icmp eq i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %5
%10 = tail call double @difftime(i64 %6, i64 %7)
%11 = fcmp ogt double %10, 5.000000e+00
br i1 %11, label %18, label %17
12: ; preds = %2
%13 = load i64, i64* %1
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12, %5
%16 = phi i64 [ %6, %5 ], [ 0, %12 ]
store i64 %16, i64* %1
br label %17
17: ; preds = %15, %12, %9
br label %18
18: ; preds = %9, %17
%19 = phi i32 [ 0, %17 ], [ -1, %9 ]
ret i32 %19
}