#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 */
int /*<<< orphan*/ asctime_r(struct tm *, char *);
int /*<<< orphan*/ gmtime_r(int /*<<< orphan*/ *, struct tm *);
int strlen(char *);
void mmp_time_asctime_format(time_t t, char *datestr, size_t strsize) {
  struct tm tt;
  if (datestr == NULL || strsize == 0)
    return;
  gmtime_r(&t, &tt);
  asctime_r(&tt, datestr);
  if (strlen(datestr) > 0)
    datestr[strlen(datestr) - 1] = '\0';
}


x86 assembly (clang, -O0):
<mmp_time_asctime_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1159 <mmp_time_asctime_format+0x29>
cmpq   $0x0,-0x18(%rbp)
jne    115e <mmp_time_asctime_format+0x2e>
jmp    11ab <mmp_time_asctime_format+0x7b>
lea    -0x4(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <gmtime_r@plt>
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdi
call   1050 <asctime_r@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jle    11ab <mmp_time_asctime_format+0x7b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mmp_time_asctime_format>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,0xc(%rsp)
test   %rsi,%rsi
je     1180 <mmp_time_asctime_format+0x50>
test   %rdx,%rdx
je     1180 <mmp_time_asctime_format+0x50>
mov    %rsi,%rbx
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
call   1040 <gmtime_r@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <asctime_r@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1180 <mmp_time_asctime_format+0x50>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
define void @mmp_time_asctime_format(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.tm
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = load i64, i64* %6
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10, %3
br label %28
14: ; preds = %10
%15 = call i32 @gmtime_r(i32* %4, %struct.tm* %7)
%16 = load i8*, i8** %5
%17 = call i32 @asctime_r(%struct.tm* %7, i8* %16)
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %14
%22 = load i8*, i8** %5
%23 = load i8*, i8** %5
%24 = call i32 @strlen(i8* %23)
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %22, i64 %26
store i8 0, i8* %27
br label %28
28: ; preds = %13, %21, %14
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
define void @mmp_time_asctime_format(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.tm
store i32 %0, i32* %4
%6 = bitcast %struct.tm* %5 to i8*
%7 = icmp eq i8* %1, null
%8 = icmp eq i64 %2, 0
%9 = or i1 %7, %8
br i1 %9, label %20, label %10
10: ; preds = %3
%11 = call i32 @gmtime_r(i32* %4, %struct.tm* %5)
%12 = call i32 @asctime_r(%struct.tm* %5, i8* %1)
%13 = call i32 @strlen(i8* %1)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = call i32 @strlen(i8* %1)
%17 = add nsw i32 %16, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %10, %15, %3
ret void
}