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

/* Variables and functions */
scalar_t__ asctime_r(struct tm *, char *);
scalar_t__ ctime_r(int /*<<< orphan*/ *, char *);
scalar_t__ gmtime_r(int /*<<< orphan*/ *, struct tm *);
scalar_t__ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ memset(struct tm *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int sprintf(char *, char *, char *);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  time_t ts = time(NULL);
  struct tm tm;
  char buf[512];
  memset(&tm, 0x00, sizeof(tm));
  if (ctime_r(&ts, buf)) {
    printf("len = %d, strlen = %d\n", sprintf(buf, "%s", buf), strlen(buf));
    printf("buf = %s\n", buf);
  }
  if (localtime_r(&ts, &tm) && asctime_r(&tm, buf)) {
    printf("buf = %s\n", buf);
  }
  if (gmtime_r(&ts, &tm) && asctime_r(&tm, buf)) {
    printf("buf_gm = %s\n", buf);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
lea    -0x210(%rbp),%rsi
lea    -0x8(%rbp),%rdi
call   1090 <ctime_r@plt>
cmp    $0x0,%rax
je     122f <main+0x9f>
lea    -0x210(%rbp),%rdi
lea    -0x210(%rbp),%rdx
lea    0xe2a(%rip),%rsi
call   10b0 <sprintf@plt>
mov    %eax,-0x214(%rbp)
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x214(%rbp),%esi
mov    %eax,%edx
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x210(%rbp),%rsi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <localtime_r@plt>
cmp    $0x0,%rax
je     1275 <main+0xe5>
lea    -0x210(%rbp),%rsi
lea    -0x10(%rbp),%rdi
call   10a0 <asctime_r@plt>
cmp    $0x0,%rax
je     1275 <main+0xe5>
lea    -0x210(%rbp),%rsi
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <gmtime_r@plt>
cmp    $0x0,%rax
je     12bb <main+0x12b>
lea    -0x210(%rbp),%rsi
lea    -0x10(%rbp),%rdi
call   10a0 <asctime_r@plt>
cmp    $0x0,%rax
je     12bb <main+0x12b>
lea    -0x210(%rbp),%rsi
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x218,%rsp
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1090 <ctime_r@plt>
test   %rax,%rax
je     11f5 <main+0x75>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0xe27(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe2c(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <localtime_r@plt>
test   %rax,%rax
je     1230 <main+0xb0>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   10a0 <asctime_r@plt>
test   %rax,%rax
je     1230 <main+0xb0>
lea    0xdf3(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1060 <gmtime_r@plt>
test   %rax,%rax
je     126b <main+0xeb>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   10a0 <asctime_r@plt>
test   %rax,%rax
je     126b <main+0xeb>
lea    0xdc2(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [23 x i8] c"len = %d, strlen = %d\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [10 x i8] c"buf = %s\0A\00"
@.str.3 = [13 x i8] c"buf_gm = %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.tm
%4 = alloca [512 x i8]
store i32 0, i32* %1
%5 = call i32 @time(i32* null)
store i32 %5, i32* %2
%6 = call i32 @memset(%struct.tm* %3, i32 0, i32 4)
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%8 = call i64 @ctime_r(i32* %2, i8* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %0
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%13 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %15)
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %10, %0
%20 = call i64 @localtime_r(i32* %2, %struct.tm* %3)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%24 = call i64 @asctime_r(%struct.tm* %3, i8* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %26, %22, %19
%30 = call i64 @gmtime_r(i32* %2, %struct.tm* %3)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %29
%33 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%34 = call i64 @asctime_r(%struct.tm* %3, i8* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %36, %32, %29
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [23 x i8] c"len = %d, strlen = %d\0A\00"
@.str.2 = [10 x i8] c"buf = %s\0A\00"
@.str.3 = [13 x i8] c"buf_gm = %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.tm
%3 = alloca [512 x i8]
%4 = bitcast i32* %1 to i8*
%5 = tail call i32 @time(i32* null)
store i32 %5, i32* %1
%6 = bitcast %struct.tm* %2 to i8*
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%8 = call i32 @memset(%struct.tm* %2, i32 0, i32 4)
%9 = call i64 @ctime_r(i32* %1, i8* %7)
%10 = icmp eq i64 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %0
%12 = call i64 bitcast (i32 (i8*)* @strlen to i64 (i8*)*)(i8* %7)
%13 = trunc i64 %12 to i32
%14 = call i32 @strlen(i8* %7)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %7)
br label %17
17: ; preds = %11, %0
%18 = call i64 @localtime_r(i32* %1, %struct.tm* %2)
%19 = icmp eq i64 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %17
%21 = call i64 @asctime_r(%struct.tm* %2, i8* %7)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %7)
br label %25
25: ; preds = %23, %20, %17
%26 = call i64 @gmtime_r(i32* %1, %struct.tm* %2)
%27 = icmp eq i64 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %25
%29 = call i64 @asctime_r(%struct.tm* %2, i8* %7)
%30 = icmp eq i64 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %7)
br label %33
33: ; preds = %31, %28, %25
ret i32 0
}