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

/* Variables and functions */
int CHAR_BIT;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ *gmtime_r(int *, struct tm *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int main(void) {
  static char date_buf[64];
  time_t max_time = ~(((time_t)1) << (sizeof(time_t) * CHAR_BIT - 1));
  struct tm broken_down;
  if (gmtime_r(&max_time, &broken_down) == NULL) {
    fprintf(stderr, "gmtime() error: year does not fit into an integer (is "
                    "time_t 64 bits wide?)\n");
    exit(EXIT_FAILURE);
  }
  strftime(date_buf, sizeof(date_buf), "%D %I:%M:%S %z %Z", &broken_down);
  printf("time_t will wrap around on %s\n", date_buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
movslq (%rax),%rax
shl    $0x2,%rax
sub    $0x1,%rax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
lea    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <gmtime_r@plt>
cmp    $0x0,%rax
jne    11ba <main+0x6a>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0x2e9f(%rip),%rdi
mov    $0x40,%esi
lea    0xe80(%rip),%rdx
lea    -0x10(%rbp),%rcx
call   1060 <strftime@plt>
lea    0xe82(%rip),%rdi
lea    0x2e7c(%rip),%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e84(%rip),%rax
mov    (%rax),%cl
shl    $0x2,%cl
add    $0xff,%cl
mov    $0xfffffffe,%eax
rol    %cl,%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1040 <gmtime_r@plt>
test   %rax,%rax
je     11ba <main+0x6a>
lea    0x2ed6(%rip),%rbx
lea    0xebc(%rip),%rdx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1060 <strftime@plt>
lea    0xeb5(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.tm = type { i32 }
@main.date_buf = internal global [64 x i8] zeroinitializer
@CHAR_BIT = global i32 0
@stderr = global i32 0
@.str = [77 x i8] c"gmtime() error: year does not fit into an integer (is time_t 64 bits wide?)\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [18 x i8] c"%D %I:%M:%S %z %Z\00"
@.str.2 = [31 x i8] c"time_t will wrap around on %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.tm
store i32 0, i32* %1
%4 = load i32, i32* @CHAR_BIT
%5 = sext i32 %4 to i64
%6 = mul i64 4, %5
%7 = sub i64 %6, 1
%8 = trunc i64 %7 to i32
%9 = shl i32 1, %8
%10 = xor i32 %9, -1
store i32 %10, i32* %2
%11 = call i32* @gmtime_r(i32* %2, %struct.tm* %3)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %18
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %0
%19 = call i32 @strftime(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @main.date_buf, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %3)
%20 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([64 x i8], [64 x i8]* @main.date_buf, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@main.date_buf = internal global [64 x i8] zeroinitializer
@CHAR_BIT = global i32 0
@stderr = global i32 0
@.str = [77 x i8] c"gmtime() error: year does not fit into an integer (is time_t 64 bits wide?)\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [18 x i8] c"%D %I:%M:%S %z %Z\00"
@.str.2 = [31 x i8] c"time_t will wrap around on %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.tm
%3 = bitcast i32* %1 to i8*
%4 = load i32, i32* @CHAR_BIT
%5 = shl i32 %4, 2
%6 = add i32 %5, -1
%7 = shl nuw i32 1, %6
%8 = xor i32 %7, -1
store i32 %8, i32* %1
%9 = bitcast %struct.tm* %2 to i8*
%10 = call i32* @gmtime_r(i32* %1, %struct.tm* %2)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %17
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %0
%18 = call i32 @strftime(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @main.date_buf, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %2)
%19 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([64 x i8], [64 x i8]* @main.date_buf, i64 0, i64 0))
ret i32 0
}