#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*/ *localtime_r(int /*<<< orphan*/ *, struct tm *);
size_t strftime(char *, size_t, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
size_t log_write_timestamp(char *buffer, size_t size) {
  size_t result;
  time_t current_time = time(NULL);
  struct tm local_time;
  if (localtime_r(&current_time, &local_time) == NULL)
    return 0;
  result = strftime(buffer, size, "%X", &local_time);
  return result;
}


x86 assembly (clang, -O0):
<log_write_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x24(%rbp)
lea    -0x24(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <localtime_r@plt>
cmp    $0x0,%rax
jne    1170 <log_write_timestamp+0x40>
movq   $0x0,-0x8(%rbp)
jmp    1194 <log_write_timestamp+0x64>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe81(%rip),%rdx
lea    -0x28(%rbp),%rcx
call   1050 <strftime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_write_timestamp>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <localtime_r@plt>
test   %rax,%rax
je     117a <log_write_timestamp+0x4a>
lea    0xe99(%rip),%rdx
lea    0x8(%rsp),%rcx
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strftime@plt>
mov    %rax,%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [3 x i8] c"%X\00"
define i64 @log_write_timestamp(i8* %0, i64 %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca %struct.tm
store i8* %0, i8** %4
store i64 %1, i64* %5
%9 = call i32 @time(i32* null)
store i32 %9, i32* %7
%10 = call i32* @localtime_r(i32* %7, %struct.tm* %8)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i64 0, i64* %3
br label %18
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = load i64, i64* %5
%16 = call i64 @strftime(i8* %14, i64 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %struct.tm* %8)
store i64 %16, i64* %6
%17 = load i64, i64* %6
store i64 %17, i64* %3
br label %18
18: ; preds = %13, %12
%19 = load i64, i64* %3
ret i64 %19
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [3 x i8] c"%X\00"
define i64 @log_write_timestamp(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca %struct.tm
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 @time(i32* null)
store i32 %6, i32* %3
%7 = bitcast %struct.tm* %4 to i8*
%8 = call i32* @localtime_r(i32* %3, %struct.tm* %4)
%9 = icmp eq i32* %8, null
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = call i64 @strftime(i8* %0, i64 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %struct.tm* %4)
br label %12
12: ; preds = %2, %10
%13 = phi i64 [ %11, %10 ], [ 0, %2 ]
ret i64 %13
}