#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;
typedef int /*<<< orphan*/ text_time;
struct tm {
  int dummy;
};

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ strftime(char *, int, char const *, struct tm *);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int util_get_time_length(const char *time_format) {
  time_t date;
  struct tm *local_time;
  char text_time[1024];
  if (!time_format || !time_format[0])
    return 0;
  date = time(NULL);
  local_time = localtime(&date);
  strftime(text_time, sizeof(text_time), time_format, local_time);
  return strlen(text_time);
}


x86 assembly (clang, -O0):
<util_get_time_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1167 <util_get_time_length+0x27>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1173 <util_get_time_length+0x33>
movl   $0x0,-0x4(%rbp)
jmp    11b4 <util_get_time_length+0x74>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x400,%esi
call   1060 <strftime@plt>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_get_time_length>:
push   %r14
push   %rbx
sub    $0x418,%rsp
xor    %eax,%eax
test   %rdi,%rdi
je     118e <util_get_time_length+0x4e>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     118e <util_get_time_length+0x4e>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1060 <strftime@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
add    $0x418,%rsp
pop    %rbx
pop    %r14
ret

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

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