#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 tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int, int);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int get_currenttime(char *currtime) {
  struct tm *ptm = NULL;
  time_t tme;
  char sztime[128] = "";
  if (currtime == NULL) {
    return -1;
  }
  tme = time(NULL);
  ptm = localtime(&tme);
  sprintf(sztime, "[%d-%02d-%02d %02d:%02d:%02d] ", (ptm->tm_year + 1900),
          ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min,
          ptm->tm_sec);
  strcpy(currtime, sztime);
  return 0;
}


x86 assembly (clang, -O0):
<get_currenttime>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1191 <get_currenttime+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    1211 <get_currenttime+0xc1>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
add    $0x76c,%edx
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%r9d
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%r10d
mov    -0x18(%rbp),%rax
mov    0x14(%rax),%eax
lea    0xe13(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_currenttime>:
push   %r15
push   %r14
push   %rbx
sub    $0x90,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
test   %rdi,%rdi
je     11de <get_currenttime+0x9e>
mov    %rdi,%rbx
xor    %r14d,%r14d
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    $0x76c,%edx
add    (%rax),%edx
mov    0x4(%rax),%ecx
mov    0x8(%rax),%r8d
add    $0x1,%ecx
mov    0xc(%rax),%r9d
mov    0x10(%rax),%r10d
mov    0x14(%rax),%eax
lea    0xe43(%rip),%rsi
lea    0x10(%rsp),%r15
mov    %r15,%rdi
push   %rax
push   %r10
call   1060 <sprintf@plt>
add    $0x10,%rsp
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
jmp    11e4 <get_currenttime+0xa4>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [31 x i8] c"[%d-%02d-%02d %02d:%02d:%02d] \00"
define i32 @get_currenttime(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.tm*
%5 = alloca i32
%6 = alloca [128 x i8]
store i8* %0, i8** %3
store %struct.tm* null, %struct.tm** %4
%7 = bitcast [128 x i8]* %6 to i8*
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %39
11: ; preds = %1
%12 = call i32 @time(i32* null)
store i32 %12, i32* %5
%13 = call %struct.tm* @localtime(i32* %5)
store %struct.tm* %13, %struct.tm** %4
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%15 = load %struct.tm*, %struct.tm** %4
%16 = getelementptr inbounds %struct.tm, %struct.tm* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = add nsw i32 %17, 1900
%19 = load %struct.tm*, %struct.tm** %4
%20 = getelementptr inbounds %struct.tm, %struct.tm* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1
%23 = load %struct.tm*, %struct.tm** %4
%24 = getelementptr inbounds %struct.tm, %struct.tm* %23, i32 0, i32 2
%25 = load i32, i32* %24
%26 = load %struct.tm*, %struct.tm** %4
%27 = getelementptr inbounds %struct.tm, %struct.tm* %26, i32 0, i32 3
%28 = load i32, i32* %27
%29 = load %struct.tm*, %struct.tm** %4
%30 = getelementptr inbounds %struct.tm, %struct.tm* %29, i32 0, i32 4
%31 = load i32, i32* %30
%32 = load %struct.tm*, %struct.tm** %4
%33 = getelementptr inbounds %struct.tm, %struct.tm* %32, i32 0, i32 5
%34 = load i32, i32* %33
%35 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %22, i32 %25, i32 %28, i32 %31, i32 %34)
%36 = load i8*, i8** %3
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%38 = call i32 @strcpy(i8* %36, i8* %37)
store i32 0, i32* %2
br label %39
39: ; preds = %11, %10
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [31 x i8] c"[%d-%02d-%02d %02d:%02d:%02d] \00"
define i32 @get_currenttime(i8* %0) {
%2 = alloca i32
%3 = alloca [128 x i8]
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = icmp eq i8* %0, null
br i1 %6, label %26, label %7
7: ; preds = %1
%8 = tail call i32 @time(i32* null)
store i32 %8, i32* %2
%9 = call %struct.tm* @localtime(i32* %2)
%10 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 0
%11 = load i32, i32* %10
%12 = add nsw i32 %11, 1900
%13 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 1
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1
%16 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 2
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 3
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 4
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 5
%23 = load i32, i32* %22
%24 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %15, i32 %17, i32 %19, i32 %21, i32 %23)
%25 = call i32 @strcpy(i8* %0, i8* %5)
br label %26
26: ; preds = %1, %7
%27 = phi i32 [ 0, %7 ], [ -1, %1 ]
ret i32 %27
}