#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 int /*<<< orphan*/ time_t;
struct tm {
  int /*<<< orphan*/ tm_year;
};

/* Variables and functions */
scalar_t__ EOVERFLOW;
int /*<<< orphan*/ INT_MAX;
char *asctime(struct tm *);
char *asctime_r(struct tm *, char *);
scalar_t__ errno;
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *, int /*<<< orphan*/ *, scalar_t__,
                          scalar_t__);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int do_test(void) {
  int result = 0;
  time_t t = time(NULL);
  struct tm *tp = localtime(&t);
  tp->tm_year = INT_MAX;
  errno = 0;
  char *s = asctime(tp);
  if (s != NULL || errno != EOVERFLOW) {
    printf("asctime did not fail correctly: s=%p, wanted %p; errno=%i, wanted "
           "%i\n",
           s, NULL, errno, EOVERFLOW);
    result = 1;
  }
  char buf[1000];
  errno = 0;
  s = asctime_r(tp, buf);
  if (s != NULL || errno != EOVERFLOW) {
    printf("asctime_r did not fail correctly: s=%p, wanted %p; errno=%i, "
           "wanted %i\n",
           s, NULL, errno, EOVERFLOW);
    result = 1;
  }
  return result;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0x8(%rbp)
lea    -0x8(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e5e(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2e3f(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <asctime@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ca <do_test+0x7a>
mov    0x2e19(%rip),%rax
mov    (%rax),%rax
mov    0x2e2f(%rip),%rcx
cmp    (%rcx),%rax
je     11f9 <do_test+0xa9>
mov    -0x18(%rbp),%rsi
mov    0x2dfb(%rip),%rax
mov    (%rax),%rcx
mov    0x2e11(%rip),%rax
mov    (%rax),%r8
lea    0xe17(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    0x2dd0(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x400(%rbp),%rsi
call   1070 <asctime_r@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1240 <do_test+0xf0>
mov    0x2da3(%rip),%rax
mov    (%rax),%rax
mov    0x2db9(%rip),%rcx
cmp    (%rcx),%rax
je     126f <do_test+0x11f>
mov    -0x18(%rbp),%rsi
mov    0x2d85(%rip),%rax
mov    (%rax),%rcx
mov    0x2d9b(%rip),%rax
mov    (%rax),%r8
lea    0xde7(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3f8,%rsp
xor    %r14d,%r14d
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,%rbx
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rbx)
mov    0x2e45(%rip),%r15
movq   $0x0,(%r15)
mov    %rbx,%rdi
call   1040 <asctime@plt>
mov    (%r15),%rcx
mov    0x2e4c(%rip),%r12
mov    (%r12),%r8
test   %rax,%rax
jne    11b2 <do_test+0x62>
cmp    %r8,%rcx
je     11c9 <do_test+0x79>
lea    0xe47(%rip),%rdi
mov    %rax,%rsi
xor    %edx,%edx
call   1050 <printf@plt>
mov    $0x1,%r14d
movq   $0x0,(%r15)
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <asctime_r@plt>
mov    (%r15),%rcx
mov    (%r12),%r8
test   %rax,%rax
jne    11ee <do_test+0x9e>
cmp    %r8,%rcx
je     1205 <do_test+0xb5>
lea    0xe51(%rip),%rdi
mov    %rax,%rsi
xor    %edx,%edx
call   1050 <printf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@INT_MAX = global i32 0
@errno = global i64 0
@EOVERFLOW = global i64 0
@.str = [70 x i8] c"asctime did not fail correctly: s=%p, wanted %p; errno=%i, wanted %i\0A\00"
@.str.1 = [72 x i8] c"asctime_r did not fail correctly: s=%p, wanted %p; errno=%i, wanted %i\0A\00"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.tm*
%4 = alloca i8*
%5 = alloca [1000 x i8]
store i32 0, i32* %1
%6 = call i32 @time(i32* null)
store i32 %6, i32* %2
%7 = call %struct.tm* @localtime(i32* %2)
store %struct.tm* %7, %struct.tm** %3
%8 = load i32, i32* @INT_MAX
%9 = load %struct.tm*, %struct.tm** %3
%10 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 0
store i32 %8, i32* %10
store i64 0, i64* @errno
%11 = load %struct.tm*, %struct.tm** %3
%12 = call i8* @asctime(%struct.tm* %11)
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %19, label %15
15: ; preds = %0
%16 = load i64, i64* @errno
%17 = load i64, i64* @EOVERFLOW
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %24
19: ; preds = %15, %0
%20 = load i8*, i8** %4
%21 = load i64, i64* @errno
%22 = load i64, i64* @EOVERFLOW
%23 = call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8* %20, i32* null, i64 %21, i64 %22)
store i32 1, i32* %1
br label %24
24: ; preds = %19, %15
store i64 0, i64* @errno
%25 = load %struct.tm*, %struct.tm** %3
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%27 = call i8* @asctime_r(%struct.tm* %25, i8* %26)
store i8* %27, i8** %4
%28 = load i8*, i8** %4
%29 = icmp ne i8* %28, null
br i1 %29, label %34, label %30
30: ; preds = %24
%31 = load i64, i64* @errno
%32 = load i64, i64* @EOVERFLOW
%33 = icmp ne i64 %31, %32
br i1 %33, label %34, label %39
34: ; preds = %30, %24
%35 = load i8*, i8** %4
%36 = load i64, i64* @errno
%37 = load i64, i64* @EOVERFLOW
%38 = call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0), i8* %35, i32* null, i64 %36, i64 %37)
store i32 1, i32* %1
br label %39
39: ; preds = %34, %30
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@INT_MAX = global i32 0
@errno = global i64 0
@EOVERFLOW = global i64 0
@.str = [70 x i8] c"asctime did not fail correctly: s=%p, wanted %p; errno=%i, wanted %i\0A\00"
@.str.1 = [72 x i8] c"asctime_r did not fail correctly: s=%p, wanted %p; errno=%i, wanted %i\0A\00"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca [1000 x i8]
%3 = bitcast i32* %1 to i8*
%4 = tail call i32 @time(i32* null)
store i32 %4, i32* %1
%5 = call %struct.tm* @localtime(i32* %1)
%6 = load i32, i32* @INT_MAX
%7 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
store i32 %6, i32* %7
store i64 0, i64* @errno
%8 = call i8* @asctime(%struct.tm* %5)
%9 = icmp eq i8* %8, null
%10 = load i64, i64* @errno
%11 = load i64, i64* @EOVERFLOW
%12 = icmp eq i64 %10, %11
%13 = select i1 %9, i1 %12, i1 false
br i1 %13, label %16, label %14
14: ; preds = %0
%15 = call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8* %8, i32* null, i64 %10, i64 %11)
br label %16
16: ; preds = %0, %14
%17 = phi i32 [ 1, %14 ], [ 0, %0 ]
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
store i64 0, i64* @errno
%19 = call i8* @asctime_r(%struct.tm* %5, i8* %18)
%20 = icmp eq i8* %19, null
%21 = load i64, i64* @errno
%22 = load i64, i64* @EOVERFLOW
%23 = icmp eq i64 %21, %22
%24 = select i1 %20, i1 %23, i1 false
br i1 %24, label %27, label %25
25: ; preds = %16
%26 = call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0), i8* %19, i32* null, i64 %21, i64 %22)
br label %27
27: ; preds = %16, %25
%28 = phi i32 [ 1, %25 ], [ %17, %16 ]
ret i32 %28
}