#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*/ time(int /*<<< orphan*/ *);
int get_time(char *string) {
  time_t rawtime;
  struct tm *timeinfo;
  if (string == NULL)
    return -1;
  time(&rawtime);
  timeinfo = localtime(&rawtime);
  sprintf(string, "%d:%02d:%02d-%02d:%02d:%02d ", 1900 + timeinfo->tm_year,
          timeinfo->tm_mon + 1, timeinfo->tm_mday, timeinfo->tm_hour,
          timeinfo->tm_min, timeinfo->tm_sec);
  return 0;
}


x86 assembly (clang, -O0):
<get_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <get_time+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <get_time+0x8d>
lea    -0x14(%rbp),%rdi
call   1040 <time@plt>
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
add    $0x76c,%edx
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%r9d
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%r10d
mov    -0x20(%rbp),%rax
mov    0x14(%rax),%eax
lea    0xe57(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1050 <sprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_time>:
test   %rdi,%rdi
je     118d <get_time+0x5d>
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1040 <time@plt>
mov    %r14,%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    0xe8c(%rip),%rsi
mov    %rbx,%rdi
push   %rax
push   %r10
call   1050 <sprintf@plt>
add    $0x10,%rsp
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0xffffffff,%eax
ret

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

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