#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 strftime(char *, size_t, char *, struct tm *);
int /*<<< orphan*/ strncpy(char *, char *, int);
size_t strnlen(char *, int);
size_t strfiso8601tz(char *buf, size_t maxsize, struct tm *tptr) {
  size_t written = strftime(buf, maxsize, "%z", tptr);
  if (0 == written || maxsize < 7) {
    return 0;
  }
  char tz_min[3];
  strncpy(tz_min, buf + 3, 2);
  buf[3] = ':';
  strncpy(buf + 4, tz_min, 3);
  buf[6] = '\0';
  return strnlen(buf, 7);
}


x86 assembly (clang, -O0):
<strfiso8601tz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
lea    0xea9(%rip),%rdx
call   1050 <strftime@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
je     1177 <strfiso8601tz+0x47>
cmpq   $0x7,-0x18(%rbp)
jae    1184 <strfiso8601tz+0x54>
movq   $0x0,-0x8(%rbp)
jmp    11d2 <strfiso8601tz+0xa2>
lea    -0x2b(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x3,%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movb   $0x3a,0x3(%rax)
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
lea    -0x2b(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,0x6(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x7,%esi
call   1040 <strnlen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strfiso8601tz>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rcx
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xebc(%rip),%rdx
call   1050 <strftime@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x7,%rbx
jb     1197 <strfiso8601tz+0x67>
test   %rcx,%rcx
je     1197 <strfiso8601tz+0x67>
lea    0x3(%r14),%rsi
lea    0x5(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2,%edx
call   1030 <strncpy@plt>
movb   $0x3a,0x3(%r14)
lea    0x4(%r14),%rdi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x6(%r14)
mov    %r14,%rdi
mov    $0x7,%esi
call   1040 <strnlen@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [3 x i8] c"%z\00"
define i64 @strfiso8601tz(i8* %0, i64 %1, %struct.tm* %2) {
%4 = alloca [3 x i8]
%5 = tail call i64 @strftime(i8* %0, i64 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %struct.tm* %2)
%6 = icmp eq i64 %5, 0
%7 = icmp ult i64 %1, 7
%8 = or i1 %7, %6
br i1 %8, label %17, label %9
9: ; preds = %3
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds i8, i8* %0, i64 3
%12 = call i32 @strncpy(i8* %10, i8* %11, i32 2)
store i8 58, i8* %11
%13 = getelementptr inbounds i8, i8* %0, i64 4
%14 = call i32 @strncpy(i8* %13, i8* %10, i32 3)
%15 = getelementptr inbounds i8, i8* %0, i64 6
store i8 0, i8* %15
%16 = call i64 @strnlen(i8* %0, i32 7)
br label %17
17: ; preds = %3, %9
%18 = phi i64 [ %16, %9 ], [ 0, %3 ]
ret i64 %18
}