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

/* Variables and functions */
struct tm *gmtime(int /*<<< orphan*/ *);
int sprintf(char *, char *, scalar_t__, scalar_t__, int /*<<< orphan*/,
            int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void timestamp_to_iso8601str(char *time_string, time_t timestamp) {
  struct tm *tm = gmtime(&timestamp);
  char *format;
  int n;
  format = "%02d-%02d-%02dT%02d:%02d:%02d";
  n = sprintf(time_string, format, tm->tm_year + 1900, tm->tm_mon + 1,
              tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
  time_string[n++] = 'Z';
}


x86 assembly (clang, -O0):
<timestamp_to_iso8601str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <gmtime@plt>
mov    %rax,-0x18(%rbp)
lea    0xebd(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rdx
add    $0x76c,%rdx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rcx
add    $0x1,%rcx
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%r8d
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r9d
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%r10d
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1040 <sprintf@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
movslq %ecx,%rcx
movb   $0x5a,(%rax,%rcx,1)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timestamp_to_iso8601str>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %esi,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <gmtime@plt>
mov    $0x76c,%edx
add    0x18(%rax),%rdx
mov    0x10(%rax),%rcx
add    $0x1,%rcx
mov    0xc(%rax),%r8d
mov    0x8(%rax),%r9d
mov    (%rax),%ebx
mov    0x4(%rax),%eax
lea    0xea6(%rip),%rsi
mov    %r14,%rdi
push   %rbx
push   %rax
call   1040 <sprintf@plt>
add    $0x10,%rsp
cltq
movb   $0x5a,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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