#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__ *);
int test_time() {
  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    $0x40,%rsp
mov    0x2ea1(%rip),%rax
movq   $0x0,(%rax)
lea    -0x18(%rbp),%rdi
call   1050 <time@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    0x2e82(%rip),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rdi
mov    -0x18(%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,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x19(%rbp)
jl     11f6 <test_time+0xc6>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
add    $0xa,%rcx
cmp    %rcx,%rax
setl   %al
mov    %al,-0x19(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rsi
mov    -0x19(%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>
mov    -0x4(%rbp),%eax
add    $0x40,%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 i32 @test_time() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
store i64 0, i64* @errno
%4 = call i64 @time(i64* %3)
store i64 %4, i64* %2
%5 = load i64, i64* %2
%6 = load i64, i64* @errno
%7 = load i64, i64* %3
%8 = load i64, i64* %2
%9 = load i64, i64* %3
%10 = icmp eq i64 %8, %9
%11 = zext i1 %10 to i64
%12 = select i1 %10, 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)
%13 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i64 %5, i64 %6, i64 %7, i8* %12)
%14 = call i32 (...) @stop()
store i64 0, i64* @errno
%15 = call i64 @time(i64* null)
store i64 %15, i64* %2
%16 = load i64, i64* %2
%17 = load i64, i64* @errno
%18 = load i64, i64* %3
%19 = load i64, i64* %2
%20 = load i64, i64* %3
%21 = icmp sge i64 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %0
%23 = load i64, i64* %2
%24 = load i64, i64* %3
%25 = add nsw i64 %24, 10
%26 = icmp slt i64 %23, %25
br label %27
27: ; preds = %22, %0
%28 = phi i1 [ false, %0 ], [ %26, %22 ]
%29 = zext i1 %28 to i64
%30 = select i1 %28, 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)
%31 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i64 %16, i64 %17, i64 %18, i8* %30)
%32 = call i32 (...) @stop()
%33 = load i32, i32* %1
ret i32 %33
}

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 i32 @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 i32 undef
}