#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*/ copy_str(char *, size_t, char *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ strftime(char *, size_t, char *, struct tm *const);
void format_time(time_t t, char buf[], size_t buf_size) {
  struct tm *const tm = localtime(&t);
  if (tm == NULL) {
    copy_str(buf, buf_size, "");
    return;
  }
  strftime(buf, buf_size, "%a, %d %b %Y %H:%M:%S", tm);
}


x86 assembly (clang, -O0):
<format_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x4(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1174 <format_time+0x44>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xeab(%rip),%rdx
call   1040 <copy_str@plt>
jmp    118c <format_time+0x5c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
lea    0xe79(%rip),%rdx
call   1050 <strftime@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_time>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     1164 <format_time+0x34>
lea    0xeac(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rax,%rcx
call   1050 <strftime@plt>
jmp    1176 <format_time+0x46>
lea    0xeaa(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <copy_str@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [22 x i8] c"%a, %d %b %Y %H:%M:%S\00"
define void @format_time(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 = call %struct.tm* @localtime(i32* %4)
store %struct.tm* %8, %struct.tm** %7
%9 = load %struct.tm*, %struct.tm** %7
%10 = icmp eq %struct.tm* %9, null
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = load i64, i64* %6
%14 = call i32 @copy_str(i8* %12, i64 %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %20
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = load i64, i64* %6
%18 = load %struct.tm*, %struct.tm** %7
%19 = call i32 @strftime(i8* %16, i64 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %18)
br label %20
20: ; preds = %15, %11
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [22 x i8] c"%a, %d %b %Y %H:%M:%S\00"
define void @format_time(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
store i32 %0, i32* %4
%5 = call %struct.tm* @localtime(i32* %4)
%6 = icmp eq %struct.tm* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = call i32 @copy_str(i8* %1, i64 %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %11
9: ; preds = %3
%10 = call i32 @strftime(i8* %1, i64 %2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %5)
br label %11
11: ; preds = %9, %7
ret void
}