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

/* Variables and functions */
struct tm *gmtime(int /*<<< orphan*/ *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int ffgstm(char *timestr, int *timeref, int *status) {
  time_t tp;
  struct tm *ptr;
  if (*status > 0)
    return (*status);
  time(&tp);
  ptr = gmtime(&tp);
  if (timeref) {
    if (ptr)
      *timeref = 0;
    else
      *timeref = 1;
  }
  if (!ptr)
    ptr = localtime(&tp);
  strftime(timestr, 25, "%Y-%m-%dT%H:%M:%S", ptr);
  return (*status);
}


x86 assembly (clang, -O0):
<ffgstm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jle    116f <ffgstm+0x2f>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11f3 <ffgstm+0xb3>
lea    -0x24(%rbp),%rdi
call   1040 <time@plt>
lea    -0x24(%rbp),%rdi
call   1060 <gmtime@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b9 <ffgstm+0x79>
cmpq   $0x0,-0x30(%rbp)
je     11aa <ffgstm+0x6a>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
jmp    11b4 <ffgstm+0x74>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    11b9 <ffgstm+0x79>
cmpq   $0x0,-0x30(%rbp)
jne    11d1 <ffgstm+0x91>
lea    -0x24(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x19,%esi
lea    0xe1b(%rip),%rdx
call   1050 <strftime@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ffgstm>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    (%rdx),%eax
test   %eax,%eax
jg     11af <ffgstm+0x6f>
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x4(%rsp),%r12
mov    %r12,%rdi
call   1040 <time@plt>
mov    %r12,%rdi
call   1060 <gmtime@plt>
test   %rbx,%rbx
je     117e <ffgstm+0x3e>
test   %rax,%rax
je     1185 <ffgstm+0x45>
movl   $0x0,(%rbx)
jmp    1195 <ffgstm+0x55>
test   %rax,%rax
jne    1195 <ffgstm+0x55>
jmp    118b <ffgstm+0x4b>
movl   $0x1,(%rbx)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xe64(%rip),%rdx
mov    %r14,%rdi
mov    $0x19,%esi
mov    %rax,%rcx
call   1050 <strftime@plt>
mov    (%r15),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [18 x i8] c"%Y-%m-%dT%H:%M:%S\00"
define i32 @ffgstm(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca %struct.tm*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%10 = load i32*, i32** %7
%11 = load i32, i32* %10
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load i32*, i32** %7
%15 = load i32, i32* %14
store i32 %15, i32* %4
br label %40
16: ; preds = %3
%17 = call i32 @time(i32* %8)
%18 = call %struct.tm* @gmtime(i32* %8)
store %struct.tm* %18, %struct.tm** %9
%19 = load i32*, i32** %6
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %29
21: ; preds = %16
%22 = load %struct.tm*, %struct.tm** %9
%23 = icmp ne %struct.tm* %22, null
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = load i32*, i32** %6
store i32 0, i32* %25
br label %28
26: ; preds = %21
%27 = load i32*, i32** %6
store i32 1, i32* %27
br label %28
28: ; preds = %26, %24
br label %29
29: ; preds = %28, %16
%30 = load %struct.tm*, %struct.tm** %9
%31 = icmp ne %struct.tm* %30, null
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = call %struct.tm* @localtime(i32* %8)
store %struct.tm* %33, %struct.tm** %9
br label %34
34: ; preds = %32, %29
%35 = load i8*, i8** %5
%36 = load %struct.tm*, %struct.tm** %9
%37 = call i32 @strftime(i8* %35, i32 25, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %36)
%38 = load i32*, i32** %7
%39 = load i32, i32* %38
store i32 %39, i32* %4
br label %40
40: ; preds = %34, %13
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [18 x i8] c"%Y-%m-%dT%H:%M:%S\00"
define i32 @ffgstm(i8* %0, i32* writeonly %1, i32* nocapture %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = load i32, i32* %2
%7 = icmp sgt i32 %6, 0
br i1 %7, label %23, label %8
8: ; preds = %3
%9 = call i32 @time(i32* %4)
%10 = call %struct.tm* @gmtime(i32* %4)
%11 = icmp eq i32* %1, null
%12 = icmp eq %struct.tm* %10, null
br i1 %11, label %16, label %13
13: ; preds = %8
br i1 %12, label %15, label %14
14: ; preds = %13
store i32 0, i32* %1
br label %19
15: ; preds = %13
store i32 1, i32* %1
br label %17
16: ; preds = %8
br i1 %12, label %17, label %19
17: ; preds = %15, %16
%18 = call %struct.tm* @localtime(i32* %4)
br label %19
19: ; preds = %14, %17, %16
%20 = phi %struct.tm* [ %10, %16 ], [ %18, %17 ], [ %10, %14 ]
%21 = call i32 @strftime(i8* %0, i32 25, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %20)
%22 = load i32, i32* %2
br label %23
23: ; preds = %3, %19
%24 = phi i32 [ %22, %19 ], [ %6, %3 ]
ret i32 %24
}