#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;
};
typedef int /*<<< orphan*/ dest_time;

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ strftime(char *, int, char const *, struct tm *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void get_time(const char *format, char *dest) {
  char dest_time[256];
  memset(dest, 0, strlen(dest));
  time_t curtime;
  struct tm *loctime;
  curtime = time(NULL);
  loctime = localtime(&curtime);
  if (!loctime)
    return;
  if (!strftime(dest_time, sizeof(dest_time), format, loctime))
    return;
  strncpy(dest, dest_time, strlen(dest_time) + 1);
}


x86 assembly (clang, -O0):
<get_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x128(%rbp),%rdi
mov    %rax,%rdx
xor    %esi,%esi
call   1060 <memset@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x114(%rbp)
lea    -0x114(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x120(%rbp)
cmpq   $0x0,-0x120(%rbp)
jne    11cd <get_time+0x6d>
jmp    1236 <get_time+0xd6>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x120(%rbp),%rcx
mov    $0x100,%esi
call   1080 <strftime@plt>
cmp    $0x0,%eax
jne    11f7 <get_time+0x97>
jmp    1236 <get_time+0xd6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x130(%rbp)
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x138(%rbp),%rdi
mov    -0x130(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <strncpy@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_time>:
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %rax,%rdx
call   1060 <memset@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     11d4 <get_time+0x74>
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %r14,%rdx
mov    %rax,%rcx
call   1080 <strftime@plt>
test   %eax,%eax
je     11d4 <get_time+0x74>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strncpy@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
define void @get_time(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = alloca %struct.tm*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
%11 = call i32 @memset(i8* %8, i32 0, i64 %10)
%12 = call i32 @time(i32* null)
store i32 %12, i32* %6
%13 = call %struct.tm* @localtime(i32* %6)
store %struct.tm* %13, %struct.tm** %7
%14 = load %struct.tm*, %struct.tm** %7
%15 = icmp ne %struct.tm* %14, null
br i1 %15, label %17, label %16
16: ; preds = %2
br label %31
17: ; preds = %2
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%19 = load i8*, i8** %3
%20 = load %struct.tm*, %struct.tm** %7
%21 = call i32 @strftime(i8* %18, i32 256, i8* %19, %struct.tm* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %17
br label %31
24: ; preds = %17
%25 = load i8*, i8** %4
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%28 = call i64 @strlen(i8* %27)
%29 = add nsw i64 %28, 1
%30 = call i32 @strncpy(i8* %25, i8* %26, i64 %29)
br label %31
31: ; preds = %24, %23, %16
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
define void @get_time(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = tail call i32 @memset(i8* %1, i32 0, i64 %6)
%8 = bitcast i32* %4 to i8*
%9 = tail call i32 @time(i32* null)
store i32 %9, i32* %4
%10 = call %struct.tm* @localtime(i32* %4)
%11 = icmp eq %struct.tm* %10, null
br i1 %11, label %19, label %12
12: ; preds = %2
%13 = call i32 @strftime(i8* %5, i32 256, i8* %0, %struct.tm* %10)
%14 = icmp eq i32 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = call i64 @strlen(i8* %5)
%17 = add nsw i64 %16, 1
%18 = call i32 @strncpy(i8* %1, i8* %5, i64 %17)
br label %19
19: ; preds = %12, %2, %15
ret void
}