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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
void log_get_time(char *str, int len, int flag_name) {
  char date_fmt[20];
  char date_ms[4];
  struct timeval tv;
  struct tm now_tm;
  int now_ms;
  time_t now_sec;
  gettimeofday(&tv, NULL);
  now_sec = tv.tv_sec;
  now_ms = tv.tv_usec / 1000;
  localtime_r(&now_sec, &now_tm);
  if (flag_name == 0) {
    strftime(date_fmt, 20, "%Y-%m-%d %H:%M:%S", &now_tm);
    snprintf(date_ms, sizeof(date_ms), "%03d", now_ms);
    snprintf(str, len, "[%s.%s]", date_fmt, date_ms);
  } else {
    strftime(date_fmt, 20, "%Y_%m_%d_%H_%M_%S", &now_tm);
    snprintf(date_ms, sizeof(date_ms), "%03d", now_ms);
    snprintf(str, len, "%s_%s.log", date_fmt, date_ms);
  }
}


x86 assembly (clang, -O0):
<log_get_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x40(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4c(%rbp)
lea    -0x50(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1030 <localtime_r@plt>
cmpl   $0x0,-0x10(%rbp)
jne    11df <log_get_time+0x9f>
lea    -0x30(%rbp),%rdi
mov    $0x14,%esi
lea    0xe66(%rip),%rdx
lea    -0x48(%rbp),%rcx
call   1060 <strftime@plt>
lea    -0x34(%rbp),%rdi
mov    -0x4c(%rbp),%ecx
mov    $0x4,%esi
lea    0xe5c(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x30(%rbp),%rcx
lea    -0x34(%rbp),%r8
lea    0xe44(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    122f <log_get_time+0xef>
lea    -0x30(%rbp),%rdi
mov    $0x14,%esi
lea    0xe30(%rip),%rdx
lea    -0x48(%rbp),%rcx
call   1060 <strftime@plt>
lea    -0x34(%rbp),%rdi
mov    -0x4c(%rbp),%ecx
mov    $0x4,%esi
lea    0xe07(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x30(%rbp),%rcx
lea    -0x34(%rbp),%r8
lea    0xe09(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_get_time>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x14(%rsp),%eax
mov    %eax,0xc(%rsp)
movslq 0x10(%rsp),%rax
imul   $0x10624dd3,%rax,%rbp
mov    %rbp,%rax
shr    $0x3f,%rax
sar    $0x26,%rbp
add    %eax,%ebp
lea    0xc(%rsp),%rdi
lea    0x18(%rsp),%r12
mov    %r12,%rsi
call   1030 <localtime_r@plt>
test   %ebx,%ebx
lea    0xe62(%rip),%rax
lea    0xe7a(%rip),%rdx
cmove  %rax,%rdx
lea    0xe67(%rip),%rax
lea    0xe7a(%rip),%rbx
cmove  %rax,%rbx
lea    0x20(%rsp),%r13
mov    %r13,%rdi
mov    $0x14,%esi
mov    %r12,%rcx
call   1060 <strftime@plt>
lea    0xe3b(%rip),%rdx
lea    0x1c(%rsp),%r12
mov    %r12,%rdi
mov    $0x4,%esi
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
mov    %r13,%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32 }
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.1 = [5 x i8] c"%03d\00"
@.str.2 = [8 x i8] c"[%s.%s]\00"
@.str.3 = [18 x i8] c"%Y_%m_%d_%H_%M_%S\00"
@.str.4 = [10 x i8] c"%s_%s.log\00"
define void @log_get_time(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [20 x i8]
%8 = alloca [4 x i8]
%9 = alloca %struct.timeval
%10 = alloca %struct.tm
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%13 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%15 = load i32, i32* %14
store i32 %15, i32* %12
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%17 = load i32, i32* %16
%18 = sdiv i32 %17, 1000
store i32 %18, i32* %11
%19 = call i32 @localtime_r(i32* %12, %struct.tm* %10)
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %33
22: ; preds = %3
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%24 = call i32 @strftime(i8* %23, i32 20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %10)
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%26 = load i32, i32* %11
%27 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %25, i32 4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = load i8*, i8** %4
%29 = load i32, i32* %5
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%32 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %28, i32 %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %30, i8* %31)
br label %44
33: ; preds = %3
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%35 = call i32 @strftime(i8* %34, i32 20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), %struct.tm* %10)
%36 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%37 = load i32, i32* %11
%38 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %36, i32 4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = load i8*, i8** %4
%40 = load i32, i32* %5
%41 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%42 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%43 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %39, i32 %40, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %41, i8* %42)
br label %44
44: ; preds = %33, %22
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32 }
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.1 = [5 x i8] c"%03d\00"
@.str.2 = [8 x i8] c"[%s.%s]\00"
@.str.3 = [18 x i8] c"%Y_%m_%d_%H_%M_%S\00"
@.str.4 = [10 x i8] c"%s_%s.log\00"
define void @log_get_time(i8* %0, i32 %1, i32 %2) {
%4 = alloca [20 x i8]
%5 = alloca [4 x i8]
%6 = alloca %struct.timeval
%7 = alloca %struct.tm
%8 = alloca i32
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%11 = bitcast %struct.timeval* %6 to i8*
%12 = bitcast %struct.tm* %7 to i8*
%13 = bitcast i32* %8 to i8*
%14 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%16 = load i32, i32* %15
store i32 %16, i32* %8
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%18 = load i32, i32* %17
%19 = sdiv i32 %18, 1000
%20 = call i32 @localtime_r(i32* %8, %struct.tm* %7)
%21 = icmp eq i32 %2, 0
%22 = select i1 %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0)
%23 = select i1 %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0)
%24 = call i32 @strftime(i8* %9, i32 20, i8* %22, %struct.tm* %7)
%25 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %10, i32 4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%26 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %0, i32 %1, i8* %23, i8* %9, i8* %10)
ret void
}