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

/* Variables and functions */
int /*<<< orphan*/ bzero(char *, size_t);
struct tm *gmtime(int /*<<< orphan*/ const *);
int snprintf(char *, size_t, char *, int, int, int, int, int, int);
int zulutime(const time_t *timep, char *zulu, size_t len) {
  int rc;
  struct tm *tms;
  bzero(zulu, len);
  tms = gmtime(timep);
  if (NULL == tms) {
    return -1;
  }
  rc = snprintf(zulu, len, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2dZ",
                tms->tm_year + 1900, tms->tm_mon + 1, tms->tm_mday,
                tms->tm_hour, tms->tm_min, tms->tm_sec);
  if (rc < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<zulutime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <bzero@plt>
mov    -0x10(%rbp),%rdi
call   1050 <gmtime@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    1176 <zulutime+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <zulutime+0xbe>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
add    $0x76c,%ecx
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%r8d
add    $0x1,%r8d
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%r9d
mov    -0x30(%rbp),%rax
mov    0xc(%rax),%r11d
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%r10d
mov    -0x30(%rbp),%rax
mov    0x14(%rax),%eax
lea    0xe44(%rip),%rdx
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1030 <snprintf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11e7 <zulutime+0xb7>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <zulutime+0xbe>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zulutime>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1040 <bzero@plt>
mov    %rbx,%rdi
call   1050 <gmtime@plt>
test   %rax,%rax
je     1196 <zulutime+0x66>
mov    $0x76c,%ecx
add    (%rax),%ecx
mov    0x4(%rax),%r8d
mov    0x8(%rax),%r9d
add    $0x1,%r8d
mov    0xc(%rax),%r10d
mov    0x10(%rax),%ebx
mov    0x14(%rax),%eax
sub    $0x8,%rsp
lea    0xe82(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
push   %rax
push   %rbx
push   %r10
call   1030 <snprintf@plt>
add    $0x20,%rsp
sar    $0x1f,%eax
jmp    119b <zulutime+0x6b>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [31 x i8] c"%.4d-%.2d-%.2dT%.2d:%.2d:%.2dZ\00"
define i32 @zulutime(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca %struct.tm*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%10 = load i8*, i8** %6
%11 = load i64, i64* %7
%12 = call i32 @bzero(i8* %10, i64 %11)
%13 = load i32*, i32** %5
%14 = call %struct.tm* @gmtime(i32* %13)
store %struct.tm* %14, %struct.tm** %9
%15 = load %struct.tm*, %struct.tm** %9
%16 = icmp eq %struct.tm* null, %15
br i1 %16, label %17, label %18
17: ; preds = %3
store i32 -1, i32* %4
br label %46
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = load i64, i64* %7
%21 = load %struct.tm*, %struct.tm** %9
%22 = getelementptr inbounds %struct.tm, %struct.tm* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = add nsw i32 %23, 1900
%25 = load %struct.tm*, %struct.tm** %9
%26 = getelementptr inbounds %struct.tm, %struct.tm* %25, i32 0, i32 1
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
%29 = load %struct.tm*, %struct.tm** %9
%30 = getelementptr inbounds %struct.tm, %struct.tm* %29, i32 0, i32 2
%31 = load i32, i32* %30
%32 = load %struct.tm*, %struct.tm** %9
%33 = getelementptr inbounds %struct.tm, %struct.tm* %32, i32 0, i32 3
%34 = load i32, i32* %33
%35 = load %struct.tm*, %struct.tm** %9
%36 = getelementptr inbounds %struct.tm, %struct.tm* %35, i32 0, i32 4
%37 = load i32, i32* %36
%38 = load %struct.tm*, %struct.tm** %9
%39 = getelementptr inbounds %struct.tm, %struct.tm* %38, i32 0, i32 5
%40 = load i32, i32* %39
%41 = call i32 @snprintf(i8* %19, i64 %20, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %24, i32 %28, i32 %31, i32 %34, i32 %37, i32 %40)
store i32 %41, i32* %8
%42 = load i32, i32* %8
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %18
store i32 -1, i32* %4
br label %46
45: ; preds = %18
store i32 0, i32* %4
br label %46
46: ; preds = %45, %44, %17
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [31 x i8] c"%.4d-%.2d-%.2dT%.2d:%.2d:%.2dZ\00"
define i32 @zulutime(i32* %0, i8* %1, i64 %2) {
%4 = tail call i32 @bzero(i8* %1, i64 %2)
%5 = tail call %struct.tm* @gmtime(i32* %0)
%6 = icmp eq %struct.tm* %5, null
br i1 %6, label %24, label %7
7: ; preds = %3
%8 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%9 = load i32, i32* %8
%10 = add nsw i32 %9, 1900
%11 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%12 = load i32, i32* %11
%13 = add nsw i32 %12, 1
%14 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 3
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 4
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 5
%21 = load i32, i32* %20
%22 = tail call i32 @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %13, i32 %15, i32 %17, i32 %19, i32 %21)
%23 = ashr i32 %22, 31
br label %24
24: ; preds = %7, %3
%25 = phi i32 [ -1, %3 ], [ %23, %7 ]
ret i32 %25
}