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

/* Variables and functions */
size_t strfiso8601tz(char *, int, struct tm *);
size_t strftime(char *, int, char *, struct tm *);
size_t strnlen(char *, size_t);
size_t strfiso8601(char *buf, size_t maxsize, struct tm *tptr) {
  if (maxsize < 26) {
    return 0;
  }
  size_t base_len_written = strftime(buf, 20, "%Y-%m-%dT%T", tptr);
  if (0 == base_len_written) {
    return 0;
  }
  size_t tz_len_written = strfiso8601tz(buf + 20 - 1, 7, tptr);
  if (0 == tz_len_written) {
    return 0;
  }
  return strnlen(buf, maxsize);
}


x86 assembly (clang, -O0):
<strfiso8601>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x1a,-0x18(%rbp)
jae    115c <strfiso8601+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    11da <strfiso8601+0xaa>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x14,%esi
lea    0xe90(%rip),%rdx
call   1050 <strftime@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    1192 <strfiso8601+0x62>
movq   $0x0,-0x8(%rbp)
jmp    11da <strfiso8601+0xaa>
mov    -0x10(%rbp),%rdi
add    $0x14,%rdi
add    $0xffffffffffffffff,%rdi
mov    -0x20(%rbp),%rdx
mov    $0x7,%esi
call   1040 <strfiso8601tz@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    11c9 <strfiso8601+0x99>
movq   $0x0,-0x8(%rbp)
jmp    11da <strfiso8601+0xaa>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strnlen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strfiso8601>:
push   %r15
push   %r14
push   %rbx
cmp    $0x1a,%rsi
jb     1183 <strfiso8601+0x53>
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xeb5(%rip),%rdx
mov    $0x14,%esi
mov    %r15,%rcx
call   1050 <strftime@plt>
test   %rax,%rax
je     1183 <strfiso8601+0x53>
lea    0x13(%r14),%rdi
mov    $0x7,%esi
mov    %r15,%rdx
call   1040 <strfiso8601tz@plt>
test   %rax,%rax
je     1183 <strfiso8601+0x53>
mov    %r14,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strnlen@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [12 x i8] c"%Y-%m-%dT%T\00"
define i64 @strfiso8601(i8* %0, i64 %1, %struct.tm* %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.tm*
%8 = alloca i64
%9 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store %struct.tm* %2, %struct.tm** %7
%10 = load i64, i64* %6
%11 = icmp ult i64 %10, 26
br i1 %11, label %12, label %13
12: ; preds = %3
store i64 0, i64* %4
br label %33
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = load %struct.tm*, %struct.tm** %7
%16 = call i64 @strftime(i8* %14, i32 20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %struct.tm* %15)
store i64 %16, i64* %8
%17 = load i64, i64* %8
%18 = icmp eq i64 0, %17
br i1 %18, label %19, label %20
19: ; preds = %13
store i64 0, i64* %4
br label %33
20: ; preds = %13
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 20
%23 = getelementptr inbounds i8, i8* %22, i64 -1
%24 = load %struct.tm*, %struct.tm** %7
%25 = call i64 @strfiso8601tz(i8* %23, i32 7, %struct.tm* %24)
store i64 %25, i64* %9
%26 = load i64, i64* %9
%27 = icmp eq i64 0, %26
br i1 %27, label %28, label %29
28: ; preds = %20
store i64 0, i64* %4
br label %33
29: ; preds = %20
%30 = load i8*, i8** %5
%31 = load i64, i64* %6
%32 = call i64 @strnlen(i8* %30, i64 %31)
store i64 %32, i64* %4
br label %33
33: ; preds = %29, %28, %19, %12
%34 = load i64, i64* %4
ret i64 %34
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [12 x i8] c"%Y-%m-%dT%T\00"
define i64 @strfiso8601(i8* %0, i64 %1, %struct.tm* %2) {
%4 = icmp ult i64 %1, 26
br i1 %4, label %14, label %5
5: ; preds = %3
%6 = tail call i64 @strftime(i8* %0, i32 20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %struct.tm* %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = getelementptr inbounds i8, i8* %0, i64 19
%10 = tail call i64 @strfiso8601tz(i8* %9, i32 7, %struct.tm* %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i64 @strnlen(i8* %0, i64 %1)
br label %14
14: ; preds = %5, %8, %12, %3
%15 = phi i64 [ 0, %3 ], [ 0, %5 ], [ %13, %12 ], [ 0, %8 ]
ret i64 %15
}