#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 tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  size_t tm_wday;
};
typedef int /*<<< orphan*/ buff;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char const *);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void tty_timestamp(void *ui) {
  FILE *tty = ui;
  struct tm local_now;
  time_t time_now;
  char buff[256];
  const char *day_of_week[7] = {"Sat", "Mon", "Tue", "Wed",
                                "Thu", "Fri", "Sat"};
  time(&time_now);
  localtime_r(&time_now, &local_now);
  snprintf(buff, sizeof(buff), "%2d-%2d %2d:%02d", local_now.tm_mon,
           local_now.tm_mday, local_now.tm_hour, local_now.tm_min);
  fprintf(tty, "timestamp: %s (%s)\r\n", buff, day_of_week[local_now.tm_wday]);
}


x86 assembly (clang, -O0):
<tty_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x170(%rbp),%rdi
lea    0x2c6b(%rip),%rsi
mov    $0x38,%edx
call   1060 <memcpy@plt>
lea    -0x2c(%rbp),%rdi
call   1070 <time@plt>
lea    -0x2c(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <localtime_r@plt>
lea    -0x130(%rbp),%rdi
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    -0x1c(%rbp),%eax
mov    $0x100,%esi
lea    0xe62(%rip),%rdx
mov    %eax,(%rsp)
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x130(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    -0x170(%rbp,%rax,8),%rcx
ff
lea    0xe4d(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tty_timestamp>:
push   %r14
push   %rbx
sub    $0x138,%rsp
mov    %rdi,%r14
lea    0x2c(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <time@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <localtime_r@plt>
mov    0x10(%rsp),%ecx
mov    0x14(%rsp),%r8d
mov    0x18(%rsp),%r9d
mov    0x1c(%rsp),%eax
mov    %eax,(%rsp)
lea    0xe95(%rip),%rdx
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1040 <snprintf@plt>
mov    0x20(%rsp),%rax
lea    0xe9f(%rip),%rdx
movslq (%rdx,%rax,4),%rcx
add    %rdx,%rcx
lea    0xe7a(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
add    $0x138,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i64 }
@.str = [4 x i8] c"Sat\00"
@.str.1 = [4 x i8] c"Mon\00"
@.str.2 = [4 x i8] c"Tue\00"
@.str.3 = [4 x i8] c"Wed\00"
@.str.4 = [4 x i8] c"Thu\00"
@.str.5 = [4 x i8] c"Fri\00"
@__const.tty_timestamp.day_of_week = [7 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0)]
@.str.6 = [17 x i8] c"%2d-%2d %2d:%02d\00"
@.str.7 = [21 x i8] c"timestamp: %s (%s)\0D\0A\00"
define void @tty_timestamp(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.tm
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca [7 x i8*]
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = bitcast i8* %8 to i32*
store i32* %9, i32** %3
%10 = bitcast [7 x i8*]* %7 to i8*
%11 = call i32 @time(i32* %5)
%12 = call i32 @localtime_r(i32* %5, %struct.tm* %4)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%14 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 0
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 1
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 2
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 3
%21 = load i32, i32* %20
%22 = call i32 @snprintf(i8* %13, i32 256, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %15, i32 %17, i32 %19, i32 %21)
%23 = load i32*, i32** %3
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%25 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 4
%26 = load i64, i64* %25
%27 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i64 0, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %24, i8* %28)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i64 }
@.str = [4 x i8] c"Sat\00"
@.str.1 = [4 x i8] c"Mon\00"
@.str.2 = [4 x i8] c"Tue\00"
@.str.3 = [4 x i8] c"Wed\00"
@.str.4 = [4 x i8] c"Thu\00"
@.str.5 = [4 x i8] c"Fri\00"
@reltable.tty_timestamp = [7 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str to i64), i64 ptrtoint ([7 x i32]* @reltable.tty_timestamp to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([7 x i32]* @reltable.tty_timestamp to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([7 x i32]* @reltable.tty_timestamp to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.3 to i64), i64 ptrtoint ([7 x i32]* @reltable.tty_timestamp to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.4 to i64), i64 ptrtoint ([7 x i32]* @reltable.tty_timestamp to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.5 to i64), i64 ptrtoint ([7 x i32]* @reltable.tty_timestamp to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str to i64), i64 ptrtoint ([7 x i32]* @reltable.tty_timestamp to i64)) to i32)]
@.str.6 = [17 x i8] c"%2d-%2d %2d:%02d\00"
@.str.7 = [21 x i8] c"timestamp: %s (%s)\0D\0A\00"
define void @tty_timestamp(i8* nocapture %0) {
%2 = alloca %struct.tm
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = bitcast i8* %0 to i32*
%6 = bitcast %struct.tm* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%9 = call i32 @time(i32* %3)
%10 = call i32 @localtime_r(i32* %3, %struct.tm* %2)
%11 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 1
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 2
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 3
%18 = load i32, i32* %17
%19 = call i32 @snprintf(i8* %8, i32 256, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %12, i32 %14, i32 %16, i32 %18)
%20 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 4
%21 = load i64, i64* %20
%22 = shl i64 %21, 2
%23 = call i8* @llvm.load.relative.i64(i8* bitcast ([7 x i32]* @reltable.tty_timestamp to i8*), i64 %22)
%24 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %8, i8* %23)
ret void
}