#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 */
scalar_t__ errno;
int /*<<< orphan*/ printf(char *, long, scalar_t__, long, char *);
int /*<<< orphan*/ stop();
scalar_t__ time(scalar_t__ *);
void test_time(void) {
  time_t ret, t;
  errno = 0;
  ret = time(&t);
  printf("time 1: ret = %ld, errno = %d, t = %ld %s\n", (long)ret, errno,
         (long)t, ret == t ? "OK" : "");
  stop();
  errno = 0;
  ret = time(NULL);
  printf("time 2: ret = %ld, errno = %d, t = %ld %s\n", (long)ret, errno,
         (long)t, ret >= t && ret < t + 10 ? "OK" : "");
  stop();
}


x86 assembly (clang, -O0):
<test_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2ea1(%rip),%rax
movq   $0x0,(%rax)
lea    -0x10(%rbp),%rdi
call   1050 <time@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
mov    0x2e82(%rip),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%r9
lea    0xeb6(%rip),%r8
lea    0xeb0(%rip),%rax
cmp    %r9,%rdi
cmove  %rax,%r8
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <stop@plt>
mov    0x2e44(%rip),%rax
movq   $0x0,(%rax)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x11(%rbp)
jl     11f6 <test_time+0xc6>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    $0xa,%rcx
cmp    %rcx,%rax
setl   %al
mov    %al,-0x11(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rsi
mov    -0x11(%rbp),%dil
lea    0xe1d(%rip),%r8
lea    0xe17(%rip),%rax
test   $0x1,%dil
cmovne %rax,%r8
lea    0xe0b(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <stop@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_time>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2ea0(%rip),%r14
movq   $0x0,(%r14)
lea    0x8(%rsp),%rdi
call   1050 <time@plt>
mov    (%r14),%rdx
mov    0x8(%rsp),%rcx
cmp    %rcx,%rax
lea    0xec8(%rip),%rbx
lea    0xec0(%rip),%r15
mov    %r15,%r8
cmove  %rbx,%r8
lea    0xe88(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <stop@plt>
movq   $0x0,(%r14)
xor    %edi,%edi
call   1050 <time@plt>
mov    0x8(%rsp),%rcx
lea    0xa(%rcx),%rdx
cmp    %rdx,%rax
cmovge %r15,%rbx
mov    (%r14),%rdx
cmp    %rcx,%rax
cmovl  %r15,%rbx
lea    0xe78(%rip),%rdi
mov    %rax,%rsi
mov    %rbx,%r8
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <stop@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [43 x i8] c"time 1: ret = %ld, errno = %d, t = %ld %s\0A\00"
@.str.1 = [3 x i8] c"OK\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [43 x i8] c"time 2: ret = %ld, errno = %d, t = %ld %s\0A\00"
define void @test_time() {
%1 = alloca i64
%2 = alloca i64
store i64 0, i64* @errno
%3 = call i64 @time(i64* %2)
store i64 %3, i64* %1
%4 = load i64, i64* %1
%5 = load i64, i64* @errno
%6 = load i64, i64* %2
%7 = load i64, i64* %1
%8 = load i64, i64* %2
%9 = icmp eq i64 %7, %8
%10 = zext i1 %9 to i64
%11 = select i1 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%12 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i64 %4, i64 %5, i64 %6, i8* %11)
%13 = call i32 (...) @stop()
store i64 0, i64* @errno
%14 = call i64 @time(i64* null)
store i64 %14, i64* %1
%15 = load i64, i64* %1
%16 = load i64, i64* @errno
%17 = load i64, i64* %2
%18 = load i64, i64* %1
%19 = load i64, i64* %2
%20 = icmp sge i64 %18, %19
br i1 %20, label %21, label %26
21: ; preds = %0
%22 = load i64, i64* %1
%23 = load i64, i64* %2
%24 = add nsw i64 %23, 10
%25 = icmp slt i64 %22, %24
br label %26
26: ; preds = %21, %0
%27 = phi i1 [ false, %0 ], [ %25, %21 ]
%28 = zext i1 %27 to i64
%29 = select i1 %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%30 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i64 %15, i64 %16, i64 %17, i8* %29)
%31 = call i32 (...) @stop()
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [43 x i8] c"time 1: ret = %ld, errno = %d, t = %ld %s\0A\00"
@.str.1 = [3 x i8] c"OK\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [43 x i8] c"time 2: ret = %ld, errno = %d, t = %ld %s\0A\00"
define void @test_time() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
store i64 0, i64* @errno
%3 = call i64 @time(i64* %1)
%4 = load i64, i64* @errno
%5 = load i64, i64* %1
%6 = icmp eq i64 %3, %5
%7 = select i1 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%8 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i64 %3, i64 %4, i64 %5, i8* %7)
%9 = call i32 (...) @stop()
store i64 0, i64* @errno
%10 = call i64 @time(i64* null)
%11 = load i64, i64* @errno
%12 = load i64, i64* %1
%13 = icmp sge i64 %10, %12
%14 = add nsw i64 %12, 10
%15 = icmp slt i64 %10, %14
%16 = select i1 %13, i1 %15, i1 false
%17 = select i1 %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%18 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i64 %10, i64 %11, i64 %12, i8* %17)
%19 = call i32 (...) @stop()
ret void
}