#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 scalar_t__ time_t;
struct tm {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ *gmtime_r(scalar_t__ *, struct tm *);
scalar_t__ strftime(char *, size_t, char *, struct tm *);
scalar_t__ time(int /*<<< orphan*/ *);
int utcstr(char *buf, size_t len) {
  time_t now = 0;
  struct tm nowtm;
  int rv = -1;
  if (!buf)
    goto out;
  now = time(NULL);
  if (now == 0)
    goto out;
  if (gmtime_r(&now, &nowtm) == NULL)
    goto out;
  if (strftime(buf, len, "%a %b %e %H:%M:%S UTC %Y", &nowtm) == 0)
    goto out;
  rv = 0;
out:
  return rv;
}


x86 assembly (clang, -O0):
<utcstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x24(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    115f <utcstr+0x2f>
jmp    11c6 <utcstr+0x96>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117c <utcstr+0x4c>
jmp    11c6 <utcstr+0x96>
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <gmtime_r@plt>
cmp    $0x0,%rax
jne    1198 <utcstr+0x68>
jmp    11c6 <utcstr+0x96>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe59(%rip),%rdx
lea    -0x20(%rbp),%rcx
call   1050 <strftime@plt>
cmp    $0x0,%rax
jne    11bf <utcstr+0x8f>
jmp    11c6 <utcstr+0x96>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utcstr>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     1186 <utcstr+0x56>
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edi,%edi
call   1040 <time@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1186 <utcstr+0x56>
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <gmtime_r@plt>
test   %rax,%rax
je     1186 <utcstr+0x56>
lea    0xe8e(%rip),%rdx
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strftime@plt>
cmp    $0x1,%rax
sbb    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [25 x i8] c"%a %b %e %H:%M:%S UTC %Y\00"
define i32 @utcstr(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca %struct.tm
%7 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
store i64 0, i64* %5
store i32 -1, i32* %7
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %2
br label %27
11: ; preds = %2
%12 = call i64 @time(i32* null)
store i64 %12, i64* %5
%13 = load i64, i64* %5
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
br label %27
16: ; preds = %11
%17 = call i32* @gmtime_r(i64* %5, %struct.tm* %6)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %16
br label %27
20: ; preds = %16
%21 = load i8*, i8** %3
%22 = load i64, i64* %4
%23 = call i64 @strftime(i8* %21, i64 %22, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), %struct.tm* %6)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
br label %27
26: ; preds = %20
store i32 0, i32* %7
br label %27
27: ; preds = %26, %25, %19, %15, %10
%28 = load i32, i32* %7
ret i32 %28
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [25 x i8] c"%a %b %e %H:%M:%S UTC %Y\00"
define i32 @utcstr(i8* %0, i64 %1) {
%3 = alloca i64
%4 = alloca %struct.tm
%5 = bitcast i64* %3 to i8*
%6 = bitcast %struct.tm* %4 to i8*
%7 = icmp eq i8* %0, null
br i1 %7, label %18, label %8
8: ; preds = %2
%9 = tail call i64 @time(i32* null)
store i64 %9, i64* %3
%10 = icmp eq i64 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %8
%12 = call i32* @gmtime_r(i64* %3, %struct.tm* %4)
%13 = icmp eq i32* %12, null
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = call i64 @strftime(i8* %0, i64 %1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), %struct.tm* %4)
%16 = icmp eq i64 %15, 0
%17 = sext i1 %16 to i32
br label %18
18: ; preds = %14, %11, %8, %2
%19 = phi i32 [ -1, %8 ], [ -1, %11 ], [ -1, %2 ], [ %17, %14 ]
ret i32 %19
}