#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 */
struct tm {
  int dummy;
};
struct timespec {
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ date;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ assert(int);
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
struct tm *localtime_r(int /*<<< orphan*/ *, struct tm *);
size_t strftime(char *, int, char const *, struct tm *);
void write_time_prefix(FILE *stream) {
  const char *format = "%H:%M:%S%z";
  struct timespec now;
  assert(clock_gettime(CLOCK_REALTIME, &now) == 0);
  struct tm current_time;
  struct tm *current_time_p = localtime_r(&now.tv_sec, &current_time);
  assert(current_time_p != NULL);
  char date[] = "00:00:00+0000";
  size_t printed = strftime(date, sizeof(date), format, current_time_p);
  assert(printed > 0);
  fwrite(date, printed, 1, stream);
  fwrite(" ", 1, 1, stream);
}


x86 assembly (clang, -O0):
<write_time_prefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9d(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1040 <clock_gettime@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    0xe57(%rip),%rax
mov    %rax,-0x36(%rbp)
mov    0xe55(%rip),%eax
mov    %eax,-0x2e(%rbp)
mov    0xe4f(%rip),%ax
mov    %ax,-0x2a(%rbp)
lea    -0x36(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0xe,%esi
call   1060 <strftime@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x36(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x8(%rbp),%rcx
lea    0xdfe(%rip),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_time_prefix>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r14
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
call   1040 <clock_gettime@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <localtime_r@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
movabs $0x303030302b3030,%rax
mov    %rax,0x16(%rsp)
movabs $0x30303a30303a3030,%rax
3a 30 30
mov    %rax,0x10(%rsp)
lea    0xe2f(%rip),%rdx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0xe,%esi
mov    %rbx,%rcx
call   1070 <strftime@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
mov    $0x20,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
%struct.tm = type { i32 }
@.str = [11 x i8] c"%H:%M:%S%z\00"
@CLOCK_REALTIME = global i32 0
@__const.write_time_prefix.date = [14 x i8] c"00:00:00+0000\00"
@.str.1 = [2 x i8] c" \00"
define void @write_time_prefix(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca %struct.timespec
%5 = alloca %struct.tm
%6 = alloca %struct.tm*
%7 = alloca [14 x i8]
%8 = alloca i64
store i32* %0, i32** %2
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %3
%9 = load i32, i32* @CLOCK_REALTIME
%10 = call i64 @clock_gettime(i32 %9, %struct.timespec* %4)
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%15 = call %struct.tm* @localtime_r(i32* %14, %struct.tm* %5)
store %struct.tm* %15, %struct.tm** %6
%16 = load %struct.tm*, %struct.tm** %6
%17 = icmp ne %struct.tm* %16, null
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = bitcast [14 x i8]* %7 to i8*
%21 = getelementptr inbounds [14 x i8], [14 x i8]* %7, i64 0, i64 0
%22 = load i8*, i8** %3
%23 = load %struct.tm*, %struct.tm** %6
%24 = call i64 @strftime(i8* %21, i32 14, i8* %22, %struct.tm* %23)
store i64 %24, i64* %8
%25 = load i64, i64* %8
%26 = icmp ugt i64 %25, 0
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = getelementptr inbounds [14 x i8], [14 x i8]* %7, i64 0, i64 0
%30 = load i64, i64* %8
%31 = trunc i64 %30 to i32
%32 = load i32*, i32** %2
%33 = call i32 @fwrite(i8* %29, i32 %31, i32 1, i32* %32)
%34 = load i32*, i32** %2
%35 = call i32 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 1, i32* %34)
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
%struct.tm = type { i32 }
@.str = [11 x i8] c"%H:%M:%S%z\00"
@CLOCK_REALTIME = global i32 0
@__const.write_time_prefix.date = [14 x i8] c"00:00:00+0000\00"
define void @write_time_prefix(i32* nocapture %0) {
%2 = alloca %struct.timespec
%3 = alloca %struct.tm
%4 = alloca [14 x i8]
%5 = bitcast %struct.timespec* %2 to i8*
%6 = load i32, i32* @CLOCK_REALTIME
%7 = call i64 @clock_gettime(i32 %6, %struct.timespec* %2)
%8 = icmp eq i64 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = bitcast %struct.tm* %3 to i8*
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%13 = call %struct.tm* @localtime_r(i32* %12, %struct.tm* %3)
%14 = icmp ne %struct.tm* %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 0
%18 = call i64 @strftime(i8* %17, i32 14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %struct.tm* %13)
%19 = icmp ne i64 %18, 0
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = trunc i64 %18 to i32
%23 = call i32 @fwrite(i8* %17, i32 %22, i32 1, i32* %0)
%24 = call i32 @fputc(i32 32, i32* %0)
ret void
}