#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 *localtime(int /*<<< orphan*/ *);
scalar_t__ strftime(char *, size_t, char *, struct tm *);
int common_tprintf(char *format, time_t time, char *buffer,
                   size_t buffer_length) {
  struct tm *local_time = localtime(&time);
  if (!local_time) {
    return -1;
  }
  if (strftime(buffer, buffer_length, format, local_time) == 0) {
    return -2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<common_tprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    115b <common_tprintf+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    118d <common_tprintf+0x6d>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1040 <strftime@plt>
cmp    $0x0,%rax
jne    1186 <common_tprintf+0x66>
movl   $0xfffffffe,-0x4(%rbp)
jmp    118d <common_tprintf+0x6d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<common_tprintf>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rdi,%rbx
mov    %esi,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     1166 <common_tprintf+0x46>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <strftime@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rcx,%rcx,1),%eax
add    $0xfffffffe,%eax
jmp    116b <common_tprintf+0x4b>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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