#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 scalar_t__ time_t;
struct tm {
  int dummy;
};

/* Variables and functions */
struct tm *localtime(scalar_t__ *);
int /*<<< orphan*/ snprintf(char *, int, char *);
scalar_t__ strftime(char *, int, char const *, struct tm *);
scalar_t__ time(int /*<<< orphan*/ *);
char *qtime_localtime_strf(char *buf, int size, time_t utctime,
                           const char *format) {
  if (utctime == 0)
    utctime = time(NULL);
  struct tm *localtm = localtime(&utctime);
  if (strftime(buf, size, format, localtm) == 0) {
    snprintf(buf, size, "(buffer small)");
  }
  return buf;
}


x86 assembly (clang, -O0):
<qtime_localtime_strf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116f <qtime_localtime_strf+0x2f>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %rax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1060 <strftime@plt>
cmp    $0x0,%rax
jne    11ad <qtime_localtime_strf+0x6d>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    0xe58(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qtime_localtime_strf>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%rbp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %rdx,0x8(%rsp)
test   %rdx,%rdx
jne    1167 <qtime_localtime_strf+0x27>
xor    %edi,%edi
call   1050 <time@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %rbp,%rdx
mov    %rax,%rcx
call   1060 <strftime@plt>
test   %rax,%rax
jne    1199 <qtime_localtime_strf+0x59>
lea    0xe72(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1040 <snprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [15 x i8] c"(buffer small)\00"
define i8* @qtime_localtime_strf(i8* %0, i32 %1, i64 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
%9 = alloca %struct.tm*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i64 %2, i64* %7
store i8* %3, i8** %8
%10 = load i64, i64* %7
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = call i64 @time(i32* null)
store i64 %13, i64* %7
br label %14
14: ; preds = %12, %4
%15 = call %struct.tm* @localtime(i64* %7)
store %struct.tm* %15, %struct.tm** %9
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = load i8*, i8** %8
%19 = load %struct.tm*, %struct.tm** %9
%20 = call i64 @strftime(i8* %16, i32 %17, i8* %18, %struct.tm* %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %14
%23 = load i8*, i8** %5
%24 = load i32, i32* %6
%25 = call i32 @snprintf(i8* %23, i32 %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %22, %14
%27 = load i8*, i8** %5
ret i8* %27
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [15 x i8] c"(buffer small)\00"
define i8* @qtime_localtime_strf(i8* returned %0, i32 %1, i64 %2, i8* %3) {
%5 = alloca i64
store i64 %2, i64* %5
%6 = icmp eq i64 %2, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i64 @time(i32* null)
store i64 %8, i64* %5
br label %9
9: ; preds = %7, %4
%10 = call %struct.tm* @localtime(i64* %5)
%11 = call i64 @strftime(i8* %0, i32 %1, i8* %3, %struct.tm* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
ret i8* %0
}