#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 */
struct timespec {
  scalar_t__ tv_sec;
};

/* Variables and functions */
int get_number_of_logins_and_last_logout(struct timespec *);
int is_time_for_halt(unsigned long long int *seconds) {
  struct timespec duration;
  int r;
  r = get_number_of_logins_and_last_logout(&duration);
  if (r < 0)
    return -1;
  if ((unsigned long long int)(duration.tv_sec) < *seconds) {
    *seconds -= (unsigned long long int)(duration.tv_sec);
    return 0;
  }
  if (r > 0)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<is_time_for_halt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <get_number_of_logins_and_last_logout@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    113e <is_time_for_halt+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1189 <is_time_for_halt+0x79>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jae    116c <is_time_for_halt+0x5c>
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1189 <is_time_for_halt+0x79>
cmpl   $0x0,-0x1c(%rbp)
jle    1182 <is_time_for_halt+0x72>
movl   $0x0,-0x4(%rbp)
jmp    1189 <is_time_for_halt+0x79>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_time_for_halt>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
call   1030 <get_number_of_logins_and_last_logout@plt>
test   %eax,%eax
js     1139 <is_time_for_halt+0x29>
mov    %eax,%ecx
mov    (%rbx),%rax
sub    0x8(%rsp),%rax
jbe    1140 <is_time_for_halt+0x30>
mov    %rax,(%rbx)
xor    %eax,%eax
jmp    1147 <is_time_for_halt+0x37>
mov    $0xffffffff,%eax
jmp    1147 <is_time_for_halt+0x37>
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.timespec = type { i64 }
define i32 @is_time_for_halt(i64* nocapture %0) {
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %2 to i8*
%4 = call i32 @get_number_of_logins_and_last_logout(%struct.timespec* %2)
%5 = icmp slt i32 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %1
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%8 = load i64, i64* %7
%9 = load i64, i64* %0
%10 = icmp ugt i64 %9, %8
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = sub i64 %9, %8
store i64 %12, i64* %0
br label %16
13: ; preds = %6
%14 = icmp eq i32 %4, 0
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %13, %1, %11
%17 = phi i32 [ 0, %11 ], [ -1, %1 ], [ %15, %13 ]
ret i32 %17
}