#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 */
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};
struct timeval {
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int, int);
char *PRINTTIME(struct timeval timeinfo) {
  char *timestr = (char *)malloc(100);
  memset(timestr, 0x00, 100);
  struct tm timefo;
  localtime_r(&(timeinfo.tv_sec), &timefo);
  sprintf(timestr, "%4d-%02d-%02d %02d:%02d:%02d", timefo.tm_year + 1900,
          timefo.tm_mon + 1, timefo.tm_mday, timefo.tm_hour, timefo.tm_min,
          timefo.tm_sec);
  printf("%s", timestr);
  return timestr;
}


x86 assembly (clang, -O0):
<PRINTTIME>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
lea    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%edx
add    $0x76c,%edx
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    -0x18(%rbp),%r10d
mov    -0x14(%rbp),%eax
lea    0xe51(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PRINTTIME>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,(%rsp)
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1030 <localtime_r@plt>
mov    $0x76c,%edx
add    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
mov    0x10(%rsp),%r8d
add    $0x1,%ecx
mov    0x14(%rsp),%r9d
mov    0x18(%rsp),%r10d
mov    0x1c(%rsp),%eax
lea    0xe55(%rip),%rsi
mov    %rbx,%rdi
push   %rax
push   %r10
call   1070 <sprintf@plt>
add    $0x10,%rsp
lea    0xe5c(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [29 x i8] c"%4d-%02d-%02d %02d:%02d:%02d\00"
@.str.1 = [3 x i8] c"%s\00"
define i8* @PRINTTIME(i32 %0) {
%2 = alloca %struct.timeval
%3 = alloca i8*
%4 = alloca %struct.tm
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
store i32 %0, i32* %5
%6 = call i64 @malloc(i32 100)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @memset(i8* %8, i32 0, i32 100)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%11 = call i32 @localtime_r(i32* %10, %struct.tm* %4)
%12 = load i8*, i8** %3
%13 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 0
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1900
%16 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 1
%17 = load i32, i32* %16
%18 = add nsw i32 %17, 1
%19 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 2
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 3
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 4
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 5
%26 = load i32, i32* %25
%27 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %18, i32 %20, i32 %22, i32 %24, i32 %26)
%28 = load i8*, i8** %3
%29 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = load i8*, i8** %3
ret i8* %30
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [29 x i8] c"%4d-%02d-%02d %02d:%02d:%02d\00"
@.str.1 = [3 x i8] c"%s\00"
define i8* @PRINTTIME(i32 %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.tm
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i32 %0, i32* %4
%5 = tail call i64 @malloc(i32 100)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @memset(i8* %6, i32 0, i32 100)
%8 = bitcast %struct.tm* %3 to i8*
%9 = call i32 @localtime_r(i32* %4, %struct.tm* %3)
%10 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
%11 = load i32, i32* %10
%12 = add nsw i32 %11, 1900
%13 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 1
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1
%16 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 2
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 3
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 4
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 5
%23 = load i32, i32* %22
%24 = call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %15, i32 %17, i32 %19, i32 %21, i32 %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
ret i8* %6
}