#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*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ snprintf(char *, size_t, char *);
int strftime(char *, size_t, char const *, struct tm *);
void util_getLocalTime(const char *fmt, char *buf, size_t len, time_t tm) {
  struct tm ltime;
  localtime_r(&tm, &ltime);
  if (strftime(buf, len, fmt, &ltime) < 1) {
    snprintf(buf, len, "[date fetch error]");
  }
}


x86 assembly (clang, -O0):
<util_getLocalTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1050 <strftime@plt>
cmp    $0x1,%eax
jge    1186 <util_getLocalTime+0x56>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe7f(%rip),%rdx
call   1040 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_getLocalTime>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %ecx,0xc(%rsp)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%r12
mov    %r12,%rsi
call   1030 <localtime_r@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1050 <strftime@plt>
test   %eax,%eax
jg     1181 <util_getLocalTime+0x51>
lea    0xe8a(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <snprintf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [19 x i8] c"[date fetch error]\00"
define void @util_getLocalTime(i8* %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca %struct.tm
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 %3, i32* %8
%10 = call i32 @localtime_r(i32* %8, %struct.tm* %9)
%11 = load i8*, i8** %6
%12 = load i64, i64* %7
%13 = load i8*, i8** %5
%14 = call i32 @strftime(i8* %11, i64 %12, i8* %13, %struct.tm* %9)
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %20
16: ; preds = %4
%17 = load i8*, i8** %6
%18 = load i64, i64* %7
%19 = call i32 @snprintf(i8* %17, i64 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %16, %4
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [19 x i8] c"[date fetch error]\00"
define void @util_getLocalTime(i8* %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.tm
store i32 %3, i32* %5
%7 = bitcast %struct.tm* %6 to i8*
%8 = call i32 @localtime_r(i32* %5, %struct.tm* %6)
%9 = call i32 @strftime(i8* %1, i64 %2, i8* %0, %struct.tm* %6)
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %4
%12 = call i32 @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %4
ret void
}