#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 dummy;
};

/* Variables and functions */
scalar_t__ isdigit(char);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
size_t strftime(char *, size_t, char *, struct tm *);
size_t __w3cdatetime(char *buf, size_t sz, time_t t) {
  struct tm tm;
  char *p;
  size_t n;
  localtime_r(&t, &tm);
  n = strftime(buf, sz - 1, "%FT%T%z", &tm);
  p = buf + n;
  if (*p == '\0' && isdigit(*(p - 1)) && isdigit(*(p - 2))) {
    *(p + 1) = *p;
    *(p) = *(p - 1);
    *(p - 1) = *(p - 2);
    *(p - 2) = ':';
  }
  return n + 1;
}


x86 assembly (clang, -O0):
<__w3cdatetime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <localtime_r@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
sub    $0x1,%rsi
lea    0xe9d(%rip),%rdx
lea    -0x18(%rbp),%rcx
call   1050 <strftime@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11ea <__w3cdatetime+0xba>
mov    -0x20(%rbp),%rax
movsbl -0x1(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11ea <__w3cdatetime+0xba>
mov    -0x20(%rbp),%rax
movsbl -0x2(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11ea <__w3cdatetime+0xba>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x20(%rbp),%rax
mov    -0x1(%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
mov    -0x2(%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,-0x1(%rax)
mov    -0x20(%rbp),%rax
movb   $0x3a,-0x2(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__w3cdatetime>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %edx,0x4(%rsp)
lea    0x4(%rsp),%rdi
lea    0x8(%rsp),%r15
mov    %r15,%rsi
call   1040 <localtime_r@plt>
add    $0xffffffffffffffff,%rbx
lea    0xea0(%rip),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rcx
call   1050 <strftime@plt>
mov    %rax,%rbx
cmpb   $0x0,(%r14,%rax,1)
jne    11b3 <__w3cdatetime+0x83>
movsbl -0x1(%r14,%rbx,1),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11b3 <__w3cdatetime+0x83>
movsbl -0x2(%r14,%rbx,1),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11b3 <__w3cdatetime+0x83>
mov    (%r14,%rbx,1),%al
mov    %al,0x1(%r14,%rbx,1)
movzwl -0x2(%r14,%rbx,1),%eax
mov    %ax,-0x1(%r14,%rbx,1)
movb   $0x3a,-0x2(%r14,%rbx,1)
add    $0x1,%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [8 x i8] c"%FT%T%z\00"
define i64 @__w3cdatetime(i8* %0, i64 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca %struct.tm
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%10 = call i32 @localtime_r(i32* %6, %struct.tm* %7)
%11 = load i8*, i8** %4
%12 = load i64, i64* %5
%13 = sub i64 %12, 1
%14 = call i64 @strftime(i8* %11, i64 %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %struct.tm* %7)
store i64 %14, i64* %9
%15 = load i8*, i8** %4
%16 = load i64, i64* %9
%17 = getelementptr inbounds i8, i8* %15, i64 %16
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %50
22: ; preds = %3
%23 = load i8*, i8** %8
%24 = getelementptr inbounds i8, i8* %23, i64 -1
%25 = load i8, i8* %24
%26 = call i64 @isdigit(i8 signext %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %50
28: ; preds = %22
%29 = load i8*, i8** %8
%30 = getelementptr inbounds i8, i8* %29, i64 -2
%31 = load i8, i8* %30
%32 = call i64 @isdigit(i8 signext %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %50
34: ; preds = %28
%35 = load i8*, i8** %8
%36 = load i8, i8* %35
%37 = load i8*, i8** %8
%38 = getelementptr inbounds i8, i8* %37, i64 1
store i8 %36, i8* %38
%39 = load i8*, i8** %8
%40 = getelementptr inbounds i8, i8* %39, i64 -1
%41 = load i8, i8* %40
%42 = load i8*, i8** %8
store i8 %41, i8* %42
%43 = load i8*, i8** %8
%44 = getelementptr inbounds i8, i8* %43, i64 -2
%45 = load i8, i8* %44
%46 = load i8*, i8** %8
%47 = getelementptr inbounds i8, i8* %46, i64 -1
store i8 %45, i8* %47
%48 = load i8*, i8** %8
%49 = getelementptr inbounds i8, i8* %48, i64 -2
store i8 58, i8* %49
br label %50
50: ; preds = %34, %28, %22, %3
%51 = load i64, i64* %9
%52 = add i64 %51, 1
ret i64 %52
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [8 x i8] c"%FT%T%z\00"
define i64 @__w3cdatetime(i8* %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.tm
store i32 %2, i32* %4
%6 = bitcast %struct.tm* %5 to i8*
%7 = call i32 @localtime_r(i32* %4, %struct.tm* %5)
%8 = add i64 %1, -1
%9 = call i64 @strftime(i8* %0, i64 %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %struct.tm* %5)
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %3
%14 = getelementptr inbounds i8, i8* %10, i64 -1
%15 = load i8, i8* %14
%16 = call i64 @isdigit(i8 signext %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %28, label %18
18: ; preds = %13
%19 = getelementptr inbounds i8, i8* %10, i64 -2
%20 = load i8, i8* %19
%21 = call i64 @isdigit(i8 signext %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %18
%24 = load i8, i8* %10
%25 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %24, i8* %25
%26 = load i8, i8* %14
store i8 %26, i8* %10
%27 = load i8, i8* %19
store i8 %27, i8* %14
store i8 58, i8* %19
br label %28
28: ; preds = %23, %18, %13, %3
%29 = add i64 %9, 1
ret i64 %29
}