#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*/ abort();
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int get_time_string(char **time_buf, int time_buf_len) {
  time_t t;
  struct tm *tm_tmp;
  memset(*time_buf, 0, time_buf_len);
  t = time(NULL);
  tm_tmp = localtime(&t);
  if (NULL == tm_tmp) {
    perror("localtime error");
    abort();
  }
  strftime(*time_buf, time_buf_len, "%Y%m%d-%H%M%S", tm_tmp);
  return strlen(*time_buf);
}


x86 assembly (clang, -O0):
<get_time_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11c8 <get_time_string+0x58>
lea    0xe44(%rip),%rdi
call   1090 <perror@plt>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rcx
lea    0xe33(%rip),%rdx
call   1080 <strftime@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_time_string>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    (%rdi),%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1060 <memset@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     11c1 <get_time_string+0x51>
mov    (%rbx),%rdi
lea    0xe68(%rip),%rdx
mov    %ebp,%esi
mov    %rax,%rcx
call   1080 <strftime@plt>
mov    (%rbx),%rdi
call   1050 <strlen@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe38(%rip),%rdi
call   1090 <perror@plt>
xor    %eax,%eax
call   1040 <abort@plt>

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

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [16 x i8] c"localtime error\00"
@.str.1 = [14 x i8] c"%Y%m%d-%H%M%S\00"
define i32 @get_time_string(i8** nocapture %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i8*, i8** %0
%6 = tail call i32 @memset(i8* %5, i32 0, i32 %1)
%7 = tail call i32 @time(i32* null)
store i32 %7, i32* %3
%8 = call %struct.tm* @localtime(i32* %3)
%9 = icmp eq %struct.tm* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (...) @abort()
unreachable
13: ; preds = %2
%14 = load i8*, i8** %0
%15 = call i32 @strftime(i8* %14, i32 %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %8)
%16 = load i8*, i8** %0
%17 = call i32 @strlen(i8* %16)
ret i32 %17
}