#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*/ buf;

/* Variables and functions */
int _date_error(char *, int);
int /*<<< orphan*/ *localtime_r(int *, struct tm *);
int /*<<< orphan*/ puts(char *);
scalar_t__ strftime(char *, int, char const *, struct tm *);
int time(int /*<<< orphan*/ *);
int /*<<< orphan*/ tzset();
int _date(char const *format) {
  time_t t;
  struct tm tm;
  char buf[128];
  tzset();
  if ((t = time(NULL)) == -1)
    return -_date_error("time", 1);
  if (localtime_r(&t, &tm) == NULL)
    return -_date_error("localtime_r", 1);
  if (strftime(buf, sizeof(buf), format, &tm) == 0 && format[0] != '\0')
    return -_date_error("strftime", 1);
  puts(buf);
  return 0;
}


x86 assembly (clang, -O0):
<_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <tzset@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11aa <_date+0x4a>
lea    0xe7e(%rip),%rdi
mov    $0x1,%esi
call   1080 <_date_error@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1245 <_date+0xe5>
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <localtime_r@plt>
cmp    $0x0,%rax
jne    11e0 <_date+0x80>
lea    0xe38(%rip),%rdi
mov    $0x1,%esi
call   1080 <_date_error@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1245 <_date+0xe5>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x80,%esi
lea    -0x18(%rbp),%rcx
call   1070 <strftime@plt>
cmp    $0x0,%rax
jne    1232 <_date+0xd2>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1232 <_date+0xd2>
lea    0xdf2(%rip),%rdi
mov    $0x1,%esi
call   1080 <_date_error@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1245 <_date+0xe5>
lea    -0xa0(%rbp),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_date>:
push   %rbx
sub    $0x90,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <tzset@plt>
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
je     11c0 <_date+0x60>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <localtime_r@plt>
test   %rax,%rax
je     11c9 <_date+0x69>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rcx
mov    $0x80,%esi
mov    %rbx,%rdx
call   1070 <strftime@plt>
test   %rax,%rax
je     11d2 <_date+0x72>
lea    0x10(%rsp),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    11ea <_date+0x8a>
lea    0xe49(%rip),%rdi
jmp    11de <_date+0x7e>
lea    0xe30(%rip),%rdi
jmp    11de <_date+0x7e>
cmpb   $0x0,(%rbx)
je     11b2 <_date+0x52>
lea    0xe2e(%rip),%rdi
mov    $0x1,%esi
call   1080 <_date_error@plt>
neg    %eax
add    $0x90,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [5 x i8] c"time\00"
@.str.1 = [12 x i8] c"localtime_r\00"
@.str.2 = [9 x i8] c"strftime\00"
define i32 @_date(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.tm
%6 = alloca [128 x i8]
store i8* %0, i8** %3
%7 = call i32 (...) @tzset()
%8 = call i32 @time(i32* null)
store i32 %8, i32* %4
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 @_date_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 1)
%12 = sub nsw i32 0, %11
store i32 %12, i32* %2
br label %36
13: ; preds = %1
%14 = call i32* @localtime_r(i32* %4, %struct.tm* %5)
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = call i32 @_date_error(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 1)
%18 = sub nsw i32 0, %17
store i32 %18, i32* %2
br label %36
19: ; preds = %13
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%21 = load i8*, i8** %3
%22 = call i64 @strftime(i8* %20, i32 128, i8* %21, %struct.tm* %5)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %33
24: ; preds = %19
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = call i32 @_date_error(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 1)
%32 = sub nsw i32 0, %31
store i32 %32, i32* %2
br label %36
33: ; preds = %24, %19
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%35 = call i32 @puts(i8* %34)
store i32 0, i32* %2
br label %36
36: ; preds = %33, %30, %16, %10
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [5 x i8] c"time\00"
@.str.1 = [12 x i8] c"localtime_r\00"
@.str.2 = [9 x i8] c"strftime\00"
define i32 @_date(i8* %0) {
%2 = alloca i32
%3 = alloca %struct.tm
%4 = alloca [128 x i8]
%5 = bitcast i32* %2 to i8*
%6 = bitcast %struct.tm* %3 to i8*
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = tail call i32 (...) @tzset()
%9 = tail call i32 @time(i32* null)
store i32 %9, i32* %2
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = tail call i32 @_date_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 1)
%13 = sub nsw i32 0, %12
br label %31
14: ; preds = %1
%15 = call i32* @localtime_r(i32* %2, %struct.tm* %3)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = call i32 @_date_error(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 1)
%19 = sub nsw i32 0, %18
br label %31
20: ; preds = %14
%21 = call i64 @strftime(i8* %7, i32 128, i8* %0, %struct.tm* %3)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load i8, i8* %0
%25 = icmp eq i8 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = call i32 @_date_error(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 1)
%28 = sub nsw i32 0, %27
br label %31
29: ; preds = %23, %20
%30 = call i32 @puts(i8* %7)
br label %31
31: ; preds = %29, %26, %17, %11
%32 = phi i32 [ %13, %11 ], [ %19, %17 ], [ %28, %26 ], [ 0, %29 ]
ret i32 %32
}