#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 tm_hour;
  int tm_min;
  int tm_sec;
};

/* Variables and functions */
int /*<<< orphan*/ localtime_r(scalar_t__ *, struct tm *);
int /*<<< orphan*/ snprintf(char *const, size_t const, char *, ...);
scalar_t__ time(int /*<<< orphan*/ *);
void get_time(char *const buffer, const size_t buflen) {
  struct tm tm;
  time_t now;
  now = time(NULL);
  if (now == ((time_t)-1)) {
    (void)snprintf(buffer, buflen, "--:--:-- ");
    return;
  }
  (void)localtime_r(&now, &tm);
  (void)snprintf(buffer, buflen, "%2.2d:%2.2d:%2.2d ", tm.tm_hour, tm.tm_min,
                 tm.tm_sec);
}


x86 assembly (clang, -O0):
<get_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xffffffffffffffff,-0x28(%rbp)
jne    1173 <get_time+0x43>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe99(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    11a1 <get_time+0x71>
lea    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x18(%rbp),%r9d
lea    0xe70(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_time>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edi,%edi
call   1050 <time@plt>
mov    %rax,0x10(%rsp)
cmp    $0xffffffffffffffff,%rax
je     1185 <get_time+0x55>
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <localtime_r@plt>
mov    (%rsp),%ecx
mov    0x4(%rsp),%r8d
mov    0x8(%rsp),%r9d
lea    0xe9a(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <snprintf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe74(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
jmp    1040 <snprintf@plt>

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

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