#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 */
int /*<<< orphan*/ gmtime_r(int /*<<< orphan*/ const *, struct tm *);
size_t snprintf(char *, int, char *, int const, int const, int const, int const,
                int const, int const);
size_t print_ts(const time_t ts, char *buf, int max_len) {
  struct tm x;
  gmtime_r(&ts, &x);
  const int Y = x.tm_year + 1900;
  const int M = x.tm_mon + 1;
  const int D = x.tm_mday;
  const int h = x.tm_hour;
  const int m = x.tm_min;
  const int s = x.tm_sec;
  return snprintf(buf, max_len, "%04d-%02d-%02dT%02d:%02d:%02dZ", Y, M, D, h, m,
                  s);
}


x86 assembly (clang, -O0):
<print_ts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x4(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <gmtime_r@plt>
mov    -0x30(%rbp),%eax
add    $0x76c,%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x34(%rbp),%ecx
mov    -0x38(%rbp),%r8d
mov    -0x3c(%rbp),%r9d
mov    -0x40(%rbp),%r11d
mov    -0x44(%rbp),%r10d
mov    -0x48(%rbp),%eax
lea    0xe71(%rip),%rdx
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1030 <snprintf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_ts>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %edi,0xc(%rsp)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1040 <gmtime_r@plt>
mov    $0x76c,%ecx
add    0x10(%rsp),%ecx
mov    0x14(%rsp),%r8d
mov    0x18(%rsp),%r9d
add    $0x1,%r8d
mov    0x1c(%rsp),%eax
mov    0x20(%rsp),%ebp
mov    0x24(%rsp),%ebx
sub    $0x8,%rsp
lea    0xe8f(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
push   %rbx
push   %rbp
push   %rax
call   1030 <snprintf@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [31 x i8] c"%04d-%02d-%02dT%02d:%02d:%02dZ\00"
define i64 @print_ts(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.tm
store i32 %0, i32* %4
%6 = bitcast %struct.tm* %5 to i8*
%7 = call i32 @gmtime_r(i32* %4, %struct.tm* %5)
%8 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%9 = load i32, i32* %8
%10 = add nsw i32 %9, 1900
%11 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%12 = load i32, i32* %11
%13 = add nsw i32 %12, 1
%14 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 3
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 4
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 5
%21 = load i32, i32* %20
%22 = call i64 @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %13, i32 %15, i32 %17, i32 %19, i32 %21)
ret i64 %22
}