#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;
};
struct timeval {
  int dummy;
};

/* Variables and functions */
scalar_t__ catcierge_strftime(char *, size_t, char const *, struct tm *,
                              struct timeval *);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
char *get_time_str_fmt(time_t t, struct timeval *tv, char *time_str, size_t len,
                       const char *fmt) {
  struct tm tm;
  localtime_r(&t, &tm);
  if (!fmt) {
    fmt = "%Y-%m-%d %H:%M:%S.%f";
  }
  if (catcierge_strftime(time_str, len, fmt, &tm, tv)) {
    return NULL;
  }
  return time_str;
}


x86 assembly (clang, -O0):
<get_time_str_fmt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
lea    -0xc(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1030 <localtime_r@plt>
cmpq   $0x0,-0x30(%rbp)
jne    115e <get_time_str_fmt+0x3e>
lea    0xea6(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x18(%rbp),%r8
lea    -0x38(%rbp),%rcx
call   1040 <catcierge_strftime@plt>
cmp    $0x0,%rax
je     118e <get_time_str_fmt+0x6e>
movq   $0x0,-0x8(%rbp)
jmp    1196 <get_time_str_fmt+0x76>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_time_str_fmt>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %edi,0x4(%rsp)
lea    0x4(%rsp),%rdi
lea    0x8(%rsp),%r13
mov    %r13,%rsi
call   1030 <localtime_r@plt>
test   %rbx,%rbx
lea    0xea7(%rip),%rdx
cmovne %rbx,%rdx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r13,%rcx
mov    %r12,%r8
call   1040 <catcierge_strftime@plt>
xor    %ecx,%ecx
test   %rax,%rax
cmove  %r15,%rcx
mov    %rcx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
%struct.tm = type { i32 }
@.str = [21 x i8] c"%Y-%m-%d %H:%M:%S.%f\00"
define i8* @get_time_str_fmt(i32 %0, %struct.timeval* %1, i8* %2, i64 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.timeval*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca %struct.tm
store i32 %0, i32* %7
store %struct.timeval* %1, %struct.timeval** %8
store i8* %2, i8** %9
store i64 %3, i64* %10
store i8* %4, i8** %11
%13 = call i32 @localtime_r(i32* %7, %struct.tm* %12)
%14 = load i8*, i8** %11
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %5
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8** %11
br label %17
17: ; preds = %16, %5
%18 = load i8*, i8** %9
%19 = load i64, i64* %10
%20 = load i8*, i8** %11
%21 = load %struct.timeval*, %struct.timeval** %8
%22 = call i64 @catcierge_strftime(i8* %18, i64 %19, i8* %20, %struct.tm* %12, %struct.timeval* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %17
store i8* null, i8** %6
br label %27
25: ; preds = %17
%26 = load i8*, i8** %9
store i8* %26, i8** %6
br label %27
27: ; preds = %25, %24
%28 = load i8*, i8** %6
ret i8* %28
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.tm = type { i32 }
@.str = [21 x i8] c"%Y-%m-%d %H:%M:%S.%f\00"
define i8* @get_time_str_fmt(i32 %0, %struct.timeval* %1, i8* %2, i64 %3, i8* %4) {
%6 = alloca i32
%7 = alloca %struct.tm
store i32 %0, i32* %6
%8 = bitcast %struct.tm* %7 to i8*
%9 = call i32 @localtime_r(i32* %6, %struct.tm* %7)
%10 = icmp eq i8* %4, null
%11 = select i1 %10, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %4
%12 = call i64 @catcierge_strftime(i8* %2, i64 %3, i8* %11, %struct.tm* %7, %struct.timeval* %1)
%13 = icmp eq i64 %12, 0
%14 = select i1 %13, i8* %2, i8* null
ret i8* %14
}