#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 dummy;
};

/* Variables and functions */
char *asctime(struct tm *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  time_t current_time;
  struct tm *timeptr;
  current_time = time(NULL);
  timeptr = NULL;
  timeptr = localtime(&current_time);
  if (timeptr != NULL) {
    printf("date: %s, ", (asctime(localtime((&current_time)))));
    puts("Test PASSED");
    return 0;
  } else {
    puts("Test FAILED: localtime failed");
    return 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x8(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c3 <main+0x73>
lea    -0x8(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,%rdi
call   1050 <asctime@plt>
mov    %rax,%rsi
lea    0xe5a(%rip),%rdi
call   1060 <printf@plt>
lea    0xe59(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d6 <main+0x86>
lea    0xe4d(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     119b <main+0x4b>
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,%rdi
call   1050 <asctime@plt>
lea    0xe76(%rip),%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
lea    0xe72(%rip),%rdi
jmp    11a7 <main+0x57>
mov    $0x1,%ebx
lea    0xe70(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [11 x i8] c"date: %s, \00"
@.str.1 = [12 x i8] c"Test PASSED\00"
@.str.2 = [30 x i8] c"Test FAILED: localtime failed\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.tm*
store i32 0, i32* %1
%4 = call i32 @time(i32* null)
store i32 %4, i32* %2
store %struct.tm* null, %struct.tm** %3
%5 = call %struct.tm* @localtime(i32* %2)
store %struct.tm* %5, %struct.tm** %3
%6 = load %struct.tm*, %struct.tm** %3
%7 = icmp ne %struct.tm* %6, null
br i1 %7, label %8, label %13
8: ; preds = %0
%9 = call %struct.tm* @localtime(i32* %2)
%10 = call i8* @asctime(%struct.tm* %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %15
13: ; preds = %0
%14 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %15
15: ; preds = %13, %8
%16 = load i32, i32* %1
ret i32 %16
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [11 x i8] c"date: %s, \00"
@.str.1 = [12 x i8] c"Test PASSED\00"
@.str.2 = [30 x i8] c"Test FAILED: localtime failed\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @time(i32* null)
store i32 %3, i32* %1
%4 = call %struct.tm* @localtime(i32* %1)
%5 = icmp eq %struct.tm* %4, null
br i1 %5, label %10, label %6
6: ; preds = %0
%7 = call %struct.tm* @localtime(i32* %1)
%8 = call i8* @asctime(%struct.tm* %7)
%9 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %0, %6
%11 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), %6 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), %0 ]
%12 = phi i32 [ 0, %6 ], [ 1, %0 ]
%13 = call i32 @puts(i8* dereferenceable(1) %11)
ret i32 %12
}