#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 */
int /*<<< orphan*/ strncpy(char *, char *, int);
int strnlen(char *, int);
char *strptime(char *, char *, struct tm *);
char *strpiso8601(char *buf, struct tm *tptr) {
  char mbuf[26];
  strncpy(mbuf, buf, strnlen(buf, 26));
  if (':' != mbuf[strnlen(buf, 26) - 3]) {
    return NULL;
  }
  for (size_t i = 3; i > 1; i--) {
    size_t target = strnlen(buf, 26) - i;
    mbuf[target] = mbuf[target + 1];
  }
  mbuf[strnlen(buf, 26) - 1] = '\0';
  return strptime(mbuf, "%Y-%m-%dT%T%z", tptr);
}


x86 assembly (clang, -O0):
<strpiso8601>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1a,%esi
call   1040 <strnlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1a,%esi
call   1040 <strnlen@plt>
sub    $0x3,%eax
cltq
movsbl -0x40(%rbp,%rax,1),%ecx
mov    $0x3a,%eax
cmp    %ecx,%eax
je     119f <strpiso8601+0x6f>
movq   $0x0,-0x8(%rbp)
jmp    121b <strpiso8601+0xeb>
movq   $0x3,-0x48(%rbp)
cmpq   $0x1,-0x48(%rbp)
jbe    11eb <strpiso8601+0xbb>
mov    -0x10(%rbp),%rdi
mov    $0x1a,%esi
call   1040 <strnlen@plt>
cltq
sub    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    -0x3f(%rbp,%rax,1),%cl
mov    -0x50(%rbp),%rax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x48(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x48(%rbp)
jmp    11a7 <strpiso8601+0x77>
mov    -0x10(%rbp),%rdi
mov    $0x1a,%esi
call   1040 <strnlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x40(%rbp,%rax,1)
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdee(%rip),%rsi
call   1050 <strptime@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strpiso8601>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x1a,%esi
call   1040 <strnlen@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    $0x1a,%esi
call   1040 <strnlen@plt>
cltq
cmpb   $0x3a,-0x3(%rax,%r15,1)
jne    11cb <strpiso8601+0x9b>
mov    %rbx,%rdi
mov    $0x1a,%esi
call   1040 <strnlen@plt>
cltq
mov    -0x2(%rax,%r15,1),%cl
mov    %cl,-0x3(%rax,%r15,1)
mov    %rbx,%rdi
mov    $0x1a,%esi
call   1040 <strnlen@plt>
cltq
mov    -0x1(%rax,%r15,1),%cl
mov    %cl,-0x2(%rax,%r15,1)
mov    %rbx,%rdi
mov    $0x1a,%esi
call   1040 <strnlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
lea    0xe42(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1050 <strptime@plt>
jmp    11cd <strpiso8601+0x9d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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