#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 *, float);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(scalar_t__ *);
char *local_time_str(time_t time_secs, char *buf) {
  time_t etime;
  struct tm *tm_info;
  if (time_secs == 0) {
    extern float sample_file_pos;
    if (sample_file_pos != -1.0) {
      snprintf(buf, 32, "@%fs", sample_file_pos);
      return buf;
    }
    time(&etime);
  } else {
    etime = time_secs;
  }
  tm_info = localtime(&etime);
  strftime(buf, 32, "%Y-%m-%d %H:%M:%S", tm_info);
  return buf;
}


x86 assembly (clang, -O0):
<local_time_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c2 <local_time_str+0x82>
mov    0x2e7e(%rip),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe8e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1187 <local_time_str+0x47>
jp     1187 <local_time_str+0x47>
jmp    11b4 <local_time_str+0x74>
mov    -0x18(%rbp),%rdi
mov    0x2e4e(%rip),%rax
movss  (%rax),%xmm0
mov    $0x20,%esi
lea    0xe66(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f8 <local_time_str+0xb8>
lea    -0x20(%rbp),%rdi
call   1050 <time@plt>
jmp    11ca <local_time_str+0x8a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x20,%esi
lea    0xe22(%rip),%rdx
call   1060 <strftime@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<local_time_str>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
test   %rdi,%rdi
je     1175 <local_time_str+0x35>
mov    %rdi,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xea6(%rip),%rdx
mov    %rbx,%rdi
mov    $0x20,%esi
mov    %rax,%rcx
call   1060 <strftime@plt>
jmp    119f <local_time_str+0x5f>
mov    0x2e64(%rip),%rax
movss  (%rax),%xmm0
ucomiss 0xe79(%rip),%xmm0
jne    118b <local_time_str+0x4b>
jnp    11a8 <local_time_str+0x68>
lea    0xe72(%rip),%rdx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <snprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret
lea    0x8(%rsp),%rdi
call   1050 <time@plt>
jmp    1152 <local_time_str+0x12>

LLVM IR (-O0):
%struct.tm = type { i32 }
@sample_file_pos = external global float
@.str = [5 x i8] c"@%fs\00"
@.str.1 = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
define i8* @local_time_str(i64 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.tm*
store i64 %0, i64* %4
store i8* %1, i8** %5
%8 = load i64, i64* %4
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %2
%11 = load float, float* @sample_file_pos
%12 = fpext float %11 to double
%13 = fcmp une double %12, -1.000000e+00
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = load float, float* @sample_file_pos
%17 = call i32 @snprintf(i8* %15, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), float %16)
%18 = load i8*, i8** %5
store i8* %18, i8** %3
br label %29
19: ; preds = %10
%20 = call i32 @time(i64* %6)
br label %23
21: ; preds = %2
%22 = load i64, i64* %4
store i64 %22, i64* %6
br label %23
23: ; preds = %21, %19
%24 = call %struct.tm* @localtime(i64* %6)
store %struct.tm* %24, %struct.tm** %7
%25 = load i8*, i8** %5
%26 = load %struct.tm*, %struct.tm** %7
%27 = call i32 @strftime(i8* %25, i32 32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %26)
%28 = load i8*, i8** %5
store i8* %28, i8** %3
br label %29
29: ; preds = %23, %14
%30 = load i8*, i8** %3
ret i8* %30
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@sample_file_pos = external global float
@.str = [5 x i8] c"@%fs\00"
@.str.1 = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
define i8* @local_time_str(i64 %0, i8* returned %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = icmp eq i64 %0, 0
br i1 %5, label %6, label %13
6: ; preds = %2
%7 = load float, float* @sample_file_pos
%8 = fcmp une float %7, -1.000000e+00
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @snprintf(i8* %1, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), float %7)
br label %17
11: ; preds = %6
%12 = call i32 @time(i64* %3)
br label %14
13: ; preds = %2
store i64 %0, i64* %3
br label %14
14: ; preds = %13, %11
%15 = call %struct.tm* @localtime(i64* %3)
%16 = call i32 @strftime(i8* %1, i32 32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %15)
br label %17
17: ; preds = %14, %9
ret i8* %1
}