#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*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ time(scalar_t__ *);
int test_clock_direction() {
  time_t starttime = 0;
  time_t stoptime = 0;
  int sleeptime = 60;
  int delta = 0;
  time(&starttime);
  sleep(sleeptime);
  time(&stoptime);
  delta = (int)stoptime - (int)starttime - sleeptime;
  printf("clock direction test: start time %d, stop time %d, sleeptime %u, "
         "delta %u\n",
         (int)starttime, (int)stoptime, sleeptime, delta);
  if (delta != 0) {
    printf("FAILED\n");
    return 1;
  }
  printf("PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_clock_direction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x3c,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x10(%rbp),%rdi
call   1040 <time@plt>
mov    -0x1c(%rbp),%edi
call   1050 <sleep@plt>
lea    -0x18(%rbp),%rdi
call   1040 <time@plt>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %ecx,%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x20(%rbp)
je     11c5 <test_clock_direction+0x95>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11da <test_clock_direction+0xaa>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_clock_direction>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%rdi
call   1050 <time@plt>
mov    $0x3c,%edi
call   1060 <sleep@plt>
lea    0x8(%rsp),%rdi
call   1050 <time@plt>
mov    0x8(%rsp),%edx
mov    0x10(%rsp),%esi
mov    %edx,%r8d
sub    %esi,%r8d
lea    0xe75(%rip),%rdi
xor    %ebp,%ebp
add    $0xffffffc4,%r8d
setne  %bpl
lea    0xeaf(%rip),%rax
lea    0xeaf(%rip),%rbx
cmove  %rax,%rbx
mov    $0x3c,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [75 x i8] c"clock direction test: start time %d, stop time %d, sleeptime %u, delta %u\0A\00"
@.str.1 = [8 x i8] c"FAILED\0A\00"
@.str.2 = [8 x i8] c"PASSED\0A\00"
define i32 @test_clock_direction() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
store i64 0, i64* %2
store i64 0, i64* %3
store i32 60, i32* %4
store i32 0, i32* %5
%6 = call i32 @time(i64* %2)
%7 = load i32, i32* %4
%8 = call i32 @sleep(i32 %7)
%9 = call i32 @time(i64* %3)
%10 = load i64, i64* %3
%11 = trunc i64 %10 to i32
%12 = load i64, i64* %2
%13 = trunc i64 %12 to i32
%14 = sub nsw i32 %11, %13
%15 = load i32, i32* %4
%16 = sub nsw i32 %14, %15
store i32 %16, i32* %5
%17 = load i64, i64* %2
%18 = trunc i64 %17 to i32
%19 = load i64, i64* %3
%20 = trunc i64 %19 to i32
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %20, i32 %21, i32 %22)
%24 = load i32, i32* %5
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %30
28: ; preds = %0
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %30
30: ; preds = %28, %26
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [75 x i8] c"clock direction test: start time %d, stop time %d, sleeptime %u, delta %u\0A\00"
@str = [7 x i8] c"PASSED\00"
@str.3 = [7 x i8] c"FAILED\00"
define i32 @test_clock_direction() {
%1 = alloca i64
%2 = alloca i64
%3 = bitcast i64* %1 to i8*
store i64 0, i64* %1
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = call i32 @time(i64* %1)
%6 = call i32 @sleep(i32 60)
%7 = call i32 @time(i64* %2)
%8 = load i64, i64* %2
%9 = trunc i64 %8 to i32
%10 = load i64, i64* %1
%11 = trunc i64 %10 to i32
%12 = sub nsw i32 %9, %11
%13 = add nsw i32 %12, -60
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %9, i32 60, i32 %13)
%15 = icmp eq i32 %13, 0
%16 = select i1 %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.3, i64 0, i64 0)
%17 = xor i1 %15, true
%18 = zext i1 %17 to i32
%19 = call i32 @puts(i8* dereferenceable(1) %16)
ret i32 %18
}