#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 *gmtime(int /*<<< orphan*/ const *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int, int);
char *ctime_r(const time_t *t, char *buff) {
  struct tm *time = gmtime(t);
  sprintf(buff, "%04d-%02d-%02d %02d:%02d:%02d", time->tm_year + 1900,
          time->tm_mon + 1, time->tm_mday, time->tm_hour, time->tm_min,
          time->tm_sec);
  return buff;
}


x86 assembly (clang, -O0):
<ctime_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <gmtime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%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    0xe83(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ctime_r>:
push   %rbx
mov    %rsi,%rbx
call   1030 <gmtime@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    0xeb4(%rip),%rsi
mov    %rbx,%rdi
push   %rax
push   %r10
call   1040 <sprintf@plt>
add    $0x10,%rsp
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [30 x i8] c"%04d-%02d-%02d %02d:%02d:%02d\00"
define i8* @ctime_r(i32* %0, i8* returned writeonly %1) {
%3 = tail call %struct.tm* @gmtime(i32* %0)
%4 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
%5 = load i32, i32* %4
%6 = add nsw i32 %5, 1900
%7 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 1
%8 = load i32, i32* %7
%9 = add nsw i32 %8, 1
%10 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 2
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 3
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 4
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 5
%17 = load i32, i32* %16
%18 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %9, i32 %11, i32 %13, i32 %15, i32 %17)
ret i8* %1
}