#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 */
int /*<<< orphan*/ ETIME;
int /*<<< orphan*/ errno;
struct tm *localtime(int /*<<< orphan*/ *);
int strftime(char *, size_t, char const *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int current_time_str(char *str, size_t len, const char *fmt) {
  time_t t;
  struct tm *t_local;
  int ret;
  t = time(NULL);
  t_local = localtime(&t);
  if (!t_local) {
    errno = ETIME;
    return -1;
  }
  ret = strftime(str, len, fmt, t_local);
  if (ret == 0) {
    errno = ETIME;
    return -1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<current_time_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x24(%rbp)
lea    -0x24(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1186 <current_time_str+0x56>
mov    0x2e79(%rip),%rax
mov    (%rax),%ecx
mov    0x2e60(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11cc <current_time_str+0x9c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1050 <strftime@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    11c6 <current_time_str+0x96>
mov    0x2e39(%rip),%rax
mov    (%rax),%ecx
mov    0x2e20(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11cc <current_time_str+0x9c>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<current_time_str>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     1171 <current_time_str+0x41>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
call   1050 <strftime@plt>
test   %eax,%eax
jne    1188 <current_time_str+0x58>
mov    0x2e70(%rip),%rax
mov    (%rax),%eax
mov    0x2e57(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@ETIME = global i32 0
@errno = global i32 0
define i32 @current_time_str(i8* %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.tm*
%10 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%11 = call i32 @time(i32* null)
store i32 %11, i32* %8
%12 = call %struct.tm* @localtime(i32* %8)
store %struct.tm* %12, %struct.tm** %9
%13 = load %struct.tm*, %struct.tm** %9
%14 = icmp ne %struct.tm* %13, null
br i1 %14, label %17, label %15
15: ; preds = %3
%16 = load i32, i32* @ETIME
store i32 %16, i32* @errno
store i32 -1, i32* %4
br label %29
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = load i64, i64* %6
%20 = load i8*, i8** %7
%21 = load %struct.tm*, %struct.tm** %9
%22 = call i32 @strftime(i8* %18, i64 %19, i8* %20, %struct.tm* %21)
store i32 %22, i32* %10
%23 = load i32, i32* %10
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %17
%26 = load i32, i32* @ETIME
store i32 %26, i32* @errno
store i32 -1, i32* %4
br label %29
27: ; preds = %17
%28 = load i32, i32* %10
store i32 %28, i32* %4
br label %29
29: ; preds = %27, %25, %15
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@ETIME = global i32 0
@errno = global i32 0
define i32 @current_time_str(i8* %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 @time(i32* null)
store i32 %6, i32* %4
%7 = call %struct.tm* @localtime(i32* %4)
%8 = icmp eq %struct.tm* %7, null
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = call i32 @strftime(i8* %0, i64 %1, i8* %2, %struct.tm* %7)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9, %3
%13 = load i32, i32* @ETIME
store i32 %13, i32* @errno
br label %14
14: ; preds = %12, %9
%15 = phi i32 [ %10, %9 ], [ -1, %12 ]
ret i32 %15
}